Commit df04400f authored by Birin Sanchez's avatar Birin Sanchez

Avoid raising an exception when the user to be added to an LDAP group

is already a member of it.
Signed-off-by: Birin Sanchez's avatarBirin Sanchez <birin.sanchez@puri.sm>
parent 80b0a91f
Pipeline #9303 passed with stage
in 38 seconds
......@@ -120,14 +120,18 @@ class User(AbstractUser):
def set_ldap_group(self, group_id):
ldap_person = self.get_ldap()
ldap_group = LdapGroup.objects.get(cn=group_id)
ldap_group.members.append(ldap_person.build_dn())
ldap_group.save()
u_dn = ldap_person.build_dn()
if u_dn not in ldap_group.members:
ldap_group.members.append(u_dn)
ldap_group.save()
def remove_ldap_group(self, group_id):
ldap_person = self.get_ldap()
ldap_group = LdapGroup.objects.get(cn=group_id)
ldap_group.members.remove(ldap_person.build_dn())
ldap_group.save()
u_dn = ldap_person.build_dn()
if u_dn in ldap_group.members:
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