Merge pull request #472 from okriuchykhin/ok_SCI_984

Check that user is a member of a team when switching to it [SCI-984]
This commit is contained in:
okriuchykhin 2017-02-07 09:36:46 +01:00 committed by GitHub
commit e2de3c92e7

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