-
-
Couldn't load subscription status.
- Fork 968
🛂 Update Handling of Gem Permissions #5849
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
Open
landongrindheim
wants to merge
12
commits into
master
Choose a base branch
from
landon/push-ownership-logic-to-rubygem-model
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3202054
Make ownership an organization OR user concern
landongrindheim 4ad20fd
Add role-based methods to Organization
landongrindheim e5c7c3e
Introduce GemPermissions for finer grained access
landongrindheim d70f77e
Use GemPermissions for policies
landongrindheim 30706cf
Allow anyone with push access to view events
landongrindheim 964234a
Rename can_admin? -> can_perform_gem_admin?
landongrindheim c2596bb
Update ownership-based policies to use permissions
landongrindheim 16c0340
Move to permissions-based access
landongrindheim f9deac5
Remove unused method
landongrindheim cffa861
Consider `can_push?` instead of ownership
landongrindheim f155580
Remove Rubygem#owned_by?
landongrindheim 9e868f7
Test that maintainers cannot invite new members
landongrindheim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -32,7 +32,7 @@ def validate_gem_and_version | |
| if [email protected]? | ||
| render plain: response_with_mfa_warning(t(:this_rubygem_could_not_be_found)), | ||
| status: :not_found | ||
| elsif !@rubygem.owned_by?(@api_key.user) | ||
| elsif !can_delete_gem?(@api_key.user) | ||
| render_forbidden response_with_mfa_warning("You do not have permission to delete this gem.") | ||
| else | ||
| begin | ||
|
|
@@ -45,4 +45,8 @@ def validate_gem_and_version | |
| end | ||
| end | ||
| end | ||
|
|
||
| def can_delete_gem?(user) | ||
| GemPermissions.new(@rubygem, user).can_push? | ||
| end | ||
| end | ||
This file contains hidden or 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,55 @@ | ||
| class GemPermissions | ||
| def initialize(rubygem, user) | ||
| @rubygem = rubygem | ||
| @user = user | ||
| end | ||
|
|
||
| def can_push? | ||
| return false if user.blank? | ||
|
|
||
| if rubygem.owned_by_organization? | ||
| org_member_in_role?(:maintainer) || user_in_role?(:maintainer) | ||
| else | ||
| user_in_role?(:maintainer) | ||
| end | ||
| end | ||
|
|
||
| def can_manage_owners? | ||
| role_granted?(:owner) | ||
| end | ||
|
|
||
| def can_perform_gem_admin? | ||
| role_granted?(:admin) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_reader :rubygem, :user | ||
|
|
||
| def role_granted?(minimum_role) | ||
| return false if @user.blank? | ||
|
|
||
| if rubygem.owned_by_organization? | ||
| org_member_in_role?(minimum_role) | ||
| else | ||
| user_in_role?(minimum_role) | ||
| end | ||
| end | ||
|
|
||
| def org_member_in_role?(minimum_role) | ||
| case minimum_role | ||
| when :maintainer | ||
| rubygem.organization.user_is_member?(user) | ||
| when :admin | ||
| rubygem.organization.administered_by?(user) | ||
| when :owner | ||
| rubygem.organization.owned_by?(user) | ||
| else | ||
| false | ||
| end | ||
| end | ||
|
|
||
| def user_in_role?(minimum_role) | ||
| rubygem.ownerships.user_with_minimum_role(user, minimum_role).exists? | ||
| end | ||
| end | ||
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -32,7 +32,7 @@ def process | |
| end | ||
|
|
||
| def authorize | ||
| (rubygem.pushable? && (api_key.user? || find_pending_trusted_publisher)) || owner.owns_gem?(rubygem) || notify_unauthorized | ||
| (rubygem.pushable? && (api_key.user? || find_pending_trusted_publisher)) || owner.can_push?(rubygem) || notify_unauthorized | ||
| end | ||
|
|
||
| def verify_gem_scope | ||
|
|
@@ -260,7 +260,7 @@ def republish_notification(version) | |
| notify("It appears that #{version.full_name} did not finish pushing.\n" \ | ||
| "Please contact [email protected] for assistance if you pushed this gem more than a minute ago.", 409) | ||
| else | ||
| different_owner = "pushed by a previous owner of this gem " unless owner.owns_gem?(version.rubygem) | ||
| different_owner = "pushed by a previous owner of this gem " unless owner.can_push?(version.rubygem) | ||
| notify("A yanked version #{different_owner}already exists (#{version.full_name}).\n" \ | ||
| "Repushing of gem versions is not allowed. Please use a new version and retry", 409) | ||
| end | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to leave these here for now, but I foresee a future where org- (and team-) based permissions are checked in a separate class.