Skip to content

Commit

Permalink
Add support for removing users/groups from a project and allow to che…
Browse files Browse the repository at this point in the history
…ck for groups with permissions to modify a PR (#815)

Add support for removing users/groups from a project and allow to check for groups with permissions to modify a PR

Related to packit/packit#2078.
Merge before packit/packit#2112.

Reviewed-by: Laura Barcziová
Reviewed-by: Nikola Forró
  • Loading branch information
softwarefactory-project-zuul[bot] authored Oct 10, 2023
2 parents f232a2b + 4ded59c commit 5ad36b6
Show file tree
Hide file tree
Showing 9 changed files with 873 additions and 381 deletions.
16 changes: 10 additions & 6 deletions COMPATIBILITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,16 @@ In case you find any error, please [create a new issue](https://github.com/packi

## Project

| | GitHub | GitLab | Pagure |
| -------------------- | :----: | :----: | :---------------------: |
| `change_token` ||||
| `get_release` ||||
| `get_latest_release` ||||
| `is_private` ||| ✘ (may not be accurate) |
| | GitHub | GitLab | Pagure |
| --------------------------- | :----: | :----: | :---------------------: |
| `change_token` ||||
| `get_release` ||||
| `get_latest_release` ||||
| `is_private` ||| ✘ (may not be accurate) |
| `remove_user` ||||
| `add_group` ||||
| `remove_group` ||||
| `which_groups_can_merge_pr` ||||

## User

Expand Down
27 changes: 26 additions & 1 deletion ogr/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,13 @@ def who_can_merge_pr(self) -> Set[str]:
"""
raise NotImplementedError()

def which_groups_can_merge_pr(self) -> Set[str]:
"""
Returns:
Names of all groups that have permission to modify pull request.
"""
raise NotImplementedError()

def can_merge_pr(self, username: str) -> bool:
"""
Args:
Expand All @@ -1525,6 +1532,15 @@ def add_user(self, user: str, access_level: AccessLevel) -> None:
"""
raise NotImplementedError()

def remove_user(self, user: str) -> None:
"""
Remove user from project.
Args:
user: Username of the user.
"""
raise NotImplementedError()

def request_access(self) -> None:
"""
Request an access to the project (cannot specify access level to be granted;
Expand All @@ -1540,7 +1556,16 @@ def add_group(self, group: str, access_level: AccessLevel) -> None:
group: Name of the group.
access_level: Permissions for the group.
"""
raise NotImplementedError
raise NotImplementedError()

def remove_group(self, group: str) -> None:
"""
Remove group from project.
Args:
group: Name of the group.
"""
raise NotImplementedError()

def get_issue_list(
self,
Expand Down
16 changes: 15 additions & 1 deletion ogr/services/pagure/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ def who_can_merge_pr(self) -> Set[str]:
users.update(project["access_users"]["owner"])
return users

def which_groups_can_merge_pr(self) -> Set[str]:
groups: Set[str] = set()
project = self.get_project_info()
groups.update(project["access_groups"]["admin"])
groups.update(project["access_groups"]["commit"])
return groups

def can_merge_pr(self, username) -> bool:
return username in self.who_can_merge_pr()

Expand Down Expand Up @@ -364,18 +371,25 @@ def get_git_urls(self) -> Dict[str, str]:
def add_user(self, user: str, access_level: AccessLevel) -> None:
self.add_user_or_group(user, access_level, "user")

def remove_user(self, user: str) -> None:
self.add_user_or_group(user, None, "user")

def add_group(self, group: str, access_level: AccessLevel):
self.add_user_or_group(group, access_level, "group")

def remove_group(self, group: str) -> None:
self.add_user_or_group(group, None, "group")

def add_user_or_group(
self, user: str, access_level: AccessLevel, user_type
self, user: str, access_level: Optional[AccessLevel], user_type: str
) -> None:
access_dict = {
AccessLevel.pull: "ticket",
AccessLevel.triage: "ticket",
AccessLevel.push: "commit",
AccessLevel.admin: "commit",
AccessLevel.maintain: "admin",
None: "",
}
response = self._call_project_api_raw(
"git",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
_requre:
DataTypes: 1
key_strategy: StorageKeysInspectSimple
version_storage_file: 3
requests.sessions:
send:
POST:
https://pagure.io/api/0/-/whoami:
- metadata:
latency: 1.5459933280944824
module_call_list:
- unittest.case
- requre.record_and_replace
- tests.integration.pagure.test_generic_commands
- ogr.abstract
- ogr.services.pagure.user
- ogr.abstract
- ogr.services.pagure.service
- ogr.abstract
- ogr.services.pagure.service
- ogr.abstract
- ogr.services.pagure.service
- requests.sessions
- requre.objects
- requre.cassette
- requests.sessions
- send
output:
__store_indicator: 2
_content:
username: nforro
_next: null
elapsed: 1.437793
encoding: utf-8
headers:
Connection: Upgrade, Keep-Alive
Content-Length: '27'
Content-Security-Policy: default-src 'self';script-src 'self' 'nonce-YbTLzdpZsoRGvtdZ7DCMmOGdg';
style-src 'self' 'nonce-YbTLzdpZsoRGvtdZ7DCMmOGdg'; object-src 'none';base-uri
'self';img-src 'self' https:;connect-src 'self' https://pagure.io:8088;frame-src
https://docs.pagure.org;frame-ancestors https://pagure.io;
Content-Type: application/json
Date: Mon, 09 Oct 2023 17:15:46 GMT
Keep-Alive: timeout=5, max=100
Referrer-Policy: same-origin
Server: Apache/2.4.37 (Red Hat Enterprise Linux) OpenSSL/1.1.1k mod_wsgi/4.6.4
Python/3.6
Set-Cookie: pagure=eyJfcGVybWFuZW50Ijp0cnVlLCJjc3JmX3Rva2VuIjoiODE0YTJhNWQ0YjQzOGM3OTY4YjQwYWJjM2RhZjQzOWQ3NDgyOTY5YiJ9.GAXGwg.cB5Z_0W9PEVmAL8KqI62vnD2It8;
Expires=Thu, 09-Nov-2023 17:15:46 GMT; Secure; HttpOnly; Path=/
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Upgrade: h2,h2c
X-Content-Type-Options: nosniff
X-Frame-Options: ALLOW-FROM https://pagure.io/
X-Xss-Protection: 1; mode=block
raw: !!binary ""
reason: OK
status_code: 200
- metadata:
latency: 0.21212029457092285
module_call_list:
- unittest.case
- requre.record_and_replace
- tests.integration.pagure.test_generic_commands
- ogr.abstract
- ogr.services.pagure.service
- ogr.abstract
- ogr.services.pagure.user
- ogr.abstract
- ogr.services.pagure.service
- ogr.abstract
- ogr.services.pagure.service
- ogr.abstract
- ogr.services.pagure.service
- requests.sessions
- requre.objects
- requre.cassette
- requests.sessions
- send
output:
__store_indicator: 2
_content:
username: nforro
_next: null
elapsed: 0.211102
encoding: utf-8
headers:
Connection: Keep-Alive
Content-Length: '27'
Content-Security-Policy: default-src 'self';script-src 'self' 'nonce-QDs6fDoljKPi1SC515oakfMHO';
style-src 'self' 'nonce-QDs6fDoljKPi1SC515oakfMHO'; object-src 'none';base-uri
'self';img-src 'self' https:;connect-src 'self' https://pagure.io:8088;frame-src
https://docs.pagure.org;frame-ancestors https://pagure.io;
Content-Type: application/json
Date: Mon, 09 Oct 2023 17:15:47 GMT
Keep-Alive: timeout=5, max=99
Referrer-Policy: same-origin
Server: Apache/2.4.37 (Red Hat Enterprise Linux) OpenSSL/1.1.1k mod_wsgi/4.6.4
Python/3.6
Set-Cookie: pagure=eyJfcGVybWFuZW50Ijp0cnVlLCJjc3JmX3Rva2VuIjoiODE0YTJhNWQ0YjQzOGM3OTY4YjQwYWJjM2RhZjQzOWQ3NDgyOTY5YiJ9.GAXGww.OfCgXTkfPa8SPrlDwdSU5kZXu-Y;
Expires=Thu, 09-Nov-2023 17:15:47 GMT; Secure; HttpOnly; Path=/
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
X-Content-Type-Options: nosniff
X-Frame-Options: ALLOW-FROM https://pagure.io/
X-Xss-Protection: 1; mode=block
raw: !!binary ""
reason: OK
status_code: 200
https://pagure.io/api/0/playground-nforro/git/modifyacls:
- metadata:
latency: 19.634831428527832
module_call_list:
- unittest.case
- requre.record_and_replace
- tests.integration.pagure.test_generic_commands
- ogr.abstract
- ogr.services.pagure.project
- ogr.abstract
- ogr.services.pagure.project
- ogr.abstract
- ogr.services.pagure.project
- ogr.abstract
- ogr.services.pagure.service
- ogr.abstract
- ogr.services.pagure.service
- requests.sessions
- requre.objects
- requre.cassette
- requests.sessions
- send
output:
__store_indicator: 2
_content:
access_groups:
admin: []
collaborator: []
commit:
- packit-test-group
ticket: []
access_users:
admin: []
collaborator: []
commit: []
owner:
- nforro
ticket: []
close_status: []
custom_keys: []
date_created: '1696871156'
date_modified: '1696871747'
description: playground-nforro
full_url: https://pagure.io/playground-nforro
fullname: playground-nforro
id: 17033
milestones: {}
name: playground-nforro
namespace: null
parent: null
priorities: {}
tags: []
url_path: playground-nforro
user:
full_url: https://pagure.io/user/nforro
fullname: "Nikola Forr\xF3"
name: nforro
url_path: user/nforro
_next: null
elapsed: 19.633572
encoding: utf-8
headers:
Connection: Keep-Alive
Content-Length: '864'
Content-Security-Policy: default-src 'self';script-src 'self' 'nonce-mvNfk0cfS75DNM84tn2Fe8nyQ';
style-src 'self' 'nonce-mvNfk0cfS75DNM84tn2Fe8nyQ'; object-src 'none';base-uri
'self';img-src 'self' https:;connect-src 'self' https://pagure.io:8088;frame-src
https://docs.pagure.org;frame-ancestors https://pagure.io;
Content-Type: application/json
Date: Mon, 09 Oct 2023 17:15:47 GMT
Keep-Alive: timeout=5, max=98
Referrer-Policy: same-origin
Server: Apache/2.4.37 (Red Hat Enterprise Linux) OpenSSL/1.1.1k mod_wsgi/4.6.4
Python/3.6
Set-Cookie: pagure=eyJfcGVybWFuZW50Ijp0cnVlLCJjc3JmX3Rva2VuIjoiODE0YTJhNWQ0YjQzOGM3OTY4YjQwYWJjM2RhZjQzOWQ3NDgyOTY5YiJ9.GAXG1g.y5tBPWMYVtlSSPKuDgmSGZTSDTM;
Expires=Thu, 09-Nov-2023 17:16:06 GMT; Secure; HttpOnly; Path=/
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
X-Content-Type-Options: nosniff
X-Frame-Options: ALLOW-FROM https://pagure.io/
X-Xss-Protection: 1; mode=block
raw: !!binary ""
reason: OK
status_code: 200
- metadata:
latency: 0.5101637840270996
module_call_list:
- unittest.case
- requre.record_and_replace
- tests.integration.pagure.test_generic_commands
- ogr.abstract
- ogr.services.pagure.project
- ogr.abstract
- ogr.services.pagure.project
- ogr.abstract
- ogr.services.pagure.project
- ogr.abstract
- ogr.services.pagure.service
- ogr.abstract
- ogr.services.pagure.service
- requests.sessions
- requre.objects
- requre.cassette
- requests.sessions
- send
output:
__store_indicator: 2
_content:
access_groups:
admin: []
collaborator: []
commit: []
ticket: []
access_users:
admin: []
collaborator: []
commit: []
owner:
- nforro
ticket: []
close_status: []
custom_keys: []
date_created: '1696871156'
date_modified: '1696871747'
description: playground-nforro
full_url: https://pagure.io/playground-nforro
fullname: playground-nforro
id: 17033
milestones: {}
name: playground-nforro
namespace: null
parent: null
priorities: {}
tags: []
url_path: playground-nforro
user:
full_url: https://pagure.io/user/nforro
fullname: "Nikola Forr\xF3"
name: nforro
url_path: user/nforro
_next: null
elapsed: 0.508932
encoding: utf-8
headers:
Connection: Keep-Alive
Content-Length: '833'
Content-Security-Policy: default-src 'self';script-src 'self' 'nonce-Y9LXANSEnP79mFdqD9aKtJZDk';
style-src 'self' 'nonce-Y9LXANSEnP79mFdqD9aKtJZDk'; object-src 'none';base-uri
'self';img-src 'self' https:;connect-src 'self' https://pagure.io:8088;frame-src
https://docs.pagure.org;frame-ancestors https://pagure.io;
Content-Type: application/json
Date: Mon, 09 Oct 2023 17:16:06 GMT
Keep-Alive: timeout=5, max=97
Referrer-Policy: same-origin
Server: Apache/2.4.37 (Red Hat Enterprise Linux) OpenSSL/1.1.1k mod_wsgi/4.6.4
Python/3.6
Set-Cookie: pagure=eyJfcGVybWFuZW50Ijp0cnVlLCJjc3JmX3Rva2VuIjoiODE0YTJhNWQ0YjQzOGM3OTY4YjQwYWJjM2RhZjQzOWQ3NDgyOTY5YiJ9.GAXG1w.n5c2qYiApdkTDkzQafv9-J8VM90;
Expires=Thu, 09-Nov-2023 17:16:07 GMT; Secure; HttpOnly; Path=/
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
X-Content-Type-Options: nosniff
X-Frame-Options: ALLOW-FROM https://pagure.io/
X-Xss-Protection: 1; mode=block
raw: !!binary ""
reason: OK
status_code: 200
Loading

0 comments on commit 5ad36b6

Please sign in to comment.