add docstrings for ldapentities app

This commit is contained in:
Jan Dittberner 2014-05-31 14:29:21 +02:00
parent ef47cf7862
commit 1466d3c93a
4 changed files with 78 additions and 5 deletions

View file

@ -0,0 +1,7 @@
"""
This app takes care of managing LDAP entities, at the moment these are:
* LDAP groups (:py:class:`ldapentities.models.LdapGroup`).
* LDAP users (:py:class:`ldapentities.models.LdapUser`)
"""

View file

@ -1,3 +1,10 @@
"""
Admin classes for easy `django admin`_ based administration of LDAP entities.
.. _django admin: https://docs.djangoproject.com/en/dev/ref/contrib/admin/
"""
from django.contrib import admin from django.contrib import admin
from .models import ( from .models import (
@ -7,12 +14,22 @@ from .models import (
class LdapGroupAdmin(admin.ModelAdmin): class LdapGroupAdmin(admin.ModelAdmin):
"""
Admin class for :py:class:`LDAP group <ldapentities.models.LdapGroup>`
entities.
"""
exclude = ['dn', 'members'] exclude = ['dn', 'members']
list_display = ['name', 'gid'] list_display = ['name', 'gid']
search_fields = ['name'] search_fields = ['name']
class LdapUserAdmin(admin.ModelAdmin): class LdapUserAdmin(admin.ModelAdmin):
"""
Admin class for :py:class:`LDAP user <ldapentities.models.LdapUser>`
entities.
"""
exclude = ['dn', 'password'] exclude = ['dn', 'password']
list_display = ['username', 'uid'] list_display = ['username', 'uid']
search_fields = ['username'] search_fields = ['username']

View file

@ -1,3 +1,12 @@
"""
This module defines models for LDAP entities.
The models are based on :py:class:`ldapmodels.Model` from `django-ldapdb`_.
.. _django-ldapdb: https://github.com/jlaine/django-ldapdb#readme
"""
from django.conf import settings from django.conf import settings
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
from ldapdb.models.fields import ( from ldapdb.models.fields import (
@ -13,44 +22,87 @@ from passlib.hash import ldap_salted_sha1
@python_2_unicode_compatible @python_2_unicode_compatible
class LdapGroup(ldapmodels.Model): class LdapGroup(ldapmodels.Model):
""" """
Class for representing an LDAP group entity. Class for representing an LDAP group entity with objectClass `posixGroup`.
.. seealso:: :rfc:`2307#section-4`
.. py:attribute:: base_dn
a string containing the LDAP base distinguished name
.. py:attribute:: members
contains the list of `memberUid` attributes
""" """
# LDAP meta-data # LDAP meta-data
base_dn = settings.GROUP_BASE_DN base_dn = settings.GROUP_BASE_DN
#: list of object classes
object_classes = ['posixGroup'] object_classes = ['posixGroup']
# posixGroup attributes # posixGroup attributes
#: group id (`gidNumber`)
gid = IntegerField(db_column='gidNumber', unique=True) gid = IntegerField(db_column='gidNumber', unique=True)
#: group name (`cn`)
name = CharField(db_column='cn', max_length=200, primary_key=True) name = CharField(db_column='cn', max_length=200, primary_key=True)
#: group description (`description`)
description = CharField(db_column='description') description = CharField(db_column='description')
members = ListField(db_column='memberUid', blank=True) members = ListField(db_column='memberUid', blank=True)
def __str__(self): def __str__(self):
"""
Get a string representation of this LDAP group.
"""
return self.name return self.name
@python_2_unicode_compatible @python_2_unicode_compatible
class LdapUser(ldapmodels.Model): class LdapUser(ldapmodels.Model):
""" """
Class for representing an LDAP user entity. Class for representing an LDAP user entity with objectClasses `account` and
`posixAccount`.
.. seealso:: :rfc:`2307#section-4`, :rfc:`4524#section-3.1`
.. py:attribute:: base_dn
a string containing the LDAP base distinguished name
""" """
base_dn = settings.USER_BASE_DN base_dn = settings.USER_BASE_DN
#: list of object classes
object_classes = ['account', 'posixAccount'] object_classes = ['account', 'posixAccount']
# posixAccount # posixAccount
#: user id (`uidNumber`)
uid = IntegerField(db_column='uidNumber', unique=True) uid = IntegerField(db_column='uidNumber', unique=True)
#: group id (`gidNumber`) of the user's primary group
group = IntegerField(db_column='gidNumber') group = IntegerField(db_column='gidNumber')
#: GECOS field (`gecos`)
gecos = CharField(db_column='gecos') gecos = CharField(db_column='gecos')
#: home directory (`homeDirectory`)
home_directory = CharField(db_column='homeDirectory') home_directory = CharField(db_column='homeDirectory')
#: login shell (`loginShell`)
login_shell = CharField(db_column='loginShell', default='/bin/bash') login_shell = CharField(db_column='loginShell', default='/bin/bash')
#: user name (`uid`)
username = CharField(db_column='uid', primary_key=True) username = CharField(db_column='uid', primary_key=True)
#: password (`userPassword`) in an LDAP compatible format
password = CharField(db_column='userPassword') password = CharField(db_column='userPassword')
#: common name (`cn`)
common_name = CharField(db_column='cn') common_name = CharField(db_column='cn')
def __str__(self): def __str__(self):
"""
Get a string representation of this LDAP user.
"""
return self.username return self.username
def set_password(self, password): def set_password(self, password):
"""
Sets the encrypted password of the user from the given clear text
password.
:param str password: the clear text password
"""
self.password = ldap_salted_sha1.encrypt(password) self.password = ldap_salted_sha1.encrypt(password)

View file

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.