From a5c1cf44504626fd57cc2936ef6b2729b9b532f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Zrim=C5=A1ek?= Date: Sat, 12 Jan 2019 22:19:07 +0100 Subject: [PATCH] Switch user's team if he's no longer a member of the currently selected one --- app/controllers/application_controller.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 607e5185c..53a40ea4e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -65,8 +65,10 @@ class ApplicationController < ActionController::Base private def update_current_team - if current_user.current_team_id.blank? && - current_user.teams.count > 0 + current_team = Team.find_by_id(current_user.current_team_id) + if (current_team.nil? || !current_user.is_member_of_team?(current_team)) && + current_user.teams.count.positive? + current_user.update( current_team_id: current_user.teams.first.id )