mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-11 18:21:04 +08:00
29 lines
777 B
Ruby
29 lines
777 B
Ruby
module Users
|
|
class SettingsController < ApplicationController
|
|
before_action :load_user, only: [
|
|
:user_current_team
|
|
]
|
|
|
|
def user_current_team
|
|
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_back(fallback_location: root_path)
|
|
end
|
|
|
|
private
|
|
|
|
def load_user
|
|
@user = current_user
|
|
end
|
|
end
|
|
end
|