From 27c661d7c42aa4780d9f062149cfdaa8b6e04b38 Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Wed, 12 Apr 2017 16:56:10 +0200 Subject: [PATCH] fix bug with changing user own role from admin to normal user --- app/assets/javascripts/users/settings/teams/show.js | 11 +++++++++-- .../users/settings/user_teams_controller.rb | 8 +++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/users/settings/teams/show.js b/app/assets/javascripts/users/settings/teams/show.js index 8eba8bc85..0ba029f14 100644 --- a/app/assets/javascripts/users/settings/teams/show.js +++ b/app/assets/javascripts/users/settings/teams/show.js @@ -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( diff --git a/app/controllers/users/settings/user_teams_controller.rb b/app/controllers/users/settings/user_teams_controller.rb index fc1b677e8..4ed45c2ef 100644 --- a/app/controllers/users/settings/user_teams_controller.rb +++ b/app/controllers/users/settings/user_teams_controller.rb @@ -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