aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/welcome_controller.rb7
-rw-r--r--app/helpers/users_helper.rb3
-rw-r--r--app/jobs/ensure_agent_job.rb15
-rw-r--r--app/models/user.rb6
4 files changed, 27 insertions, 4 deletions
diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb
index 85246e5..5fce0cf 100644
--- a/app/controllers/welcome_controller.rb
+++ b/app/controllers/welcome_controller.rb
@@ -121,16 +121,15 @@ class WelcomeController < ApplicationController
# Update user agents
def perform_background_jobs
if @current_user.present?
- AgencyWatcherJob.perform_later(@current_user, @sso.user_info[:groups].split(','))
+ EnsureAgentJob.perform_later(@current_user, @sso.user_info[:groups].split(','))
end
end
# Save User ID and current agent in session
def update_current_session
if @current_user.present?
- session[:current_user] = @current_user[:external_id]
- # TODO: make this a bit smarter
- session[:current_agent] = @current_user&.agents&.pluck(:name)&.last
+ session[:current_user] = @current_user[:external_id]
+ session[:current_agent] = current_agent_name
end
end
end
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index 0adb3be..1520238 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -3,4 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
module UsersHelper
+ def default_user_avatar_url
+ "https://talk.incommon.cc/uploads/talk_incommon_cc/optimized/1X/ae4533e882f427b1ae870080a42978c67c6437cc_2_32x32.png"
+ end
end
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
diff --git a/app/models/user.rb b/app/models/user.rb
index 9b199ac..7288412 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -5,4 +5,10 @@
class User < ApplicationRecord
has_many :agencies
has_many :agents, through: :agencies, source: :agent
+
+ include UsersHelper
+
+ def avatar_url
+ attributes[:avatar_url] || default_user_avatar_url
+ end
end