Skip to content

Commit

Permalink
Move pundit policy has_association above methods (#4743)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinemde authored May 26, 2024
1 parent 39fae38 commit 4924fec
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 71 deletions.
8 changes: 4 additions & 4 deletions app/policies/api_key_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ def resolve
end
end

def avo_show?
Pundit.policy!(user, record.owner).avo_show?
end

has_association :api_key_rubygem_scope
has_association :ownership
has_association :oidc_id_token

def avo_show?
Pundit.policy!(user, record.owner).avo_show?
end
end
4 changes: 2 additions & 2 deletions app/policies/deletion_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ def resolve
end
end

has_association :version

def avo_index?
rubygems_org_admin?
end

def avo_show?
rubygems_org_admin?
end

has_association :version
end
6 changes: 3 additions & 3 deletions app/policies/events/rubygem_event_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ def resolve
end
end

def avo_index? = rubygems_org_admin?
def avo_show? = rubygems_org_admin?

has_association :rubygem
has_association :ip_address

def avo_index? = rubygems_org_admin?
def avo_show? = rubygems_org_admin?
end
6 changes: 3 additions & 3 deletions app/policies/events/user_event_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ def resolve
end
end

def avo_index? = rubygems_org_admin?
def avo_show? = rubygems_org_admin?

has_association :user
has_association :ip_address

def avo_index? = rubygems_org_admin?
def avo_show? = rubygems_org_admin?
end
4 changes: 2 additions & 2 deletions app/policies/geoip_info_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ def resolve
end
end

has_association :ip_addresses

def avo_index? = rubygems_org_admin?
def avo_show? = rubygems_org_admin?

has_association :ip_addresses
end
6 changes: 3 additions & 3 deletions app/policies/ip_address_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ def resolve
end
end

def avo_index? = rubygems_org_admin?
def avo_show? = rubygems_org_admin?

has_association :user_events
has_association :rubygem_events

def avo_index? = rubygems_org_admin?
def avo_show? = rubygems_org_admin?
end
6 changes: 3 additions & 3 deletions app/policies/oidc/api_key_role_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ def resolve
end
end

has_association :provider
has_association :id_tokens

def avo_index? = rubygems_org_admin?
def avo_show? = rubygems_org_admin?
def avo_create? = rubygems_org_admin?
def avo_update? = rubygems_org_admin?
def act_on? = rubygems_org_admin?

has_association :provider
has_association :id_tokens
end
6 changes: 3 additions & 3 deletions app/policies/oidc/id_token_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ def resolve
end
end

def avo_index? = rubygems_org_admin?
def avo_show? = rubygems_org_admin?

has_association :provider
has_association :api_key_role
has_association :api_key

def avo_index? = rubygems_org_admin?
def avo_show? = rubygems_org_admin?
end
6 changes: 3 additions & 3 deletions app/policies/oidc/pending_trusted_publisher_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ def resolve
end
end

def avo_index? = rubygems_org_admin?
def avo_show? = rubygems_org_admin?

has_association :rubygem
has_association :trusted_publisher

def avo_index? = rubygems_org_admin?
def avo_show? = rubygems_org_admin?
end
4 changes: 2 additions & 2 deletions app/policies/oidc/provider_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ def resolve
end
end

has_association :api_key_roles

def avo_index? = rubygems_org_admin?
def avo_show? = rubygems_org_admin?
def avo_create? = rubygems_org_admin?
def avo_update? = rubygems_org_admin?
def act_on? = rubygems_org_admin?

has_association :api_key_roles
end
6 changes: 3 additions & 3 deletions app/policies/oidc/rubygem_trusted_publisher_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ def resolve
end
end

def avo_index? = rubygems_org_admin?
def avo_show? = rubygems_org_admin?

has_association :rubygem
has_association :trusted_publisher

def avo_index? = rubygems_org_admin?
def avo_show? = rubygems_org_admin?
end
6 changes: 3 additions & 3 deletions app/policies/oidc/trusted_publisher/github_action_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ def resolve
end
end

def avo_index? = rubygems_org_admin?
def avo_show? = rubygems_org_admin?

has_association :trusted_publishers
has_association :rubygem_trusted_publishers
has_association :pending_trusted_publishers
has_association :rubygems
has_association :api_keys

def avo_index? = rubygems_org_admin?
def avo_show? = rubygems_org_admin?
end
4 changes: 2 additions & 2 deletions app/policies/ownership_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ def resolve
end
end

has_association :api_key_rubygem_scopes

def avo_show?
rubygems_org_admin?
end

has_association :api_key_rubygem_scopes
end
25 changes: 12 additions & 13 deletions app/policies/rubygem_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@ def resolve
end
end

def avo_index?
rubygems_org_admin?
end

def avo_show?
rubygems_org_admin?
end

def act_on?
rubygems_org_admin?
end

has_association :versions
has_association :latest_version
has_association :ownerships
Expand All @@ -34,6 +22,17 @@ def act_on?
has_association :gem_download
has_association :audits
has_association :link_verifications

has_association :oidc_rubygem_trusted_publishers

def avo_index?
rubygems_org_admin?
end

def avo_show?
rubygems_org_admin?
end

def act_on?
rubygems_org_admin?
end
end
24 changes: 12 additions & 12 deletions app/policies/user_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ def resolve
end
end

def avo_index?
rubygems_org_admin?
end

def avo_show?
rubygems_org_admin?
end

def act_on?
rubygems_org_admin?
end

has_association :ownerships
has_association :rubygems
has_association :subscriptions
Expand All @@ -34,4 +22,16 @@ def act_on?
has_association :webauthn_credentials
has_association :webauthn_verification
has_association :events

def avo_index?
rubygems_org_admin?
end

def avo_show?
rubygems_org_admin?
end

def act_on?
rubygems_org_admin?
end
end
8 changes: 4 additions & 4 deletions app/policies/version_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def resolve
end
end

has_association :dependencies
has_association :gem_download
has_association :deletion

def avo_index?
rubygems_org_admin?
end
Expand All @@ -20,8 +24,4 @@ def avo_show?
def act_on?
rubygems_org_admin?
end

has_association :dependencies
has_association :gem_download
has_association :deletion
end
4 changes: 2 additions & 2 deletions app/policies/web_hook_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ def resolve
end
end

has_association :audits

def avo_index?
rubygems_org_admin?
end
Expand All @@ -16,6 +18,4 @@ def avo_show?
def act_on?
rubygems_org_admin?
end

has_association :audits
end
4 changes: 2 additions & 2 deletions app/policies/webauthn_credential_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ def resolve
end
end

has_association :user

def avo_show?
Pundit.policy!(user, record.user).avo_show?
end

has_association :user
end
4 changes: 2 additions & 2 deletions app/policies/webauthn_verification_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ def resolve
end
end

has_association :user

def avo_show?
Pundit.policy!(user, record.user).avo_show?
end

has_association :user
end

0 comments on commit 4924fec

Please sign in to comment.