Created
June 8, 2015 12:52
-
-
Save capooti/4dae9703fd0cab47305a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def add_user_in_registered_group(user): | |
from geonode.groups.models import GroupProfile | |
from geonode.people.models import Profile | |
try: | |
gp = GroupProfile.objects.get(slug='registered') | |
except GroupProfile.DoesNotExist: | |
gp = GroupProfile.objects.create( | |
title=_('Registered GeoNode Users'), | |
slug='registered', | |
description=_('Group containg all of the GeoNode users'), | |
access="public", | |
) | |
# assign all existing users to this group | |
for profile in Profile.objects.all(): | |
if profile.username != 'AnonymousUser': | |
gp.join(profile) | |
return | |
# assign user to group | |
gp.join(user) | |
def profile_post_save(instance, sender, **kwargs): | |
"""Make sure the user belongs by default to the anonymous group. | |
This will make sure that anonymous permissions will be granted to the new users.""" | |
from django.contrib.auth.models import Group | |
anon_group, created = Group.objects.get_or_create(name='anonymous') | |
instance.groups.add(anon_group) | |
# keep in sync Profile email address with Account email address | |
if instance.email not in [u'', '', None] and not kwargs.get('raw', False): | |
EmailAddress.objects.filter(user=instance, primary=True).update(email=instance.email) | |
# check if profile is in registered users group | |
add_user_in_registered_group(instance) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment