fix bug with changing user own role from admin to normal user

This commit is contained in:
Mojca Lorber 2017-04-12 16:56:10 +02:00
parent 3d9323c8d7
commit 27c661d7c4
2 changed files with 16 additions and 3 deletions

View file

@ -147,8 +147,15 @@ function initUpdateRoles() {
"ajax:success",
"[data-id='update-role-form']",
function (e, data, status, xhr) {
// Reload the whole table
usersDatatable.ajax.reload();
// If user does'n have permission to view the team anymore
// he/she is redirected to teams page
if (data.new_path) {
location.replace(data.new_path);
}
else {
// Reload the whole table
usersDatatable.ajax.reload();
}
}
)
.on(

View file

@ -16,9 +16,15 @@ module Users
def update
respond_to do |format|
if @user_t.update(update_params)
# If user is administrator of team,
# and he/she changes his/her role
# he/she should be redirected to teams page
new_path = teams_path if @user_t.user == @current_user &&
@user_t.role != 'admin'
format.json do
render json: {
status: :ok
status: :ok,
new_path: new_path
}
end
else