Jan Dittberner
4b9d8d02ba
- remove all code from osusers.models - add description field to ldapentities.models.LdapGroup - change tasks defined in osusers.tasks to use primitive values as parameters to avoid serialization and model synchronization
57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
from django.conf import settings
|
|
from django.utils.encoding import python_2_unicode_compatible
|
|
from ldapdb.models.fields import (
|
|
CharField,
|
|
IntegerField,
|
|
ListField,
|
|
)
|
|
import ldapdb.models as ldapmodels
|
|
|
|
from passlib.hash import ldap_salted_sha1
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
class LdapGroup(ldapmodels.Model):
|
|
"""
|
|
Class for representing an LDAP group entity.
|
|
|
|
"""
|
|
# LDAP meta-data
|
|
base_dn = settings.GROUP_BASE_DN
|
|
object_classes = ['posixGroup']
|
|
|
|
# posixGroup attributes
|
|
gid = IntegerField(db_column='gidNumber', unique=True)
|
|
name = CharField(db_column='cn', max_length=200, primary_key=True)
|
|
description = CharField(db_column='description')
|
|
members = ListField(db_column='memberUid', blank=True)
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
class LdapUser(ldapmodels.Model):
|
|
"""
|
|
Class for representing an LDAP user entity.
|
|
|
|
"""
|
|
base_dn = settings.USER_BASE_DN
|
|
object_classes = ['account', 'posixAccount']
|
|
|
|
# posixAccount
|
|
uid = IntegerField(db_column='uidNumber', unique=True)
|
|
group = IntegerField(db_column='gidNumber')
|
|
gecos = CharField(db_column='gecos')
|
|
home_directory = CharField(db_column='homeDirectory')
|
|
login_shell = CharField(db_column='loginShell', default='/bin/bash')
|
|
username = CharField(db_column='uid', primary_key=True)
|
|
password = CharField(db_column='userPassword')
|
|
common_name = CharField(db_column='cn')
|
|
|
|
def __str__(self):
|
|
return self.username
|
|
|
|
def set_password(self, password):
|
|
self.password = ldap_salted_sha1.encrypt(password)
|