diff --git a/app/models/remote_storage_authorization.rb b/app/models/remote_storage_authorization.rb index 7eedd57..d2d3700 100644 --- a/app/models/remote_storage_authorization.rb +++ b/app/models/remote_storage_authorization.rb @@ -69,11 +69,19 @@ class RemoteStorageAuthorization < ApplicationRecord end def remove_token_expiry_job - queue = Sidekiq::Queue.new(RemoteStorageExpireAuthorizationJob.queue_name) - queue.each do |job| - next unless job.display_class == "RemoteStorageExpireAuthorizationJob" - job.delete if job.display_args == [id] - end + job_class = RemoteStorageExpireAuthorizationJob + job_args = [id] + + query = SolidQueue::Job.where(class_name: job_class.to_s) + + case ActiveRecord::Base.connection.adapter_name.downcase + when /sqlite/ + query.where("json_extract(arguments, '$.arguments') = ?", job_args.to_json) + when /postgres/ + query.where("arguments->>'arguments' = ?", job_args.to_json) + else + raise "Unsupported database adapter" + end.destroy_all end def find_or_create_web_app diff --git a/spec/controllers/rs/oauth_controller_spec.rb b/spec/controllers/rs/oauth_controller_spec.rb index 09b0750..03f4750 100644 --- a/spec/controllers/rs/oauth_controller_spec.rb +++ b/spec/controllers/rs/oauth_controller_spec.rb @@ -5,6 +5,7 @@ RSpec.describe Rs::OauthController, type: :controller do before do allow_any_instance_of(AppCatalog::WebApp).to receive(:update_metadata).and_return(true) + allow_any_instance_of(RemoteStorageAuthorization).to receive(:remove_token_expiry_job).and_return(nil) end describe "GET /rs/oauth/:username" do diff --git a/spec/controllers/services/rs_auths_controller_spec.rb b/spec/controllers/services/rs_auths_controller_spec.rb index 44bcdc0..61dc088 100644 --- a/spec/controllers/services/rs_auths_controller_spec.rb +++ b/spec/controllers/services/rs_auths_controller_spec.rb @@ -5,6 +5,7 @@ RSpec.describe Services::RsAuthsController, type: :controller do before do allow_any_instance_of(AppCatalog::WebApp).to receive(:update_metadata).and_return(true) + allow_any_instance_of(RemoteStorageAuthorization).to receive(:remove_token_expiry_job).and_return(nil) allow_any_instance_of(Flipper).to receive(:enabled?).and_return(true) end diff --git a/spec/jobs/remote_storage_expire_authorization_job_spec.rb b/spec/jobs/remote_storage_expire_authorization_job_spec.rb index 8e6cbb7..afe0f3e 100644 --- a/spec/jobs/remote_storage_expire_authorization_job_spec.rb +++ b/spec/jobs/remote_storage_expire_authorization_job_spec.rb @@ -5,6 +5,9 @@ RSpec.describe RemoteStorageExpireAuthorizationJob, type: :job do allow_any_instance_of(AppCatalog::WebApp).to( receive(:update_metadata).and_return(true) ) + allow_any_instance_of(RemoteStorageAuthorization).to( + receive(:remove_token_expiry_job).and_return(nil) + ) @user = create :user, cn: "ronald", ou: "kosmos.org" @rs_authorization = create :remote_storage_authorization, diff --git a/spec/models/remote_storage_authorization_spec.rb b/spec/models/remote_storage_authorization_spec.rb index 3673bde..2db3d7d 100644 --- a/spec/models/remote_storage_authorization_spec.rb +++ b/spec/models/remote_storage_authorization_spec.rb @@ -7,6 +7,7 @@ RSpec.describe RemoteStorageAuthorization, type: :model do before do allow_any_instance_of(AppCatalog::WebApp).to receive(:update_metadata).and_return(true) + allow_any_instance_of(RemoteStorageAuthorization).to receive(:remove_token_expiry_job).and_return(nil) end describe "#create" do