diff --git a/app/controllers/users/settings_controller.rb b/app/controllers/users/settings_controller.rb index 07483f301..8bc45eb7b 100644 --- a/app/controllers/users/settings_controller.rb +++ b/app/controllers/users/settings_controller.rb @@ -350,16 +350,19 @@ class Users::SettingsController < ApplicationController end def user_current_team - @user.current_team_id = params[:user][:current_team_id] - @changed_team = Team.find_by_id(@user.current_team_id) - if params[:user][:current_team_id].present? && @user.save - flash[:success] = t('users.settings.changed_team_flash', - team: @changed_team.name) - redirect_to root_path - else - flash[:alert] = t('users.settings.changed_team_error_flash') - redirect_to :back + team_id = params[:user][:current_team_id].to_i + if @user.teams_ids.include?(team_id) + @user.current_team_id = team_id + @changed_team = Team.find_by_id(@user.current_team_id) + if @user.save + flash[:success] = t('users.settings.changed_team_flash', + team: @changed_team.name) + redirect_to root_path + return + end end + flash[:alert] = t('users.settings.changed_team_error_flash') + redirect_to :back end private