diff --git a/canaille/oidc/consents.py b/canaille/oidc/consents.py index 45208a56..7ba9831d 100644 --- a/canaille/oidc/consents.py +++ b/canaille/oidc/consents.py @@ -22,11 +22,11 @@ bp = Blueprint("consents", __name__, url_prefix="/consent") def consents(user): consents = Consent.query(subject=user) clients = {t.client for t in consents} - preconsented = [ - client - for client in Client.query() - if client.preconsent and client not in clients - ] + + nb_consents = len(consents) + nb_preconsents = sum( + 1 for client in Client.query() if client.preconsent and client not in clients + ) return render_template( "oidc/user/consent_list.html", @@ -34,7 +34,33 @@ def consents(user): menuitem="consents", scope_details=SCOPE_DETAILS, ignored_scopes=["openid"], + nb_consents=nb_consents, + nb_preconsents=nb_preconsents, + ) + + +@bp.route("/pre-consents") +@user_needed() +def pre_consents(user): + consents = Consent.query(subject=user) + clients = {t.client for t in consents} + preconsented = [ + client + for client in Client.query() + if client.preconsent and client not in clients + ] + + nb_consents = len(consents) + nb_preconsents = len(preconsented) + + return render_template( + "oidc/user/preconsent_list.html", + menuitem="consents", + scope_details=SCOPE_DETAILS, + ignored_scopes=["openid"], preconsented=preconsented, + nb_consents=nb_consents, + nb_preconsents=nb_preconsents, ) diff --git a/canaille/templates/oidc/user/consent_list.html b/canaille/templates/oidc/user/consent_list.html index cb43fadb..3120abad 100644 --- a/canaille/templates/oidc/user/consent_list.html +++ b/canaille/templates/oidc/user/consent_list.html @@ -8,8 +8,23 @@ {% endblock %} +{% block submenu %} + +{% endblock %} + {% block content %} -
+

{{ _("My consents") }} @@ -101,72 +116,5 @@

{% endif %} - - {% if preconsented %} -

-
- {{ _("Pre-authorized applications") }} -
-
- {% trans %}Those applications automatically have authorizations to access you data.{% endtrans %} -
-

-
- {% for client in preconsented %} -
-
- {% if client.logo_uri %} - - {% endif %} - {% if client.client_uri %} - {{ client.client_name }} - {% else %} -
{{ client.client_name }}
- {% endif %} -
-

- {% trans %}Has access to:{% endtrans %} -

-
- {% for scope in client.scope %} - {% if scope not in ignored_scopes %} - {% if scope not in scope_details %} -
{{ scope }}
- {% else %} -
- -
{{ scope_details[scope][1] }}
-
- {% endif %} - {% endif %} - {% endfor %} -
-
-
- {% if client.policy_uri %} - - {% endif %} - {% if client.tos_uri %} - - {% endif %} - - - {% trans %}Revoke access{% endtrans %} - -
- {% endfor %} -
- - {% endif %}
{% endblock %} diff --git a/canaille/templates/oidc/user/preconsent_list.html b/canaille/templates/oidc/user/preconsent_list.html new file mode 100644 index 00000000..9c538760 --- /dev/null +++ b/canaille/templates/oidc/user/preconsent_list.html @@ -0,0 +1,94 @@ +{% extends theme('base.html') %} + +{% block title %} + {% trans %}My consents{% endtrans %} +{% endblock %} + +{% block script %} + +{% endblock %} + +{% block submenu %} + +{% endblock %} + +{% block content %} +
+ {% if preconsented %} +

+
+ {{ _("Pre-authorized applications") }} +
+
+ {% trans %}Those applications automatically have authorizations to access you data.{% endtrans %} +
+

+
+ {% for client in preconsented %} +
+
+ {% if client.logo_uri %} + + {% endif %} + {% if client.client_uri %} + {{ client.client_name }} + {% else %} +
{{ client.client_name }}
+ {% endif %} +
+

+ {% trans %}Has access to:{% endtrans %} +

+
+ {% for scope in client.scope %} + {% if scope not in ignored_scopes %} + {% if scope not in scope_details %} +
{{ scope }}
+ {% else %} +
+ +
{{ scope_details[scope][1] }}
+
+ {% endif %} + {% endif %} + {% endfor %} +
+
+
+ {% if client.policy_uri %} + + {% endif %} + {% if client.tos_uri %} + + {% endif %} + + + {% trans %}Revoke access{% endtrans %} + +
+ {% endfor %} +
+ {% endif %} +
+{% endblock %} diff --git a/tests/oidc/test_consent.py b/tests/oidc/test_consent.py index f310bda1..3a8ebebd 100644 --- a/tests/oidc/test_consent.py +++ b/tests/oidc/test_consent.py @@ -145,13 +145,13 @@ def test_oidc_authorization_after_revokation( def test_preconsented_client_appears_in_consent_list(testclient, client, logged_user): assert not client.preconsent - res = testclient.get("/consent") + res = testclient.get("/consent/pre-consents") res.mustcontain(no=client.client_name) client.preconsent = True client.save() - res = testclient.get("/consent") + res = testclient.get("/consent/pre-consents") res.mustcontain(client.client_name)