From 8ad28687fa35be3e3a493d84253a27f6c858bc57 Mon Sep 17 00:00:00 2001 From: Michał Górny Date: Tue, 17 Sep 2013 17:40:13 +0200 Subject: Import ACLField from our forked django-ldapdb. We will work on getting a more generic field upstream. For now, let's just keep it local. --- okupy/accounts/models.py | 3 ++- okupy/common/fields.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 okupy/common/fields.py diff --git a/okupy/accounts/models.py b/okupy/accounts/models.py index 277f470..4da7ee4 100644 --- a/okupy/accounts/models.py +++ b/okupy/accounts/models.py @@ -3,9 +3,10 @@ from django.conf import settings from django.db import models from ldapdb.models.fields import (CharField, IntegerField, ListField, - FloatField, ACLField, DateField) + FloatField, DateField) import ldapdb.models +from okupy.common.fields import ACLField from okupy.crypto.models import EncryptedPKModel diff --git a/okupy/common/fields.py b/okupy/common/fields.py new file mode 100644 index 0000000..86754f0 --- /dev/null +++ b/okupy/common/fields.py @@ -0,0 +1,34 @@ +# vim:fileencoding=utf8:et:ts=4:sts=4:sw=4:ft=python + +from django.db.models import fields + +from ldapdb import escape_ldap_filter + +class ACLField(fields.Field): + def _group(self): + return self.name.split('_')[1] + '.group' + + def from_ldap(self, value, connection): + if self._group() in value: + return True + else: + return False + + def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False): + "Returns field's value prepared for database lookup." + return [self.get_prep_lookup(lookup_type, value)] + + def get_db_prep_save(self, value, connection): + return [x.encode(connection.charset) for x in value] + + def get_prep_lookup(self, lookup_type, value): + "Perform preliminary non-db specific lookup checks and conversions" + if value not in (False, True): + raise TypeError("Invalid value") + if lookup_type == 'exact': + if value: + return escape_ldap_filter(self._group()) + else: + raise NotImplementedError( + "Negative lookups on ACLField are not yet implemented") + raise TypeError("ACLField has invalid lookup: %s" % lookup_type) -- cgit v1.2.3-65-gdbad From 7acd7881b61a862cbd819cdb15f7dc48134819d4 Mon Sep 17 00:00:00 2001 From: Michał Górny Date: Tue, 17 Sep 2013 17:41:53 +0200 Subject: Switch travis to the clean branch. --- requirements/base.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/base.txt b/requirements/base.txt index 5861981..038469a 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -2,7 +2,7 @@ django>=1.5 django-auth-ldap>=1.1.4 django-compressor>=1.3 django-otp>=0.1.7 -git+https://github.com/tampakrap/django-ldapdb@okupy#egg=django-ldapdb +git+https://github.com/mgorny/django-ldapdb@bind_as-2#egg=django-ldapdb paramiko>=1.10.1 passlib>=1.6.1 pycrypto>=2.6 -- cgit v1.2.3-65-gdbad