1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-11-22 09:24:21 +01:00

implementing weight and normalizing each kind of attributes

This commit is contained in:
kakwa 2015-05-31 23:27:04 +02:00
parent af3326db07
commit f8b3df8b58
8 changed files with 28 additions and 14 deletions

View File

@ -122,6 +122,7 @@ password:
logscript: logscript:
description: "Windows login script" description: "Windows login script"
display_name: "Login script" display_name: "Login script"
weight: 100
type: fix type: fix
value: login1.bat value: login1.bat
backends: backends:

View File

@ -21,7 +21,7 @@ class Attributes:
def __init__(self, attributes_file): def __init__(self, attributes_file):
self.attributes_file = attributes_file self.attributes_file = attributes_file
self.backends = Set([]) self.backends = Set([])
self.self_attributes = Set([]) self.self_attributes = {}
self.backend_attributes = {} self.backend_attributes = {}
self.displayed_attributes = {} self.displayed_attributes = {}
self.key = None self.key = None
@ -40,7 +40,7 @@ class Attributes:
if not attr['type'] in types: if not attr['type'] in types:
raise WrongAttributeType(attr['type'], attrid, attributes_file) raise WrongAttributeType(attr['type'], attrid, attributes_file)
if 'self' in attr and attr['self']: if 'self' in attr and attr['self']:
self.self_attributes.add(attrid) self.self_attributes[attrid] = attr
if 'key' in attr and attr['key']: if 'key' in attr and attr['key']:
if not self.key is None: if not self.key is None:
raise DumplicateUserKey(attrid, self.key) raise DumplicateUserKey(attrid, self.key)
@ -51,7 +51,7 @@ class Attributes:
self.backend_attributes[b] = [] self.backend_attributes[b] = []
self.backend_attributes[b].append(attr['backends'][b]) self.backend_attributes[b].append(attr['backends'][b])
if 'search_displayed' in attr and attr['search_displayed']: if 'search_displayed' in attr and attr['search_displayed']:
self.displayed_attributes[attrid] = attr['display_name'] self.displayed_attributes[attrid] = attr
if self.key is None: if self.key is None:
raise MissingUserKey() raise MissingUserKey()
@ -63,7 +63,7 @@ class Attributes:
return self.key return self.key
def _mandatory_check(self, attr): def _mandatory_check(self, attr):
for m in ['description', 'display_name', 'type', 'backends']: for m in ['description', 'display_name', 'type', 'backends', 'weight']:
if m not in self.attributes[attr]: if m not in self.attributes[attr]:
raise MissingKey(m, attr, self.attributes_file) raise MissingKey(m, attr, self.attributes_file)

View File

@ -1,4 +1,4 @@
% for a in attributes: % for a in sorted(attributes.keys(), key=lambda attr: attributes[attr]['weight']):
<% attr = attributes[a] %> <% attr = attributes[a] %>
<div class="form-group"> <div class="form-group">
<div class="input-group"> <div class="input-group">

View File

@ -22,9 +22,9 @@
<table id="RecordTable" class="table table-hover table-condensed tablesorter"> <table id="RecordTable" class="table table-hover table-condensed tablesorter">
<thead> <thead>
<tr> <tr>
%for attr in attrs_list: %for attr in sorted(attrs_list.keys(), key=lambda attr: attrs_list[attr]['weight']):
<th> <th>
${attrs_list[attr]} ${attrs_list[attr]['display_name']}
</th> </th>
% endfor % endfor
<th class="sorter-false"> <th class="sorter-false">
@ -38,7 +38,7 @@
<tbody> <tbody>
%for user in searchresult: %for user in searchresult:
<tr> <tr>
%for attr in attrs_list: %for attr in sorted(attrs_list.keys(), key=lambda attr: attrs_list[attr]['weight']):
<td> <td>
% if attr in searchresult[user]: % if attr in searchresult[user]:
${searchresult[user][attr]} ${searchresult[user][attr]}

View File

@ -22,9 +22,9 @@
<table id="RecordTable" class="table table-hover table-condensed tablesorter"> <table id="RecordTable" class="table table-hover table-condensed tablesorter">
<thead> <thead>
<tr> <tr>
%for attr in attrs_list: %for attr in sorted(attrs_list.keys(), key=lambda attr: attrs_list[attr]['weight']):
<th> <th>
${attrs_list[attr]} ${attrs_list[attr]['display_name']}
</th> </th>
% endfor % endfor
</tr> </tr>
@ -32,7 +32,7 @@
<tbody> <tbody>
%for user in searchresult: %for user in searchresult:
<tr> <tr>
%for attr in attrs_list: %for attr in sorted(attrs_list.keys(), key=lambda attr: attrs_list[attr]['weight']):
<td> <td>
% if attr in searchresult[user]: % if attr in searchresult[user]:
${searchresult[user][attr]} ${searchresult[user][attr]}

View File

