Commit b4aca32d by Őry Máté

dashboard: create user profile on creation

closes #269
parent 65fd2ea6
...@@ -261,7 +261,7 @@ def get_or_create_profile(self): ...@@ -261,7 +261,7 @@ def get_or_create_profile(self):
Group.profile = property(get_or_create_profile) Group.profile = property(get_or_create_profile)
def create_profile(sender, user, request, **kwargs): def create_profile(user):
if not user.pk: if not user.pk:
return False return False
profile, created = Profile.objects.get_or_create(user=user) profile, created = Profile.objects.get_or_create(user=user)
...@@ -272,7 +272,11 @@ def create_profile(sender, user, request, **kwargs): ...@@ -272,7 +272,11 @@ def create_profile(sender, user, request, **kwargs):
logger.exception("Can't create user %s", unicode(user)) logger.exception("Can't create user %s", unicode(user))
return created return created
user_logged_in.connect(create_profile)
def create_profile_hook(sender, user, request, **kwargs):
return create_profile(user)
user_logged_in.connect(create_profile_hook)
if hasattr(settings, 'SAML_ORG_ID_ATTRIBUTE'): if hasattr(settings, 'SAML_ORG_ID_ATTRIBUTE'):
logger.debug("Register save_org_id to djangosaml2 pre_user_save") logger.debug("Register save_org_id to djangosaml2 pre_user_save")
......
...@@ -91,7 +91,7 @@ from vm.models import ( ...@@ -91,7 +91,7 @@ from vm.models import (
from storage.models import Disk from storage.models import Disk
from firewall.models import Vlan, Host, Rule from firewall.models import Vlan, Host, Rule
from .models import (Favourite, Profile, GroupProfile, FutureMember, from .models import (Favourite, Profile, GroupProfile, FutureMember,
ConnectCommand) ConnectCommand, create_profile)
from .store_api import Store, NoStoreException, NotOkException from .store_api import Store, NoStoreException, NotOkException
...@@ -3288,6 +3288,7 @@ class UserCreationView(LoginRequiredMixin, PermissionRequiredMixin, ...@@ -3288,6 +3288,7 @@ class UserCreationView(LoginRequiredMixin, PermissionRequiredMixin,
self.get_group(group_pk) self.get_group(group_pk)
ret = super(UserCreationView, self).post(*args, **kwargs) ret = super(UserCreationView, self).post(*args, **kwargs)
if self.object: if self.object:
create_profile(self.object)
self.object.groups.add(self.group) self.object.groups.add(self.group)
return redirect( return redirect(
reverse('dashboard.views.group-detail', args=[group_pk])) reverse('dashboard.views.group-detail', args=[group_pk]))
......
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 sign in to comment