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

Clarify that our only user role is "admin" and simplify code #13047

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mkllnk
Copy link
Member

@mkllnk mkllnk commented Dec 18, 2024

What? Why?

Whenever I needed to make a user account admin in the console I had to type Spree::Role.find_by(name: "admin"). This was unnecessarily long, especially since we don't use any other roles. The database seeding was also adding the "user" role but we never use it. So here are a few steps to simplify this:

  • A new method Spree::Role.admin to access that role easily.
  • Removing the option of the user role from the UI so that people don't wonder what it's for.
  • Simplify code better prepared for getting rid of Spree::Role altogether

Shall we replace Spree::Role.admin with an admin flag on the user?

I would love to hear your thoughts around this. It would replace two database tables with one boolean column on spree_users. I'm sure it would have a positive effect on performance and simplify the code base further. And I think that I could do that in one or two hours.

What should we test?

Specs cover this quite well. We can't test the setup of a new instance. I tested db:reset and ofn:sample_data. So I would suggest a minimal check of the worst case scenario:

  • Sign up as new enterprise user.
  • Verify that you don't have super-admin access.
  • Make that user super-admin. Check.
  • Remove super-admin flag from the user. Check.

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

We only ever check for the admin role.
We are now creating the role on demand which removes the need for
seeding it as well.
We have only one role, so let's get rid of the unneeded method.

Now we are in a better place to get rid of Spree::Role and replace it
with a simple boolean.
The privileges of a user should never change within a request
life cycle. The `spree_roles` association is very small, between 0 and 2
items are quickly searched in memory without the need of additional
database queries.

From memory, I've seen a lot of spree_roles queries in log files per
request. This should reduce it to one.
@mkllnk mkllnk added the user facing changes Thes pull requests affect the user experience label Dec 18, 2024
@mkllnk mkllnk self-assigned this Dec 18, 2024
@mkllnk mkllnk marked this pull request as ready for review December 18, 2024 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user facing changes Thes pull requests affect the user experience
Projects
Status: Code review 🔎
Development

Successfully merging this pull request may close these issues.

1 participant