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

Replace spree roles #13090

Merged
merged 6 commits into from
Jan 31, 2025
Merged

Conversation

mkllnk
Copy link
Member

@mkllnk mkllnk commented Jan 22, 2025

What? Why?

Since we have only one super admin role, we can replace Spree::Role with a simple boolean flag on the user. This makes two database tables redundant and reduces database queries.

What should we test?

  • Make sure that normal users do not accidentally gain admin permissions after deploying this.

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

@mkllnk mkllnk added the technical changes only These pull requests do not contain user facing changes and are grouped in release notes label Jan 22, 2025
@mkllnk mkllnk self-assigned this Jan 22, 2025
@mkllnk mkllnk marked this pull request as ready for review January 22, 2025 04:09
Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

Nice clean up 🧹

Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Great work!

I'm assuming that you're tracking this and will remove the unused DB tables after this has bedded down 👍

Perhaps it's not worth the effort, but I think I see opportunity to tidy up specs a little so have made some suggestions.

@@ -235,8 +235,6 @@ class GatewayWithPassword < PaymentMethod
let(:user) do
new_user = create(:user, email: 'enterprise@hub.com', password: 'blahblah',
password_confirmation: 'blahblah', )
# for some reason unbeknown to me, this new user gets admin permissions by default.
new_user.spree_roles = []
Copy link
Member

Choose a reason for hiding this comment

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

It's reassuring to see this is no longer necessary!

spree_put :update, id: test_user.id, user: { show_api_key_view: true }
expect(response).to redirect_to spree.edit_admin_user_path(test_user)
end

it "re-renders the edit form if error" do
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
user.update!(admin: true)
spree_put :update, id: test_user.id, user: { password: "blah", password_confirmation: "" }

expect(response).to render_template :edit
Copy link
Member

Choose a reason for hiding this comment

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

3 out of 4 tests require an admin user, so we could set it up as an admin user in the beginning.
In fact, the fourth test mocks the admin? method anyway..
Maybe I'll submit a commit.

spec/models/spree/ability_spec.rb Show resolved Hide resolved
spec/models/spree/ability_spec.rb Outdated Show resolved Hide resolved
@dacook
Copy link
Member

dacook commented Jan 24, 2025

Hope you don't mind me joining in!

Copy link
Member Author

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

Nice improvements!

@filipefurtad0 filipefurtad0 self-assigned this Jan 31, 2025
@filipefurtad0 filipefurtad0 added the pr-staged-fr staging.coopcircuits.fr label Jan 31, 2025
@filipefurtad0
Copy link
Contributor

Hey @mkllnk ,

Tried to access the pages:
i) /admin
ii) /admin/zones

As a:

  1. guest -> i) and ii) prompted to login
  2. customer -> i) and ii) unauthorized
  3. enterprise manager -> i) OK; ii) unauthorized
  4. superadmin -> i) and ii) OK

Access rights seem to work the same as before.
Merging.

@filipefurtad0 filipefurtad0 removed the pr-staged-fr staging.coopcircuits.fr label Jan 31, 2025
@filipefurtad0 filipefurtad0 merged commit e216166 into openfoodfoundation:master Jan 31, 2025
35 checks passed
@mkllnk mkllnk deleted the replace-spree-roles branch February 4, 2025 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
technical changes only These pull requests do not contain user facing changes and are grouped in release notes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants