Browse Source

offer a way to disable LDAP fixes #225

Jocelyn Delande 10 years ago
parent
commit
3d10865f0f
3 changed files with 18 additions and 10 deletions
  1. 4 0
      README.md
  2. 11 10
      coin/mixins.py
  3. 3 0
      coin/settings.py

+ 4 - 0
README.md

@@ -66,6 +66,10 @@ settings:
 At this point, you should setup your database.  Recommended is postgreSQL,
 but you might be able to use SQLite.  For more information, see https://www.illyse.org/projects/ils-si/wiki/Mise_en_place_environnement_de_dev
 
+If you don't want to use a LDAP, just set in your `settings_local.py`
+
+    LDAP_ENABLE = False
+
 The first time, you need to create the database, create a superuser, and
 import some base data to play with:
 

+ 11 - 10
coin/mixins.py

@@ -2,10 +2,9 @@
 from __future__ import unicode_literals
 
 from django.db import transaction
-
+from django.conf import settings
 
 class CoinLdapSyncMixin(object):
-
     """
     Ce mixin est à utiliser lorsqu'il s'agit de définir un modèle
     à synchroniser avec le LDAP. Le modèle doit définir les méthodes :
@@ -38,17 +37,19 @@ class CoinLdapSyncMixin(object):
         # Sauvegarde dans le LDAP
         # Si la sauvegarde LDAP échoue, Rollback la sauvegarde en base, sinon
         # commit
-        try:
-            self.sync_to_ldap(creation=creation,update_fields=update_fields)
-        except:
-            raise
+        if settings.LDAP_ACTIVATE:
+            try:
+                self.sync_to_ldap(creation=creation,update_fields=update_fields)
+            except:
+                raise
 
     @transaction.atomic
     def delete(self, *args, **kwargs):
         # Supprime de la base de donnée (mais sans commit, cf decorator)
         super(CoinLdapSyncMixin, self).delete(*args, **kwargs)
 
-        try:
-            self.delete_from_ldap()
-        except:
-            raise
+        if settings.LDAP_ACTIVATE:
+            try:
+                self.delete_from_ldap()
+            except:
+                raise

+ 3 - 0
coin/settings.py

@@ -230,6 +230,9 @@ TEST_RUNNER = 'django.test.runner.DiscoverRunner'
 
 GRAPHITE_SERVER = "http://graphite-dev.illyse.org"
 
+# Do we use LDAP or not
+LDAP_ACTIVATE=True
+
 # LDAP Base DNs
 LDAP_USER_BASE_DN = "ou=users,ou=unix,o=ILLYSE,l=Villeurbanne,st=RHA,c=FR"
 LDAP_GROUP_BASE_DN = "ou=groups,ou=unix,o=ILLYSE,l=Villeurbanne,st=RHA,c=FR"