forked from pulp/pulp_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request pulp#679 from gerrod3/rbac
Add RBAC support
- Loading branch information
Showing
13 changed files
with
925 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added RBAC support. |
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,30 @@ | ||
from django.conf import settings | ||
|
||
|
||
# Access Condition methods that can be used with PyPI access policies | ||
|
||
|
||
def index_has_perm(request, view, action, perm="python.view_pythondistribution"): | ||
"""Access Policy condition that checks if the user has the perm on the index(distro).""" | ||
if request.user.has_perm(perm): | ||
return True | ||
if settings.DOMAIN_ENABLED: | ||
if request.user.has_perm(perm, obj=request.pulp_domain): | ||
return True | ||
return request.user.has_perm(perm, obj=view.distribution) | ||
|
||
|
||
def index_has_repo_perm(request, view, action, perm="python.view_pythonrepository"): | ||
""" | ||
Access Policy condition that checks if the user has the perm on the index's repository. | ||
If index doesn't have a repository, then default return True. | ||
""" | ||
if request.user.has_perm(perm): | ||
return True | ||
if settings.DOMAIN_ENABLED: | ||
if request.user.has_perm(perm, obj=request.pulp_domain): | ||
return True | ||
if repo := view.distribution.repository: | ||
return request.user.has_perm(perm, obj=repo.cast()) | ||
return True |
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,29 @@ | ||
# Generated by Django 4.2.10 on 2024-06-14 01:25 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('python', '0012_add_domain'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name='pythondistribution', | ||
options={'default_related_name': '%(app_label)s_%(model_name)s', 'permissions': [('manage_roles_pythondistribution', 'Can manage roles on python distributions')]}, | ||
), | ||
migrations.AlterModelOptions( | ||
name='pythonpublication', | ||
options={'default_related_name': '%(app_label)s_%(model_name)s', 'permissions': [('manage_roles_pythonpublication', 'Can manage roles on python publications')]}, | ||
), | ||
migrations.AlterModelOptions( | ||
name='pythonremote', | ||
options={'default_related_name': '%(app_label)s_%(model_name)s', 'permissions': [('manage_roles_pythonremote', 'Can manage roles on python remotes')]}, | ||
), | ||
migrations.AlterModelOptions( | ||
name='pythonrepository', | ||
options={'default_related_name': '%(app_label)s_%(model_name)s', 'permissions': [('sync_pythonrepository', 'Can start a sync task'), ('modify_pythonrepository', 'Can modify content of the repository'), ('manage_roles_pythonrepository', 'Can manage roles on python repositories'), ('repair_pythonrepository', 'Can repair repository versions')]}, | ||
), | ||
] |
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
Oops, something went wrong.