-
-
Notifications
You must be signed in to change notification settings - Fork 932
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor access to
rubygem
in Policies, cleanup policies. (#4833)
Clean up how the forbidden message is sent from pundit Remove unused methods
- Loading branch information
1 parent
430d749
commit 1f308c8
Showing
15 changed files
with
65 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,4 +56,10 @@ def destroy? | |
def search? | ||
index? | ||
end | ||
|
||
private | ||
|
||
def current_user?(record_user) | ||
user && user == record_user | ||
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
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 |
---|---|---|
@@ -1,19 +1,18 @@ | ||
class OIDC::RubygemTrustedPublisherPolicy < ApplicationPolicy | ||
class Scope < ApplicationPolicy::Scope | ||
def resolve | ||
scope.none | ||
end | ||
end | ||
|
||
delegate :rubygem, to: :record | ||
|
||
def show? | ||
record.rubygem.owned_by?(user) | ||
rubygem.owned_by?(user) | ||
end | ||
|
||
def create? | ||
record.rubygem.owned_by?(user) | ||
rubygem.owned_by?(user) | ||
end | ||
|
||
def destroy? | ||
record.rubygem.owned_by?(user) | ||
rubygem.owned_by?(user) | ||
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 |
---|---|---|
@@ -1,15 +1,14 @@ | ||
class OwnershipCallPolicy < ApplicationPolicy | ||
class Scope < ApplicationPolicy::Scope | ||
def resolve | ||
scope.none | ||
end | ||
end | ||
|
||
delegate :rubygem, to: :record | ||
|
||
def create? | ||
record.rubygem.owned_by?(user) && record.user == user | ||
rubygem.owned_by?(user) && current_user?(record.user) | ||
end | ||
|
||
def close? | ||
record.rubygem.owned_by?(user) | ||
rubygem.owned_by?(user) | ||
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 |
---|---|---|
@@ -1,15 +1,14 @@ | ||
class OwnershipPolicy < ApplicationPolicy | ||
class Scope < ApplicationPolicy::Scope | ||
def resolve | ||
scope.none # unused | ||
end | ||
end | ||
|
||
delegate :rubygem, to: :record | ||
|
||
def create? | ||
record.rubygem.owned_by?(user) && record.authorizer == user | ||
rubygem.owned_by?(user) && current_user?(record.authorizer) | ||
end | ||
|
||
def destroy? | ||
record.rubygem.owned_by?(user) | ||
rubygem.owned_by?(user) | ||
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 |
---|---|---|
@@ -1,20 +1,18 @@ | ||
class OwnershipRequestPolicy < ApplicationPolicy | ||
class Scope < ApplicationPolicy::Scope | ||
def resolve | ||
scope.none | ||
end | ||
end | ||
|
||
delegate :rubygem, to: :record | ||
|
||
def create? | ||
return false unless record.user == user | ||
Pundit.policy!(user, record.rubygem).request_ownership? | ||
current_user?(record.user) && Pundit.policy!(user, rubygem).request_ownership? | ||
end | ||
|
||
def approve? | ||
record.rubygem.owned_by?(user) | ||
rubygem.owned_by?(user) | ||
end | ||
|
||
def close? | ||
(user.present? && record.user == user) || record.rubygem.owned_by?(user) | ||
current_user?(record.user) || rubygem.owned_by?(user) | ||
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
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
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