@ -3,6 +3,7 @@ cn:
display_name: "Display Name" display_name: "Display Name"
type: string type: string
search_displayed: True search_displayed: True
weight: 30
autofill: autofill:
function: cn function: cn
args: args:
@ -11,11 +12,13 @@ cn:
backends: backends:
ldap: cn ldap: cn
ad: CN ad: CN
first-name: first-name:
description: "First name of the user" description: "First name of the user"
display_name: "First Name" display_name: "First Name"
search_displayed: True search_displayed: True
type: string type: string
weight: 20
backends: backends:
ldap: givenName ldap: givenName
ad: givenName ad: givenName
@ -23,6 +26,7 @@ name:
description: "Family name of the user" description: "Family name of the user"
display_name: "Name" display_name: "Name"
search_displayed: True search_displayed: True
weight: 10
type: string type: string
backends: backends:
ldap: sn ldap: sn
@ -30,8 +34,8 @@ name:
email: email:
description: "Email of the user" description: "Email of the user"
display_name: "Name" display_name: "Name"
search_displayed: True
type: email type: email
weight: 40
autofill: autofill:
function: email function: email
args: args:
@ -47,6 +51,7 @@ uid:
search_displayed: True search_displayed: True
key: True key: True
type: string type: string
weight: 50
autofill: autofill:
function: uid function: uid
args: args:
@ -58,6 +63,7 @@ uid:
uidNumber: uidNumber:
description: "User ID Number of the user" description: "User ID Number of the user"
display_name: "UID Number" display_name: "UID Number"
weight: 60
type: int type: int
autofill: autofill:
function: uidNumber function: uidNumber
@ -70,6 +76,7 @@ uidNumber:
gidNumber: gidNumber:
description: "Group ID Number of the user" description: "Group ID Number of the user"
display_name: "GID Number" display_name: "GID Number"
weight: 70
type: int type: int
default: 10000 default: 10000
backends: backends:
@ -78,6 +85,7 @@ gidNumber:
shell: shell:
description: "Shell of the user" description: "Shell of the user"
display_name: "Shell" display_name: "Shell"
weight: 80
self: True self: True
type: stringlist type: stringlist
values: values:
@ -90,6 +98,7 @@ shell:
home: home:
description: "Home user path" description: "Home user path"
display_name: "Home" display_name: "Home"
weight: 90
type: string type: string
autofill: autofill:
function: home function: home
@ -104,6 +113,7 @@ home:
password: password:
description: "Password of the user" description: "Password of the user"
display_name: "Password" display_name: "Password"
weight: 31
self: True self: True
type: password type: password
backends: backends:
@ -112,6 +122,7 @@ password:
logscript: logscript:
description: "Windows login script" description: "Windows login script"
display_name: "Login script" display_name: "Login script"
weight: 100
type: fix type: fix
value: login1.bat value: login1.bat
backends: backends:

View File

@ -3,6 +3,7 @@ cn:
display_name: "Display Name" display_name: "Display Name"
type: notatype type: notatype
key: True key: True
weight: 10
autofill: autofill:
function: cn function: cn
args: args:
@ -16,6 +17,7 @@ first-name:
description: "First name of the user" description: "First name of the user"
display_name: "First Name" display_name: "First Name"
type: string type: string
weight: 10
backends: backends:
ldap: givenName ldap: givenName
ad: givenName ad: givenName

View File

@ -21,7 +21,7 @@ class TestError(object):
def testGetSelfAttributes(self): def testGetSelfAttributes(self):
inv = Attributes('./tests/cfg/attributes.yml') inv = Attributes('./tests/cfg/attributes.yml')
ret = inv.get_selfattributes() ret = inv.get_selfattributes()
expected = Set(['password', 'shell']) expected = {'password': {'backends': {'ad': 'userPassword', 'ldap': 'userPassword'}, 'display_name': 'Password', 'description': 'Password of the user', 'weight': 31, 'self': True, 'type': 'password'}, 'shell': {'backends': {'ad': 'SHELL', 'ldap': 'shell'}, 'display_name': 'Shell', 'description': 'Shell of the user', 'weight': 80, 'values': ['/bin/bash', '/bin/zsh', '/bin/sh'], 'self': True, 'type': 'stringlist'}}
assert ret == expected assert ret == expected
def testGetSelfAttributes(self): def testGetSelfAttributes(self):
@ -33,7 +33,7 @@ class TestError(object):
def testGetSearchAttributes(self): def testGetSearchAttributes(self):
inv = Attributes('./tests/cfg/attributes.yml') inv = Attributes('./tests/cfg/attributes.yml')
ret = inv.get_search_attributes() ret = inv.get_search_attributes()
expected = {'first-name': 'First Name', 'cn': 'Display Name', 'name': 'Name', 'uid': 'UID', 'email': 'Name'} expected = {'first-name': {'backends': {'ad': 'givenName', 'ldap': 'givenName'}, 'display_name': 'First Name', 'description': 'First name of the user', 'weight': 20, 'search_displayed': True, 'type': 'string'}, 'cn': {'autofill': {'function': 'cn', 'args': ['$first-name', '$name']}, 'backends': {'ad': 'CN', 'ldap': 'cn'}, 'display_name': 'Display Name', 'description': 'Firt Name and Display Name', 'weight': 30, 'search_displayed': True, 'type': 'string'}, 'name': {'backends': {'ad': 'sn', 'ldap': 'sn'}, 'display_name': 'Name', 'description': 'Family name of the user', 'weight': 10, 'search_displayed': True, 'type': 'string'}, 'uid': {'display_name': 'UID', 'description': 'UID of the user', 'weight': 50, 'autofill': {'function': 'uid', 'args': ['$first-name', '$last-name']}, 'backends': {'ad': 'UID', 'ldap': 'uid'}, 'key': True, 'search_displayed': True, 'type': 'string'}}
assert ret == expected assert ret == expected
def testGetBackendAttributes(self): def testGetBackendAttributes(self):