0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-24 10:20:28 +01:00
discourse-custom-wizard/lib/custom_wizard/user_history.rb

47 Zeilen
1,4 KiB
Ruby

2023-01-18 19:53:36 +01:00
# frozen_string_literal: true
UserHistory.actions[:custom_wizard_step] = 1000
class CustomWizard::UserHistory
def self.where(actor_id: nil, action: nil, context: nil, subject: nil)
::UserHistory.where(where_opts(actor_id, action, context, subject))
end
def self.create(actor_id: nil, action: nil, context: nil, subject: nil)
::UserHistory.create(create_opts(actor_id, action, context, subject))
end
def self.create!(actor_id: nil, action: nil, context: nil, subject: nil)
::UserHistory.create!(create_opts(actor_id, action, context, subject))
end
def self.actions
2024-10-16 13:52:03 +02:00
@actions ||= Enum.new(step: UserHistory.actions[:custom_wizard_step])
2023-01-18 19:53:36 +01:00
end
def self.where_opts(actor_id, action, context, subject)
2024-10-16 13:52:03 +02:00
opts = { context: context }
2023-01-18 19:53:36 +01:00
opts[:action] = action if action
opts[:subject] = subject if subject
add_actor(opts, actor_id)
end
def self.create_opts(actor_id, action, context, subject)
2024-10-16 13:52:03 +02:00
opts = { action: action, context: context }
2023-01-18 19:53:36 +01:00
opts[:subject] = subject if subject
add_actor(opts, actor_id)
end
def self.add_actor(opts, actor_id)
acting_user_id = actor_id
if actor_id.is_a?(String) && actor_id.include?(CustomWizard::Wizard::GUEST_ID_PREFIX)
opts[:acting_user_id] = Discourse.system_user.id
opts[:details] = actor_id
else
opts[:acting_user_id] = actor_id
end
opts
end
end