reg again

This commit is contained in:
holger.trampe 2019-12-12 23:41:30 +01:00
parent 45fd25ef70
commit 675571bccf
2 changed files with 23 additions and 14 deletions

View File

@ -8,21 +8,30 @@ from django.contrib.auth.models import Permission
@receiver(post_save, sender=User)
def create_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance, agency=instance.agency, parent=instance.parent)
if(len(user_agency)) == 1:
Profile.objects.create(user=instance, agency=instance.agency)
'''
Wenn ein neuer Nutzer angelegt wird und dies der erste der Agentur ist,
erhält dieser automatisch alle verfügbaren Rechte!
'''
user_agency = User.objects.filter(profile__agency__pk=instance.agency.pk)
if len(user_agency) == 1:
tempuser = user_agency[0]
temprof = Profile
for ele in temprof._meta.permissions:
tempperm = Permission.objects.get(codename=ele[0])
tempuser.user_permissions.add(tempperm)
tempuser.profile.func = 'lead'
#tempuser.profile.parent = tempuser
'''
Wenn ein neuer Nutzer angelegt wird und dies der erste der Agentur ist,
erhält dieser automatisch alle verfügbaren Rechte!
'''
user_agency = User.objects.filter(profile__agency__pk=instance.agency.pk)
if len(user_agency) == 1:
tempuser = user_agency[0]
temprof = Profile
for ele in temprof._meta.permissions:
tempperm = Permission.objects.get(codename=ele[0])
tempuser.user_permissions.add(tempperm)
tempuser.profile.func = 'lead'
tempuser.profile.parent = tempuser
tempuser.save()
else:
Profile.objects.create(user=instance, agency=instance.agency, parent=instance.parent)
user_agency = User.objects.filter(profile__agency__pk=instance.agency.pk)
tempuser.profile.func = 'external'
tempuser.profile.parent=parent
tempuser.profile.agency=agency
tempuser.profile.user = user
tempuser.save()