Check that user is a member of a team when switching to it [SCI-984]

This commit is contained in:
Oleksii Kriuchykhin 2017-02-03 16:10:37 +01:00
parent 65bbd81497
commit cc6b518c7f

View file

@ -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