diff options
author | 2013-09-17 09:06:24 -0700 | |
---|---|---|
committer | 2013-09-17 09:06:24 -0700 | |
commit | 2c5771e8d4b972aacf0595a9a6917feef4261563 (patch) | |
tree | 3a20b35b913faa264f948f13aa8f65b4ceb3073b | |
parent | Merge pull request #94 from mgorny/tests-fix (diff) | |
parent | Switch travis to the clean branch. (diff) | |
download | identity.gentoo.org-2c5771e8d4b972aacf0595a9a6917feef4261563.tar.gz identity.gentoo.org-2c5771e8d4b972aacf0595a9a6917feef4261563.tar.bz2 identity.gentoo.org-2c5771e8d4b972aacf0595a9a6917feef4261563.zip |
Merge pull request #95 from mgorny/clean-ldapdb
Import ACLField from our forked django-ldapdb.
-rw-r--r-- | okupy/accounts/models.py | 3 | ||||
-rw-r--r-- | okupy/common/fields.py | 34 | ||||
-rw-r--r-- | requirements/base.txt | 2 |
3 files changed, 37 insertions, 2 deletions
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) 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 |