From f4c04d96665ebf7dd3013ca15980952e9a137c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89loi=20Rivard?= Date: Mon, 13 Dec 2021 22:50:53 +0100 Subject: [PATCH] Default configuration and test client use user avatars --- canaille/account.py | 2 +- canaille/conf/config.sample.toml | 1 + demo/client/templates/index.html | 127 +++++++++++++++++-------------- demo/conf/canaille.toml | 1 + doc/configuration.rst | 4 + tests/conftest.py | 1 + 6 files changed, 79 insertions(+), 57 deletions(-) diff --git a/canaille/account.py b/canaille/account.py index beb644af..fad5e1a1 100644 --- a/canaille/account.py +++ b/canaille/account.py @@ -519,7 +519,7 @@ def reset(uid, hash): @bp.route("/profile//") def photo(uid, field): - if field != "jpegPhoto": + if field.lower() != "jpegphoto": abort(404) user = User.get(uid) diff --git a/canaille/conf/config.sample.toml b/canaille/conf/config.sample.toml index 87253958..a07487af 100644 --- a/canaille/conf/config.sample.toml +++ b/canaille/conf/config.sample.toml @@ -156,6 +156,7 @@ FAMILY_NAME = "{{ user.sn[0] }}" PREFERRED_USERNAME = "{{ user.displayName[0] }}" LOCALE = "{{ user.preferredLanguage[0] }}" ADDRESS = "{{ user.postalAddress[0] }}" +PICTURE = "{% if user.jpegPhoto %}{{ url_for('account.photo', uid=user.uid[0], field='jpegPhoto', _external=True) }}{% endif %}" # The SMTP server options. If not set, mail related features such as # user invitations, and password reset emails, will be disabled. diff --git a/demo/client/templates/index.html b/demo/client/templates/index.html index 984ee55c..b0f9104e 100644 --- a/demo/client/templates/index.html +++ b/demo/client/templates/index.html @@ -1,71 +1,86 @@ - - - - + + + + - Canaille test client + Canaille test client - - - {% if logo_url %}{% endif %} - {% block style %}{% endblock %} + + + {% if logo_url %}{% endif %} + {% block style %}{% endblock %} - + - + - - - -
- {% with messages = get_flashed_messages(with_categories=true) %} - {% for category, message in messages %} -
- {{ message }} + + + +
+ {% with messages = get_flashed_messages(with_categories=true) %} + {% for category, message in messages %} +
+ {{ message }} +
+ {% endfor %} + {% endwith %} + +
+

{{ name }}

+ {% if user %} +
+ {% if user.picture %} +
+ Avatar +
+ {% endif %} +
+ {{ user.name }} +
+ {{ user.sub }} +
+ {% if user.groups %} +
+ + {% for group in user.groups %} + {{ group }} + {% endfor %} +
+ {% endif %} +
+
+ {% else %} + Sign in. + {% endif %}
-
- - - - {% block script %}{% endblock %} - + + + + {% block script %}{% endblock %} + diff --git a/demo/conf/canaille.toml b/demo/conf/canaille.toml index af13cc9a..745f4311 100644 --- a/demo/conf/canaille.toml +++ b/demo/conf/canaille.toml @@ -162,6 +162,7 @@ FAMILY_NAME = "{{ user.sn[0] }}" PREFERRED_USERNAME = "{{ user.displayName[0] }}" LOCALE = "{{ user.preferredLanguage[0] }}" ADDRESS = "{{ user.postalAddress[0] }}" +PICTURE = "{% if user.jpegPhoto %}{{ url_for('account.photo', uid=user.uid[0], field='jpegPhoto', _external=True) }}{% endif %}" # The SMTP server options. If not set, mail related features such as # user invitations, and password reset emails, will be disabled. diff --git a/doc/configuration.rst b/doc/configuration.rst index 95b6d178..0ba299b0 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -212,6 +212,10 @@ Attributes are rendered using jinja2, and can use a ``user`` variable. :ADDRESS: *Optional.* Defaults to ``{{ user.postalAddress[0] }}`` +:PICTURE: + *Optional.* Defaults to ``{% if user.jpegPhoto %}{{ url_for('account.photo', uid=user.uid[0], field='jpegPhoto', _external=True) }}{% endif %}`` + + SMTP ---- Canaille needs you to configure a SMTP server to send some mails, including the *I forgot my password* and the *invitation* mails. diff --git a/tests/conftest.py b/tests/conftest.py index 70ac8c1d..89283f01 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -187,6 +187,7 @@ def configuration(slapd_server, smtpd, keypair_path): "FAMILY_NAME": "{{ user.sn[0] }}", "PREFERRED_USERNAME": "{{ user.displayName[0] }}", "LOCALE": "{{ user.preferredLanguage[0] }}", + "PICTURE": "{% if user.jpegPhoto %}{{ url_for('account.photo', uid=user.uid[0], field='jpegPhoto', _external=True) }}{% endif %}", }, }, "SMTP": {