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

Merged
merged 5 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/spree/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def self.admin_created?

# Checks whether the specified user is a superadmin, with full control of the instance
def admin?
spree_roles.where(name: "admin").any?
spree_roles.any? { |role| role.name == "admin" }
Copy link
Member

Choose a reason for hiding this comment

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

Good solution. I would have simply reached for elvis (@admin ||= ), but this is no more queries, and ensures that if the roles are updated during a request, we get the up-to-date value.

end

# Send devise-based user emails asyncronously via ActiveJob
Expand Down
1 change: 0 additions & 1 deletion spec/controllers/admin/order_cycles_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ module Admin
order_cycles: 6,
proxy_orders: 1,
schedules: 1,
spree_roles: 9,
spree_variants: 8,
tags: 1
},
Expand Down
2 changes: 0 additions & 2 deletions spec/lib/reports/orders_and_distributors_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@
subject # build context first

expect { subject.table_rows }.to query_database [
"Spree::Role Exists?",
"Spree::Role Exists?",
"SQL",
"Spree::LineItem Load",
"Spree::PaymentMethod Load",
Expand Down
Loading