Révision d21f26c6
Ajouté par Jérôme Schneider il y a plus de 9 ans
mandaye/backends/ldap_back.py | ||
---|---|---|
10 | 10 |
from mandaye.log import logger |
11 | 11 |
from mandaye.backends.default import storage_conn |
12 | 12 |
|
13 |
def cmp_reverse_last_connection_date(x, y): |
|
14 |
return -cmp(x[1]['lastConnectionDate'][0], y[1]['lastConnectionDate'][0]) |
|
15 |
|
|
13 | 16 |
class Association(object): |
14 | 17 |
""" |
15 | 18 |
association dictionary return by the following methods: |
... | ... | |
106 | 109 |
logger.info("New association %r with %r", sp_login, idp_unique_id) |
107 | 110 |
return unique_id |
108 | 111 |
else: |
109 |
biggest = '0' |
|
110 |
biggest_pos = 0 |
|
111 |
for i, result in enumerate(results): |
|
112 |
if result[1]['lastConnectionDate'][0] > biggest: |
|
113 |
biggest = result[1]['lastConnectionDate'][0] |
|
114 |
biggest_pos = i |
|
115 |
dn = results[biggest_pos][0] |
|
112 |
results.sort(cmp_reverse_last_connection_date) |
|
113 |
dn = results[0][0] |
|
116 | 114 |
mod_list = [(ldap.MOD_REPLACE, 'spPostValues', json.dumps(sp_post_values))] |
117 | 115 |
storage_conn.modify_s(dn, mod_list) |
118 | 116 |
logger.info("Update post values for %r (%r)", sp_login, idp_unique_id) |
119 |
return results[biggest_pos][1]['uniqueID'][0]
|
|
117 |
return results[0][1]['uniqueID'][0]
|
|
120 | 118 |
|
121 | 119 |
@staticmethod |
122 | 120 |
def delete(asso_id): |
... | ... | |
133 | 131 |
results = storage_conn.search_s(config.ldap_base_dn, ldap.SCOPE_ONELEVEL, |
134 | 132 |
filterstr='(&(objectClass=MandayeUser)(spName=%s)(idpUniqueID=%s)(idpName=%s))' % (sp_name, idp_unique_id, idp_name)) |
135 | 133 |
if results: |
136 |
biggest = '0' |
|
137 |
biggest_pos = 0 |
|
138 |
for i, result in enumerate(results): |
|
139 |
if result[1]['lastConnectionDate'][0] > biggest: |
|
140 |
biggest = result[1]['lastConnectionDate'][0] |
|
141 |
biggest_pos = i |
|
142 |
return Association.ldap2association(results[biggest_pos][1]) |
|
134 |
results.sort(cmp_reverse_last_connection_date) |
|
135 |
return Association.ldap2association(results[0][1]) |
|
143 | 136 |
return None |
144 | 137 |
|
145 | 138 |
@staticmethod |
Formats disponibles : Unified diff
ldap backend: use a more pythonic sort to get the last connected
Closes #5835