From 931503261d31eac7f66570ef70888a9ead26f706 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Sun, 27 Jan 2013 15:56:11 +0100 Subject: [PATCH] Applying proper permissions to newly created objects. fix #366 --- doc/getting_started/configuration.rst | 15 +++++++++++++-- modoboa/admin/models.py | 21 +++++++++++++++++++++ modoboa/lib/authbackends.py | 3 --- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/doc/getting_started/configuration.rst b/doc/getting_started/configuration.rst index 66e0cd49f..11f1d1622 100644 --- a/doc/getting_started/configuration.rst +++ b/doc/getting_started/configuration.rst @@ -177,7 +177,7 @@ Then, all you have to do is to modify the *settings.py* file: variable, like this:: AUTHENTICATION_BACKENDS = ( - 'django_auth_ldap.backend.LDAPBackend', + 'modoboa.lib.authbackends.LDAPBackend', 'modoboa.lib.authbackends.SimpleBackend', ) @@ -187,16 +187,27 @@ Then, all you have to do is to modify the *settings.py* file: import ldap from django_auth_ldap.config import LDAPSearch + AUTH_LDAP_SERVER_URI = "ldap://" AUTH_LDAP_BIND_DN = "" AUTH_LDAP_BIND_PASSWORD = "" - LDAP_USER_BASE = "ou=users,dc=example,dc=com" + LDAP_USER_BASE = "ou=users,dc=example,dc=com" LDAP_USER_FILTER = "(mail=%(user)s)" AUTH_LDAP_USER_SEARCH = LDAPSearch(LDAP_USER_BASE, ldap.SCOPE_SUBTREE, LDAP_USER_FILTER) + AUTH_LDAP_USER_ATTR_MAP = { + "first_name": "givenName", + "email": "mail", + "last_name": "sn" + } + You will find a detailled documentation `here `_. +Finally, go to *Modoboa > Parameters > admin*, set the +``AUTHENTICATION_TYPE`` parameter to ``LDAP`` and click on the *Save* +blue button. + Once the authentication is properly configured, the users defined in your LDAP directory will be able to connect to *Modoboa*, the associated domain and mailboxes will be automatically created if needed. diff --git a/modoboa/admin/models.py b/modoboa/admin/models.py index 8a88a8c42..a5bfdf0bd 100644 --- a/modoboa/admin/models.py +++ b/modoboa/admin/models.py @@ -1021,10 +1021,22 @@ def populate_callback(sender, user=None, **kwargs): :param sender: ?? :param user: a ``User`` instance """ + from modoboa.lib.permissions import grant_access_to_object + if parameters.get_admin("AUTHENTICATION_TYPE") != "ldap": return if user is None: return + + sadmins = User.objects.filter(is_superuser=True) + + user.groups.add(Group.objects.get(name="SimpleUsers")) + user.save() + events.raiseEvent("AccountCreated", user) + grant_access_to_object(sadmins[0], user, True) + for su in sadmins[1:]: + grant_access_to_object(su, user) + localpart, domname = split_mailbox(user.username) try: domain = Domain.objects.get(name=domname) @@ -1034,11 +1046,20 @@ def populate_callback(sender, user=None, **kwargs): domain.enabled = True domain.quota = 0 domain.save() + events.raiseEvent("CreateDomain", sadmins[0], domain) + grant_access_to_object(sadmins[0], domain, True) + for su in sadmins[1:]: + grant_access_to_object(su, domain) try: mb = Mailbox.objects.get(domain=domain, address=localpart) except Mailbox.DoesNotExist: mb = Mailbox() mb.save_from_user(localpart, domain, user) + events.raiseEvent("CreateMailbox", sadmins[0], mb) + grant_access_to_object(sadmins[0], mb, True) + for su in sadmins[1:]: + grant_access_to_object(su, domain) + try: from django_auth_ldap.backend import populate_user diff --git a/modoboa/lib/authbackends.py b/modoboa/lib/authbackends.py index 7729e7858..b27a05ccd 100644 --- a/modoboa/lib/authbackends.py +++ b/modoboa/lib/authbackends.py @@ -20,7 +20,6 @@ class SimpleBackend(ModelBackend): try: from django_auth_ldap.backend import LDAPBackend as orig_LDAPBackend, _LDAPUser - from modoboa.admin.models import User class LDAPBackend(orig_LDAPBackend): @@ -37,13 +36,11 @@ try: def get_user(self, user_id): user = None - try: user = User.objects.get(pk=user_id) _LDAPUser(self, user=user) # This sets user.ldap_user except User.DoesNotExist: pass - return user except ImportError: