Skip to content

Commit

Permalink
TP2000-1435 Improved links to rules violations page (#1272)
Browse files Browse the repository at this point in the history
* Add violation link before rule check finishes

* Updated rule check workbasket links

* Add test

* Update rule check link to use select workbasket view

* Combine tests
  • Loading branch information
mattjamc authored Jul 31, 2024
1 parent b186db9 commit b9375dc
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ govuk-button{% if workbasket.tracked_model_checks.exists() %} govuk-button--seco
{% set live_rule_check_status %}
Rule check in progress. Checking {{ workbasket.tracked_models.count() }} item{{ workbasket.tracked_models.count()|pluralize }} in basket.
{{ rule_check_progress }}.
Come back later or refresh to see results.
<a href="{{ url('workbaskets:workbasket-ui-violations') }}" class="govuk-link">View violations</a> or refresh to see progress.
{% endset %}
{% set rule_check_button = terminate_rule_check_form %}
{% set rule_check_block %}{% endset %}
Expand Down
6 changes: 5 additions & 1 deletion workbaskets/jinja2/workbaskets/rule_check_queue.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
{% endmacro %}

{% macro workbasket_link(workbasket_id) %}
<a href="{{ url("workbaskets:workbasket-ui-detail", args=[workbasket_id]) }}"> {{ workbasket_id }} </a>
<form action="{{ url("workbaskets:workbasket-ui-list") }}" method="post">
<input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
<input type="hidden" name="workbasket-tab" value="view-violations">
<input type="submit" class="button-link" name="workbasket" value="{{ workbasket_id }}">
</form>
{% endmacro %}
{% set list_include = "includes/measures/create-task-list.jinja"%}

Expand Down
1 change: 1 addition & 0 deletions workbaskets/jinja2/workbaskets/violations.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<strong class="govuk-warning-text__text">
<span class="govuk-warning-text__assistive">Warning</span>
Number of business rule violations: {{ workbasket.tracked_model_check_errors.count() }}
{% if rule_check_in_progress %}<p>This workbasket has a rule check in progress, so there may be more violations than shown. </p>{% endif %}
</strong>
</div>
{% set table_rows = [] %}
Expand Down
9 changes: 7 additions & 2 deletions workbaskets/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,15 +393,18 @@ def test_select_workbasket_with_errored_status(valid_user_client):
],
)
def test_select_workbasket_redirects_to_tab(
valid_user_client,
valid_user,
client,
workbasket_tab,
expected_url,
url_kwargs_required,
):
"""Test that SelectWorkbasketView redirects to a specific tab on the
selected workbasket if a tab has been provided."""
client.force_login(valid_user)
assert not valid_user.current_workbasket
workbasket = factories.WorkBasketFactory.create()
response = valid_user_client.post(
response = client.post(
reverse("workbaskets:workbasket-ui-list"),
{
"workbasket": workbasket.id,
Expand All @@ -413,6 +416,8 @@ def test_select_workbasket_redirects_to_tab(
assert response.url == reverse(expected_url, kwargs={"pk": workbasket.pk})
else:
assert response.url == reverse(expected_url)
valid_user.refresh_from_db()
assert valid_user.current_workbasket == workbasket


@pytest.mark.parametrize(
Expand Down
10 changes: 9 additions & 1 deletion workbaskets/views/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,15 @@ def workbasket(self) -> WorkBasket:
return WorkBasket.current(self.request)

def get_context_data(self, **kwargs):
return super().get_context_data(workbasket=self.workbasket, **kwargs)
context = super().get_context_data(workbasket=self.workbasket, **kwargs)
if self.workbasket.rule_check_task_id:
result = AsyncResult(self.workbasket.rule_check_task_id)
if result.status != "SUCCESS":
context["rule_check_in_progress"] = True
else:
context["rule_check_in_progress"] = False

return context

def get_queryset(self):
self.queryset = TrackedModelCheck.objects.filter(
Expand Down

0 comments on commit b9375dc

Please sign in to comment.