mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-27 22:49:02 +08:00
Merge pull request #7441 from ivanscinote/SCI-10583-ik
Implement user settings cleanup job for Step deletion [SCI-10583]
This commit is contained in:
commit
5b68001c1d
2 changed files with 25 additions and 1 deletions
20
app/jobs/cleanup_user_settings_job.rb
Normal file
20
app/jobs/cleanup_user_settings_job.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CleanupUserSettingsJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(record_type, record_id)
|
||||
raise ArgumentError, 'Invalid record_type' unless %w(task_step_states results_order).include?(record_type)
|
||||
|
||||
sanitized_record_id = record_id.to_i.to_s
|
||||
raise ArgumentError, 'Invalid record_id' unless sanitized_record_id == record_id.to_s
|
||||
|
||||
sql = <<-SQL.squish
|
||||
UPDATE users
|
||||
SET settings = (settings#>>'{}')::jsonb #- '{#{record_type},#{sanitized_record_id}}'
|
||||
WHERE (settings#>>'{}')::jsonb->'#{record_type}' ? '#{sanitized_record_id}';
|
||||
SQL
|
||||
|
||||
ActiveRecord::Base.connection.execute(sql)
|
||||
end
|
||||
end
|
||||
|
|
@ -25,7 +25,7 @@ class Step < ApplicationRecord
|
|||
after_destroy :adjust_positions_after_destroy, unless: -> { skip_position_adjust }
|
||||
|
||||
# conditional touch excluding step completion updates
|
||||
after_destroy :touch_protocol
|
||||
after_destroy :touch_protocol, :remove_from_user_settings
|
||||
after_save :touch_protocol
|
||||
after_touch :touch_protocol
|
||||
|
||||
|
|
@ -189,6 +189,10 @@ class Step < ApplicationRecord
|
|||
|
||||
private
|
||||
|
||||
def remove_from_user_settings
|
||||
CleanupUserSettingsJob.perform_later('task_step_states', id)
|
||||
end
|
||||
|
||||
def touch_protocol
|
||||
# if only step completion attributes were changed, do not touch protocol
|
||||
return if saved_changes.keys.sort == %w(completed completed_on updated_at)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue