Skip to content

Commit

Permalink
Fix group related creation hooks if no user
Browse files Browse the repository at this point in the history
fixes #673

(cherry picked from commit b1725ad)
  • Loading branch information
mdellweg committed Mar 31, 2022
1 parent 5cc0a64 commit 8c2931e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES/673.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed group related creation hooks that failed if no current user could be identified.
10 changes: 5 additions & 5 deletions pulp_container/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,13 @@ def create_namespace_group(self, permissions, parameters):
group = Group.objects.create(
name="{}.{}.{}".format("container.namespace", group_type, self.name)
)
current_user = get_current_authenticated_user()
owners_group = Group.objects.get(
name="{}.{}".format("container.namespace.owners", self.name)
)
assign_perm("core.change_group", owners_group, group)
assign_perm("core.view_group", owners_group, group)
if add_user_to_group:
current_user = get_current_authenticated_user()
if current_user and add_user_to_group:
current_user.groups.add(group)
self.add_for_groups(permissions, group.name)

Expand Down Expand Up @@ -615,7 +615,7 @@ def add_perms_to_distribution_group(self, permissions, parameters):
name="{}.{}.{}".format("container.distribution", group_type, suffix)
)
current_user = get_current_authenticated_user()
if add_user_to_group:
if current_user and add_user_to_group:
current_user.groups.add(group)
self.add_for_groups(permissions, group.name)

Expand Down Expand Up @@ -708,13 +708,13 @@ def create_distribution_group(self, permissions, parameters):
group = Group.objects.create(
name="{}.{}.{}".format("container.distribution", group_type, self.pk)
)
current_user = get_current_authenticated_user()
owners_group = Group.objects.get(
name="{}.{}".format("container.distribution.owners", self.pk)
)
assign_perm("core.change_group", owners_group, group)
assign_perm("core.view_group", owners_group, group)
if add_user_to_group:
current_user = get_current_authenticated_user()
if current_user and add_user_to_group:
current_user.groups.add(group)
self.add_for_groups(permissions, group.name)

Expand Down

0 comments on commit 8c2931e

Please sign in to comment.