-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor unauthorized access handling in SolidusAdmin
Enhance the SolidusAdmin authorization mechanism to improve user experience during unauthorized access attempts. Now, instead of previous behavior, users are redirected to a dedicated unauthorized page when attempting to access a resource for which they do not have permission.
- Loading branch information
1 parent
89617d8
commit b06342d
Showing
4 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1><%= t('solidus_admin.errors.authorization.access_denied.title') %></h1> | ||
<p><%= t('solidus_admin.errors.authorization.access_denied.description') %></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
en: | ||
solidus_admin: | ||
errors: | ||
authorization: | ||
access_denied: | ||
title: "Access Denied" | ||
description: "You are not authorized to access this page." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,22 @@ def index | |
allow_any_instance_of(SolidusAdmin::BaseController).to receive(:spree_current_user).and_return(nil) | ||
end | ||
|
||
it "redirects to unauthorized" do | ||
it "redirects to unauthorized for no user" do | ||
get :index | ||
expect(response).to redirect_to '/unauthorized' | ||
end | ||
|
||
context "with a user without update permission" do | ||
before do | ||
user = create(:user, email: '[email protected]') | ||
allow_any_instance_of(SolidusAdmin::BaseController).to receive(:spree_current_user).and_return(user) | ||
end | ||
|
||
it "redirects to unauthorized" do | ||
get :index | ||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
end | ||
|
||
context "successful request" do | ||
|