0001-ldap-record-users-ldap-accounts-51211.patch
src/authentic2/backends/__init__.py | ||
---|---|---|
18 | 18 | |
19 | 19 |
from authentic2 import app_settings |
20 | 20 | |
21 |
default_app_config = 'authentic2.backends.apps.AppConfig' |
|
22 | ||
21 | 23 | |
22 | 24 |
def get_user_queryset(): |
23 | 25 |
User = get_user_model() |
... | ... | |
42 | 44 |
if not app_settings.A2_USER_FILTER and not app_settings.A2_USER_EXCLUDE: |
43 | 45 |
return True |
44 | 46 |
return get_user_queryset().filter(pk=user.pk).exists() |
45 | ||
46 | ||
47 |
from .ldap_backend import LDAPBackend # noqa: F401 |
|
48 |
from .models_backend import ModelBackend # noqa: F401 |
src/authentic2/backends/apps.py | ||
---|---|---|
1 |
# authentic2 - versatile identity manager |
|
2 |
# Copyright (C) 2010-2021 Entr'ouvert |
|
3 |
# |
|
4 |
# This program is free software: you can redistribute it and/or modify it |
|
5 |
# under the terms of the GNU Affero General Public License as published |
|
6 |
# by the Free Software Foundation, either version 3 of the License, or |
|
7 |
# (at your option) any later version. |
|
8 |
# |
|
9 |
# This program is distributed in the hope that it will be useful, |
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
# GNU Affero General Public License for more details. |
|
13 |
# |
|
14 |
# You should have received a copy of the GNU Affero General Public License |
|
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | ||
17 |
import django.apps |
|
18 |
from django import template |
|
19 | ||
20 | ||
21 |
class AppConfig(django.apps.AppConfig): |
|
22 |
name = 'authentic2.backends' |
|
23 | ||
24 |
def a2_hook_manager_user_data(self, view, user): |
|
25 |
context = {'user': user} |
|
26 |
return [template.loader.get_template('authentic2/backends/manager_user_sidebar.html').render(context)] |
src/authentic2/backends/templates/authentic2/backends/manager_user_sidebar.html | ||
---|---|---|
1 |
{% load i18n %} |
|
2 |
{% for external_id in user.userexternalid_set.all %} |
|
3 |
<p> |
|
4 |
{% blocktrans trimmed with source=external_id.source created=external_id.created uid=external_id.external_id %} |
|
5 |
Linked with LDAP server "{{ source }}" created on {{ created }} (external_id {{ uid }}). |
|
6 |
{% endblocktrans %} |
|
7 |
</p> |
|
8 |
{% endfor %} |
src/authentic2/settings.py | ||
---|---|---|
145 | 145 |
'authentic2.disco_service', |
146 | 146 |
'authentic2.manager', |
147 | 147 |
'authentic2.apps.journal', |
148 |
'authentic2.backends', |
|
148 | 149 |
'authentic2', |
149 | 150 |
'django_rbac', |
150 | 151 |
'authentic2.a2_rbac', |
tests/test_ldap.py | ||
---|---|---|
1809 | 1809 | |
1810 | 1810 |
assert backend.build_external_id(['uid'], {'uid': 'john.doe'}) == 'john.doe' |
1811 | 1811 |
assert backend.build_external_id(['uid'], {}) is None |
1812 | ||
1813 | ||
1814 |
def test_manager_user_sidebar(slapd, settings, client, db, app, superuser): |
|
1815 |
settings.LDAP_AUTH_SETTINGS = [ |
|
1816 |
{ |
|
1817 |
'url': [slapd.ldap_url], |
|
1818 |
'basedn': 'o=ôrga', |
|
1819 |
'use_tls': False, |
|
1820 |
} |
|
1821 |
] |
|
1822 | ||
1823 |
# create users as a side effect |
|
1824 |
list(ldap_backend.LDAPBackend.get_users()) |
|
1825 |
user = User.objects.get(username='etienne.michu@ldap') |
|
1826 | ||
1827 |
utils.login(app, superuser, '/manage/') |
|
1828 |
resp = app.get('/manage/users/%s/' % user.pk) |
|
1829 |
assert 'LDAP' in resp.text |
|
1830 |
assert 'server "ldap"' in resp.text |
|
1831 |
assert 'external_id etienne.michu' in resp.text |
|
1832 | ||
1833 |
user.userexternalid_set.all().delete() |
|
1834 |
resp = app.get('/manage/users/%s/' % user.pk) |
|
1835 |
assert 'LDAP' not in resp.text |
|
1812 |
- |