Skip to content

Commit

Permalink
Redirect to account page if editing own user name
Browse files Browse the repository at this point in the history
c.f. `redirect_to_account_page_if_acting_on_own_user` before action in
`UsersController`.

In this case it makes sense to redirect to the specific account page for
editing name.

I missed this in #2497.
  • Loading branch information
floehopper committed Nov 10, 2023
1 parent 8cfa8f3 commit 957034f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/controllers/users/names_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Users::NamesController < ApplicationController
before_action :authenticate_user!
before_action :load_user
before_action :authorize_user
before_action :redirect_to_account_page_if_acting_on_own_user, only: %i[edit]

def edit; end

Expand All @@ -29,4 +30,8 @@ def authorize_user
def user_params
params.require(:user).permit(*current_user.permitted_params.intersection([:name]))
end

def redirect_to_account_page_if_acting_on_own_user
redirect_to edit_account_email_path if current_user == @user
end
end
9 changes: 8 additions & 1 deletion test/controllers/users/names_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ class Users::NamesControllerTest < ActionController::TestCase
context "GET edit" do
context "signed in as Admin user" do
setup do
sign_in(create(:admin_user))
@admin = create(:admin_user)
sign_in(@admin)
end

should "display form with name field" do
Expand Down Expand Up @@ -39,6 +40,12 @@ class Users::NamesControllerTest < ActionController::TestCase

assert_not_authorised
end

should "redirect to account edit email page if admin is acting on their own user" do
get :edit, params: { user_id: @admin }

assert_redirected_to edit_account_email_path
end
end

context "signed in as Normal user" do
Expand Down

0 comments on commit 957034f

Please sign in to comment.