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 14, 2025
1 parent 0e9e0e7 commit a4af1f3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
8 changes: 6 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,15 @@ <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" %}">{% endif %}
{% if 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 a4af1f3

Please sign in to comment.