-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow users and groups for creating namespaces.
No-Issue Signed-off-by: James Tanner <[email protected]>
- Loading branch information
Showing
7 changed files
with
278 additions
and
3 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
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,45 @@ | ||
from collections import defaultdict | ||
|
||
from django.db.models import Q | ||
from django.contrib.auth.models import Permission | ||
from django.contrib.contenttypes.models import ContentType | ||
|
||
from pulpcore.plugin.models.role import GroupRole | ||
from pulpcore.plugin.models.role import UserRole | ||
|
||
|
||
def get_users_with_perms_attached_roles( | ||
obj, | ||
with_group_users=True, | ||
only_with_perms_in=None, | ||
include_domain_permissions=True, | ||
include_model_permissions=True, | ||
for_concrete_model=False, | ||
): | ||
# DELETE ONCE https://github.com/pulp/pulpcore/pull/4479 IS RELEASED AND BUMPED IN GALAXY_NG | ||
ctype = ContentType.objects.get_for_model(obj, for_concrete_model=for_concrete_model) | ||
perms = Permission.objects.filter(content_type__pk=ctype.id) | ||
if only_with_perms_in: | ||
codenames = [ | ||
split_perm[-1] | ||
for split_perm in (perm.split(".", maxsplit=1) for perm in only_with_perms_in) | ||
if len(split_perm) == 1 or split_perm[0] == ctype.app_label | ||
] | ||
perms = perms.filter(codename__in=codenames) | ||
|
||
object_query = Q(content_type=ctype, object_id=obj.pk) | ||
if include_domain_permissions and getattr(obj, "pulp_domain", None): | ||
object_query = Q(domain=obj.pulp_domain_id) | object_query | ||
if include_model_permissions: | ||
object_query = Q(object_id=None) | object_query | ||
|
||
user_roles = UserRole.objects.filter(role__permissions__in=perms).filter(object_query) | ||
res = defaultdict(set) | ||
for user_role in user_roles: | ||
res[user_role.user].add(user_role.role.name) | ||
if with_group_users: | ||
group_roles = GroupRole.objects.filter(role__permissions__in=perms).filter(object_query) | ||
for group_role in group_roles: | ||
for user in group_role.group.user_set.all(): | ||
res[user].add(group_role.role.name) | ||
return {k: list(v) for k, v in res.items()} |
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