-
-
Notifications
You must be signed in to change notification settings - Fork 931
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Avo-related Pundit policies into Admin:: namespace (#4745)
* Move all policies under Admin:: namespace * Add basic ApplicationPolicy for userland policies * Add hack around avo not using authorization_policy everywhere yet (fixed in Avo 3)
- Loading branch information
1 parent
7ec6cbf
commit b547946
Showing
99 changed files
with
1,285 additions
and
1,087 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Admin::ApiKeyRubygemScopePolicy < Admin::ApplicationPolicy | ||
class Scope < Admin::ApplicationPolicy::Scope | ||
def resolve | ||
scope.all | ||
end | ||
end | ||
|
||
def avo_show? | ||
policy!(user, record.ownership).avo_show? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# frozen_string_literal: true | ||
|
||
class Admin::ApplicationPolicy | ||
include Admin::Concerns::PolicyHelpers | ||
include SemanticLogger::Loggable | ||
|
||
attr_reader :user, :record | ||
|
||
def initialize(user, record) | ||
@user = user | ||
@record = record | ||
end | ||
|
||
def avo_index? | ||
false | ||
end | ||
|
||
def avo_show? | ||
false | ||
end | ||
|
||
def avo_create? | ||
false | ||
end | ||
|
||
def avo_new? | ||
avo_create? | ||
end | ||
|
||
def avo_update? | ||
false | ||
end | ||
|
||
def avo_edit? | ||
avo_update? | ||
end | ||
|
||
def avo_destroy? | ||
false | ||
end | ||
|
||
def avo_search? | ||
avo_index? | ||
end | ||
|
||
def act_on? | ||
false | ||
end | ||
|
||
def self.has_association(assocation) # rubocop:disable Naming/PredicateName | ||
%w[create attach detach destroy edit].each do |action| | ||
define_method(:"#{action}_#{assocation}?") { false } | ||
end | ||
define_method(:"show_#{assocation}?") { policy!(user, record).avo_show? } | ||
alias_method :"view_#{assocation}?", :avo_show? | ||
end | ||
|
||
class Scope | ||
include Admin::Concerns::PolicyHelpers | ||
|
||
def initialize(user, scope) | ||
@user = user | ||
@scope = scope | ||
end | ||
|
||
def resolve | ||
raise NotImplementedError, "You must define #resolve in #{self.class}" | ||
end | ||
|
||
private | ||
|
||
attr_reader :user, :scope | ||
end | ||
end |
4 changes: 2 additions & 2 deletions
4
app/policies/audit_policy.rb → app/policies/admin/audit_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/policies/deletion_policy.rb → app/policies/admin/deletion_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Admin::DependencyPolicy < Admin::ApplicationPolicy | ||
class Scope < Admin::ApplicationPolicy::Scope | ||
def resolve | ||
scope.all | ||
end | ||
end | ||
|
||
def avo_show? | ||
rubygems_org_admin? | ||
end | ||
end |
4 changes: 2 additions & 2 deletions
4
app/policies/events/rubygem_event_policy.rb → ...cies/admin/events/rubygem_event_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/policies/events/user_event_policy.rb → ...olicies/admin/events/user_event_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/policies/gem_download_policy.rb → app/policies/admin/gem_download_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/policies/gem_name_reservation_policy.rb → ...cies/admin/gem_name_reservation_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/policies/gem_typo_exception_policy.rb → ...licies/admin/gem_typo_exception_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/policies/geoip_info_policy.rb → app/policies/admin/geoip_info_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/policies/ip_address_policy.rb → app/policies/admin/ip_address_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/policies/link_verification_policy.rb → ...olicies/admin/link_verification_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Admin::LinksetPolicy < Admin::ApplicationPolicy | ||
class Scope < Admin::ApplicationPolicy::Scope | ||
def resolve | ||
scope.all | ||
end | ||
end | ||
|
||
def avo_index? | ||
policy!(user, Rubygem).avo_index? | ||
end | ||
|
||
def avo_show? | ||
policy!(user, record.rubygem).avo_show? | ||
end | ||
end |
4 changes: 2 additions & 2 deletions
4
app/policies/log_ticket_policy.rb → app/policies/admin/log_ticket_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/policies/maintenance_tasks/run_policy.rb → ...ies/admin/maintenance_tasks/run_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/policies/oidc/api_key_role_policy.rb → ...olicies/admin/oidc/api_key_role_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/policies/oidc/id_token_policy.rb → app/policies/admin/oidc/id_token_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
.../oidc/pending_trusted_publisher_policy.rb → .../oidc/pending_trusted_publisher_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/policies/oidc/provider_policy.rb → app/policies/admin/oidc/provider_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
.../oidc/rubygem_trusted_publisher_policy.rb → .../oidc/rubygem_trusted_publisher_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...trusted_publisher/github_action_policy.rb → ...trusted_publisher/github_action_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/policies/ownership_policy.rb → app/policies/admin/ownership_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/policies/rubygem_policy.rb → app/policies/admin/rubygem_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/policies/sendgrid_event_policy.rb → app/policies/admin/sendgrid_event_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/policies/user_policy.rb → app/policies/admin/user_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/policies/version_policy.rb → app/policies/admin/version_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/policies/web_hook_policy.rb → app/policies/admin/web_hook_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class Admin::WebauthnCredentialPolicy < Admin::ApplicationPolicy | ||
class Scope < Admin::ApplicationPolicy::Scope | ||
def resolve | ||
scope.all | ||
end | ||
end | ||
|
||
has_association :user | ||
|
||
def avo_show? | ||
policy!(user, record.user).avo_show? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class Admin::WebauthnVerificationPolicy < Admin::ApplicationPolicy | ||
class Scope < Admin::ApplicationPolicy::Scope | ||
def resolve | ||
scope.all | ||
end | ||
end | ||
|
||
has_association :user | ||
|
||
def avo_show? | ||
policy!(user, record.user).avo_show? | ||
end | ||
end |
Oops, something went wrong.