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

Remove duplication in pundit policies #2665

Closed
wants to merge 26 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0cb81e0
Avoid unnecessary metaprogramming
chrisroos Jan 25, 2024
5951247
Remove Roles::<class>#level
chrisroos Jan 25, 2024
f0ec514
Explicitly require roles
chrisroos Jan 25, 2024
10fd8cd
Remove unused Roles::Base
chrisroos Jan 25, 2024
b8c557b
Extract Roles.all
chrisroos Jan 25, 2024
12367ba
Extract Roles.names
chrisroos Jan 25, 2024
82e4f54
Move User#role validation to User class
chrisroos Jan 25, 2024
15058cd
Extract Roles.admin
chrisroos Jan 25, 2024
d6eb388
Extract Roles.admin_names
chrisroos Jan 25, 2024
981dc13
Avoid metaprogramming
chrisroos Jan 25, 2024
894f955
Remove duplication in Roles#govuk_admin?
chrisroos Jan 25, 2024
200d0c8
Remove duplication in Roles#publishing_manager?
chrisroos Jan 25, 2024
0d344a8
TEMP: Remove roles_test while experimenting
chrisroos Jan 25, 2024
d8c63de
Move #role_class to Roles
chrisroos Jan 25, 2024
2cd32d9
Extract Roles::<class>.can_manage?
chrisroos Jan 25, 2024
8800e3f
Extract Roles::Base.can_manage?
chrisroos Jan 25, 2024
33c50fb
Remove explicit requires
chrisroos Jan 25, 2024
85ca5d2
Use User#govuk_admin? where possible
chrisroos Jan 25, 2024
3cd82da
Use User#publishing_manager? where possible
chrisroos Jan 25, 2024
7580e96
Extract Roles.find
chrisroos Jan 25, 2024
592d8e5
Add #require_2sv? to roles
chrisroos Jan 25, 2024
60b42f3
Use Roles::<class>.require_2sv?
chrisroos Jan 25, 2024
8288ff9
Remove Roles.admin and .admin_names
chrisroos Jan 25, 2024
2bc2381
Simplify Roles.find
chrisroos Jan 25, 2024
8d6a544
Use metaprogramming to define predicate methods
chrisroos Jan 25, 2024
f9035b4
Return Role class from User#role
chrisroos Jan 25, 2024
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
Prev Previous commit
Next Next commit
Move #role_class to Roles
chrisroos committed Jan 29, 2024
commit d8c63dec3cc5457e19d0f801910b4636d4142334
4 changes: 0 additions & 4 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -305,10 +305,6 @@ def not_setup_2sv?
two_step_status == TWO_STEP_STATUS_NOT_SET_UP
end

def role_class
Roles.const_get(role.classify)
end

def can_manage?(other_user)
manageable_roles.include?(other_user.role)
end
4 changes: 4 additions & 0 deletions lib/roles.rb
Original file line number Diff line number Diff line change
@@ -27,6 +27,10 @@ def self.admin_names
admin.map(&:role_name)
end

def role_class
Roles.const_get(role.classify)
end

def superadmin?
role == Roles::Superadmin.role_name
end