Skip to content

Commit

Permalink
Only add a User to the Public Group if they aren't already a member
Browse files Browse the repository at this point in the history
  • Loading branch information
scottx611x committed Sep 11, 2018
1 parent 3b45172 commit 12f53c6
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions refinery/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,15 @@ def create_user_profile(sender, instance, created, **kwargs):


@receiver(post_save, sender=User)
def add_user_to_public_group(sender, instance, created, **kwargs):
"""Add users to Public group automatically
"""
def add_user_to_public_group(sender, **kwargs):
"""Add users to Public group automatically"""
user = kwargs["instance"]
public_group = ExtendedGroup.objects.public_group()
# need to check if Public group exists to avoid errors when creating
# user accounts (like superuser and AnonymousUser) before the group
# is created by init_refinery command
if public_group:
instance.groups.add(public_group)
if public_group and user not in public_group.user_set.all():
user.groups.add(public_group)


def create_user_profile_registered(sender, user, request, **kwargs):
Expand Down

0 comments on commit 12f53c6

Please sign in to comment.