Commit 18a2cdf5 authored by Birin Sanchez's avatar Birin Sanchez

Add logic to make new users members of the right LDAP groups.

Signed-off-by: Birin Sanchez's avatarBirin Sanchez <birin.sanchez@puri.sm>
parent 0d9039d7
......@@ -142,6 +142,8 @@ class CartRegistrationView(RegistrationView):
# Activate Chat and Social
to_activate.append(settings.LM_SERVICES.SOCIAL)
to_activate.append(settings.LM_SERVICES.CHAT)
for lgroup in ['chat', 'social']:
user.set_ldap_group(lgroup)
elif self.reward in complete_carts:
# Register as COMPLETE user
......@@ -154,6 +156,8 @@ class CartRegistrationView(RegistrationView):
to_activate.append(settings.LM_SERVICES.TUNNEL)
to_activate.append(settings.LM_SERVICES.MAIL)
to_activate.append(settings.LM_SERVICES.XMPP)
for lgroup in ['chat', 'social', 'mail', 'xmpp']:
user.set_ldap_group(lgroup)
if self.reward in group_carts:
user.account_type = AccountType.GROUP
......
......@@ -128,6 +128,8 @@ def activate_single_limit(limit, credit_timedelta=None, renewal_date=None):
limit.user.set_ldap_group("social")
elif limit.service == settings.LM_SERVICES.XMPP:
limit.user.set_ldap_group("xmpp")
elif limit.service == settings.LM_SERVICES.GROUP:
pass # Nothing to do for GROUP
else:
raise Exception("Invalid activation attempt. Service not recognised.")
......
......@@ -17,7 +17,6 @@ from limitmonitor.tunnel import TunnelManager
from cryptography.fernet import Fernet
from choicesenum import ChoicesEnum
from choicesenum.django.fields import EnumIntegerField
from invitation.models import Invitation
from woocommerce import API as WOO_API
......@@ -117,10 +116,16 @@ class User(AbstractUser):
ldap_person.change_password(raw_password)
def set_ldap_group(self, group_id):
pass
ldap_person = self.get_ldap()
ldap_group = LdapGroup.objects.get(cn=group_id)
ldap_group.members.append(ldap_person.build_dn())
ldap_group.save()
def remove_ldap_group(self, group_id):
pass
ldap_person = self.get_ldap()
ldap_group = LdapGroup.objects.get(cn=group_id)
ldap_group.members.remove(ldap_person.build_dn())
ldap_group.save()
def woo_get_json(self, query):
......
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