Skip to content
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

Merged

Conversation

cringegnere
Copy link
Contributor

@cringegnere cringegnere commented Mar 22, 2018

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.

@cringegnere cringegnere force-pushed the add-edit-user-backend-permission-check branch 3 times, most recently from 12bcadc to 3e31fdb Compare March 24, 2018 11:11
Copy link
Member

@kennyadsl kennyadsl left a 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)
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

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.

@cringegnere cringegnere force-pushed the add-edit-user-backend-permission-check branch from 3e31fdb to 4d61048 Compare March 26, 2018 18:10
<%= try_spree_current_user.email %>
<% end %>
<% else %>
<%= link_to spree.admin_path do %>
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

@cringegnere cringegnere force-pushed the add-edit-user-backend-permission-check branch from 4d61048 to faa64d8 Compare April 16, 2018 07:46
@cringegnere cringegnere force-pushed the add-edit-user-backend-permission-check branch from faa64d8 to 5b64046 Compare April 16, 2018 10:33
@cringegnere
Copy link
Contributor Author

I think it's all okay now

Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@tvdeyen tvdeyen merged commit 7ccbe3a into solidusio:master Jul 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants