diff options
Diffstat (limited to 'app/jobs')
-rw-r--r-- | app/jobs/ensure_agent_job.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/app/jobs/ensure_agent_job.rb b/app/jobs/ensure_agent_job.rb new file mode 100644 index 0000000..c754fc0 --- /dev/null +++ b/app/jobs/ensure_agent_job.rb @@ -0,0 +1,15 @@ +class EnsureAgentJob < ApplicationJob + queue_as :default + + include AgentsHelper + + def perform(user, groups) + # Ensure the logged in user has a current agent + # In order to do this, we first check the existing agents against the user's + # groups. If none match, we assign the user to the default Anonymous agent. + existing_agents = Agent.find_by(name: groups) + if existing_agents.nil? + user.agents << default_agent unless user.agents.include? default_agent + end + end +end |