mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-30 20:23:14 +08:00
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:
commit
e2de3c92e7
1 changed files with 12 additions and 9 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue