Skip to content

Commit

Permalink
👔(dashboard) update consent management logic and improve UI accessibi…
Browse files Browse the repository at this point in the history
…lity

Disabled updates to non-AWAITING consents and enhanced the bulk update logic to enforce the restriction.
Disabled checkbox if status is VALIDATED.
Added tooltips to consent labels in the UI for better context
Fix the home URL in the navigation menu.
  • Loading branch information
ssorin committed Jan 15, 2025
1 parent bfcb414 commit 0409835
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/dashboard/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to
- add mass admin action (make revoked and make awaiting) for consents
- block the updates of all new data if a consent has the status `VALIDATED`
- block the deletion of consent if it has the status `VALIDATED`
- block consent updates (via the consent form) if the consent status is not `AWAITING`
- integration of custom 403, 404 and 500 pages
- sentry integration
- added a signal on the creation of a delivery point. This signal allows the creation
Expand Down
11 changes: 9 additions & 2 deletions src/dashboard/apps/consent/templates/consent/manage.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ <h2>{% trans "Manage consents" %}</h2>
name="status"
value="{{ consent.id }}"
id="{{ consent.id }}"
{% if consent.status == 'VALIDATED' %} checked{% endif %}
{% if consent.status == 'VALIDATED' %} checked="checked" disabled="disabled"{% endif %}
aria-describedby="{{ consent.id }}-messages"
data-fr-js-checkbox-input="true"
data-fr-js-checkbox-actionee="true" />
<label class="fr-label" for="{{ consent.id }}">{{ consent.delivery_point.provider_assigned_id }} </label>
<label class="fr-label" for="{{ consent.id }}"
{% if consent.status == 'VALIDATED' %}
title="{% trans "Delivery point is already validated" %}"
{% elif consent.status == 'AWAITING' %}
title="{% trans "Delivery point awaiting consent" %}"
{% endif %}>
{{ consent.delivery_point.provider_assigned_id }}
</label>
<div class="fr-messages-group" id="{{ consent.id }}-messages" aria-live="assertive"></div>
</div>
</div>
Expand Down
12 changes: 11 additions & 1 deletion src/dashboard/apps/consent/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.urls import reverse

from apps.auth.factories import UserFactory
from apps.consent import AWAITING, VALIDATED
from apps.consent import AWAITING, REVOKED, VALIDATED
from apps.consent.factories import ConsentFactory
from apps.consent.models import Consent
from apps.consent.views import ConsentFormView
Expand Down Expand Up @@ -62,6 +62,16 @@ def test_bulk_update_consent_status(rf):
# and checks that the data has changed to VALIDATED after the update.
assert all(c == VALIDATED for c in Consent.objects.values_list("status", flat=True))

# bulk update from VALIDATED to AWAITING: no data must be updated
assert view._bulk_update_consent(ids, AWAITING) == 0
# and checks that the status has not changed after the update.
assert all(c == VALIDATED for c in Consent.objects.values_list("status", flat=True))

# bulk update from VALIDATED to REVOKED: no data must be updated
assert view._bulk_update_consent(ids, REVOKED) == 0
# and checks that the status has not changed after the update.
assert all(c == VALIDATED for c in Consent.objects.values_list("status", flat=True))


@pytest.mark.django_db
def test_bulk_update_consent_status_with_fake_id(rf):
Expand Down
7 changes: 5 additions & 2 deletions src/dashboard/apps/consent/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ def _get_entities(self) -> list:
return list(user.get_entities())

def _bulk_update_consent(self, ids: list[str], status: str) -> int:
"""Bulk update of the consent status for a given status and list of entities."""
"""Bulk update of the consent status for a given status and list of entities.
Only `AWAITING` consents can be updated by users.
"""
return (
Consent.objects.filter(id__in=ids)
Consent.objects.filter(id__in=ids, status=AWAITING)
.filter(
Q(delivery_point__entity__users=self.request.user)
| Q(delivery_point__entity__proxies__users=self.request.user)
Expand Down
2 changes: 1 addition & 1 deletion src/dashboard/templates/blocks/main_menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ul class="fr-nav__list">
{% if request.user.is_authenticated %}
<li class="fr-nav__item">
{% url 'index' as home_url %}
{% url 'home:index' as home_url %}
<a class="fr-nav__link"
href="{{ home_url }}"
target="_self"
Expand Down

0 comments on commit 0409835

Please sign in to comment.