From 7f880e3ab041584f77daf098e585bc3c4a08a38a Mon Sep 17 00:00:00 2001 From: hellekin Date: Tue, 2 Feb 2021 23:18:27 +0100 Subject: [FIX] Account for users without an avatar or group 1. Ensure new users belong to an Agent Users may come without the correct group information, leading to a situation where they have no Agent assigned to them. The application cannot handle this, so we ensure new users are at least associated to the new Anonymous Agent. 2. Introduce a default avatar Users coming without an avatar would see a broken view. Now they're assigned a default avatar, which shows the IN COMMON icon logo instead. --- app/jobs/ensure_agent_job.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 app/jobs/ensure_agent_job.rb (limited to 'app/jobs/ensure_agent_job.rb') 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 -- cgit v1.2.3