2017-02-09 22:10:45 +08:00
|
|
|
module Users
|
|
|
|
class SettingsController < ApplicationController
|
|
|
|
before_action :load_user, only: [
|
|
|
|
:user_current_team
|
|
|
|
]
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2017-02-09 22:10:45 +08:00
|
|
|
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
|
2017-02-03 23:10:37 +08:00
|
|
|
end
|
2017-02-09 22:10:45 +08:00
|
|
|
flash[:alert] = t('users.settings.changed_team_error_flash')
|
2017-12-08 00:59:23 +08:00
|
|
|
redirect_back(fallback_location: root_path)
|
2016-10-11 17:40:14 +08:00
|
|
|
end
|
|
|
|
|
2017-02-09 22:10:45 +08:00
|
|
|
private
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2017-02-09 22:10:45 +08:00
|
|
|
def load_user
|
|
|
|
@user = current_user
|
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
end
|