-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable backend footer profile edit link if role cannot edit users #2646
Disable backend footer profile edit link if role cannot edit users #2646
Conversation
12bcadc
to
3e31fdb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution, great job, I just left some comment on how to improve specs. 👍
@@ -6,16 +6,39 @@ | |||
let(:user) { FactoryBot.build_stubbed(:admin_user) } | |||
before do | |||
allow(view).to receive(:try_spree_current_user).and_return(user) | |||
@ability = Object.new.extend(CanCan::Ability) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be a let outside the before block
@@ -6,16 +6,39 @@ | |||
let(:user) { FactoryBot.build_stubbed(:admin_user) } | |||
before do | |||
allow(view).to receive(:try_spree_current_user).and_return(user) | |||
@ability = Object.new.extend(CanCan::Ability) | |||
allow(@controller).to receive(:current_ability).and_return(@ability) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @controller
can be called as controller
without the @
here.
expect(rendered).to have_link(user.email, href: Spree::Core::Engine.routes.url_helpers.edit_admin_user_path(user)) | ||
context "authorized user" do | ||
it "has a user-account-link that links to edit_admin_user_path" do | ||
@ability.can :admin, user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can move this ability setting in a before that lives into the context authorized user
since it will be applied to all its scenarios.
3e31fdb
to
4d61048
Compare
<%= try_spree_current_user.email %> | ||
<% end %> | ||
<% else %> | ||
<%= link_to spree.admin_path do %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it makes sense to link to the root. Maybe we should drop the link entirely (just plain text) if we don't have permissions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
4d61048
to
faa64d8
Compare
faa64d8
to
5b64046
Compare
I think it's all okay now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
A user with a role that can access the backend main page but has no permissions to edit users will get a misleading "Authorization Failure" error.
With this fix the user will be cleanly routed to the main page without displaying any errors.