GRN2-268: Redirecting user back to page they came from in Manage Users (#950)

* GRN2-268: Redirecting user back to page they come from in Manage Users

* re-factoring
This commit is contained in:
etiennevvv 2020-02-10 16:57:07 -05:00 committed by farhatahmad
parent 68b231dbdb
commit 01c93b1f67
2 changed files with 23 additions and 6 deletions

View File

@ -75,20 +75,23 @@ class AdminsController < ApplicationController
# GET /admins/edit/:user_uid # GET /admins/edit/:user_uid
def edit_user def edit_user
session[:prev_url] = request.referer if request.referer.present?
end end
# POST /admins/ban/:user_uid # POST /admins/ban/:user_uid
def ban_user def ban_user
@user.roles = [] @user.roles = []
@user.add_role :denied @user.add_role :denied
redirect_to admins_path, flash: { success: I18n.t("administrator.flash.banned") }
redirect_back fallback_location: admins_path, flash: { success: I18n.t("administrator.flash.banned") }
end end
# POST /admins/unban/:user_uid # POST /admins/unban/:user_uid
def unban_user def unban_user
@user.remove_role :denied @user.remove_role :denied
@user.add_role :user @user.add_role :user
redirect_to admins_path, flash: { success: I18n.t("administrator.flash.unbanned") }
redirect_back fallback_location: admins_path, flash: { success: I18n.t("administrator.flash.unbanned") }
end end
# POST /admins/approve/:user_uid # POST /admins/approve/:user_uid
@ -97,7 +100,7 @@ class AdminsController < ApplicationController
send_user_approved_email(@user) send_user_approved_email(@user)
redirect_to admins_path, flash: { success: I18n.t("administrator.flash.approved") } redirect_back fallback_location: admins_path, flash: { success: I18n.t("administrator.flash.approved") }
end end
# POST /admins/approve/:user_uid # POST /admins/approve/:user_uid
@ -106,7 +109,7 @@ class AdminsController < ApplicationController
@user.undelete! @user.undelete!
@user.rooms.deleted.each(&:undelete!) @user.rooms.deleted.each(&:undelete!)
redirect_to admins_path, flash: { success: I18n.t("administrator.flash.restored") } redirect_back fallback_location: admins_path, flash: { success: I18n.t("administrator.flash.restored") }
end end
# POST /admins/invite # POST /admins/invite
@ -128,7 +131,14 @@ class AdminsController < ApplicationController
send_password_reset_email(@user) send_password_reset_email(@user)
redirect_to admins_path, flash: { success: I18n.t("administrator.flash.reset_password") } if session[:prev_url].present?
redirect_path = session[:prev_url]
session.delete(:prev_url)
else
redirect_path = admins_path
end
redirect_to redirect_path, flash: { success: I18n.t("administrator.flash.reset_password") }
end end
# SITE SETTINGS # SITE SETTINGS

View File

@ -80,7 +80,14 @@ class UsersController < ApplicationController
# PATCH /u/:user_uid/edit # PATCH /u/:user_uid/edit
def update def update
profile = params[:setting] == "password" ? change_password_path(@user) : edit_user_path(@user) profile = params[:setting] == "password" ? change_password_path(@user) : edit_user_path(@user)
redirect_path = current_user.admin_of?(@user) ? admins_path : profile if session[:prev_url].present?
path = session[:prev_url]
session.delete(:prev_url)
else
path = admins_path
end
redirect_path = current_user.admin_of?(@user) ? path : profile
if params[:setting] == "password" if params[:setting] == "password"
# Update the users password. # Update the users password.