Commit 167e2faf authored by Olga Brani's avatar Olga Brani
Browse files

Merge branch '0.6.4' of https://code.grnet.gr/git/astakos into 0.6.4

parents cdde4aac 1e9df9ae
......@@ -37,12 +37,13 @@ from optparse import make_option
from random import choice
from string import digits, lowercase, uppercase
from uuid import uuid4
from datetime import datetime
from django.core.management.base import BaseCommand, CommandError
from django.core.validators import validate_email
from django.core.exceptions import ValidationError
from astakos.im.models import AstakosUser, AstakosGroup
from astakos.im.models import AstakosUser, AstakosGroup, Membership
from astakos.im.util import reserved_email
from ._common import add_user_permission
......@@ -121,7 +122,7 @@ class Command(BaseCommand):
if groupname is not None:
try:
group = AstakosGroup.objects.get(name=groupname)
user.astakos_groups.add(group)
Membership(group=group, person=user, date_joined=datetime.now()).save()
self.stdout.write('Group: %s added successfully\n' % groupname)
except AstakosGroup.DoesNotExist, e:
self.stdout.write('Group named %s does not exist\n' % groupname)
......
......@@ -233,7 +233,6 @@ class AstakosUser(User):
through='Membership')
__has_signed_terms = False
__groupnames = []
owner = models.ManyToManyField(AstakosGroup, related_name='owner', null=True)
......@@ -243,9 +242,7 @@ class AstakosUser(User):
def __init__(self, *args, **kwargs):
super(AstakosUser, self).__init__(*args, **kwargs)
self.__has_signed_terms = self.has_signed_terms
if self.id:
self.__groupnames = [g.name for g in self.astakos_groups.all()]
else:
if not self.id:
self.is_active = False
@property
......@@ -308,15 +305,6 @@ class AstakosUser(User):
self.activation_sent = None
super(AstakosUser, self).save(**kwargs)
# set group if does not exist
groupname = 'shibboleth' if self.provider == 'shibboleth' else 'default'
if groupname not in self.__groupnames:
try:
group = AstakosGroup.objects.get(name = groupname)
Membership(group=group, person=self, date_joined=datetime.now()).save()
except AstakosGroup.DoesNotExist, e:
logger.exception(e)
def renew_token(self):
md5 = hashlib.md5()
......@@ -576,6 +564,17 @@ def superuser_post_save(sender, instance, **kwargs):
post_save.connect(superuser_post_save, sender=User)
def set_default_group(sender, instance, created, **kwargs):
if not created:
return
try:
default = AstakosGroup.objects.get(name = 'default')
Membership(group=default, person=instance, date_joined=datetime.now()).save()
except AstakosGroup.DoesNotExist, e:
logger.exception(e)
post_save.connect(set_default_group, sender=AstakosUser)
def get_resources():
# use cache
return Resource.objects.select_related().all()
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment