Applying proper permissions to newly created objects.

fix #366
This commit is contained in:
Antoine Nguyen
2013-01-27 15:56:11 +01:00
parent 1beb18343a
commit 931503261d
3 changed files with 34 additions and 5 deletions
+13 -2
View File
@@ -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://<ldap server address>"
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
<http://packages.python.org/django-auth-ldap/>`_.
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.
+21
View File
@@ -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
-3
View File
@@ -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: