Skip to content

Commit

Permalink
Merge pull request #2346 from uktrade/dev
Browse files Browse the repository at this point in the history
UAT Release
  • Loading branch information
currycoder authored Dec 16, 2024
2 parents cb0954d + 77a82b3 commit 68774ff
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 25 deletions.
15 changes: 13 additions & 2 deletions api/cases/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,24 @@ def without_control_list_entries(self, control_list_entries):
def without_regime_entries(self, regime_entries):
return self.exclude(baseapplication__goods__regime_entries__id__in=regime_entries)

def with_flags(self, flags):
def _get_case_ids_with_any_flags(self, flags):
case_flag_ids = self.filter(flags__id__in=flags).values_list("id", flat=True)
org_flag_ids = self.filter(organisation__flags__id__in=flags).values_list("id", flat=True)
goods_flag_ids = self.filter(baseapplication__goods__good__flags__id__in=flags).values_list("id", flat=True)
parties_flag_ids = self.filter(baseapplication__parties__party__flags__id__in=flags).values_list(
"id", flat=True
)

case_ids = set(list(case_flag_ids) + list(org_flag_ids) + list(goods_flag_ids) + list(parties_flag_ids))
return set(list(case_flag_ids) + list(org_flag_ids) + list(goods_flag_ids) + list(parties_flag_ids))

def with_flags(self, flags):
case_ids = self._get_case_ids_with_any_flags(flags)
return self.filter(id__in=case_ids)

def without_flags(self, flags):
case_ids = self._get_case_ids_with_any_flags(flags)
return self.exclude(id__in=case_ids)

def with_country(self, country_id):
return self.filter(Q(baseapplication__parties__party__country_id=country_id))

Expand Down Expand Up @@ -267,6 +274,7 @@ def search( # noqa
exclude_regime_entry=None,
regime_entry=None,
flags=None,
exclude_flags=None,
country=None,
countries=None,
team_advice_type=None,
Expand Down Expand Up @@ -402,6 +410,9 @@ def search( # noqa
if flags:
case_qs = case_qs.with_flags(flags)

if exclude_flags:
case_qs = case_qs.without_flags(exclude_flags)

if country:
case_qs = case_qs.with_country(country)

Expand Down
53 changes: 51 additions & 2 deletions api/cases/tests/test_case_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
from api.users.enums import UserStatuses
from api.users.models import GovUser
from api.cases.tests import factories
from api.cases.enums import AdviceType
from api.staticdata.statuses.enums import CaseStatusEnum
from api.teams.models import Team
from api.cases.views.search.service import (
get_case_status_list,
Expand Down Expand Up @@ -553,6 +551,57 @@ def test_filter_cases_by_flags(self, flag_id, flags_key):
for case in response_data["cases"]:
self.assertIn(flag_id, [item["id"] for item in case[flags_key]])

def test_filter_cases_exclude_flags_case_level(self):
# set required flags
application = self.application_cases[0]
case = Case.objects.get(id=application.id)
flag_id = FlagsEnum.GOODS_NOT_LISTED
flag = Flag.objects.get(id=flag_id)
case.flags.add(flag)

url = f"{self.url}?exclude_flags={flag_id}"

response = self.client.get(url, **self.gov_headers)
response_data = response.json()["results"]

self.assertEqual(response.status_code, status.HTTP_200_OK)
for search_result_case in response_data["cases"]:
self.assertNotEqual(search_result_case["id"], str(case.id))

def test_filter_cases_exclude_flags_good_level(self):
# set required flags
application = self.application_cases[0]
good = application.goods.all()[0].good
flag_id = FlagsEnum.WASSENAAR
flag = Flag.objects.get(id=flag_id)
good.flags.add(flag)

url = f"{self.url}?exclude_flags={flag_id}"

response = self.client.get(url, **self.gov_headers)
response_data = response.json()["results"]

self.assertEqual(response.status_code, status.HTTP_200_OK)
for search_result_case in response_data["cases"]:
self.assertNotEqual(search_result_case["id"], str(application.id))

def test_filter_cases_exclude_flags_destination_level(self):
# set required flags
application = self.application_cases[0]
destination = application.parties.all()[0].party
flag_id = FlagsEnum.MOD_DI_COUNTRY_OF_INTEREST
flag = Flag.objects.get(id=flag_id)
destination.flags.add(flag)

url = f"{self.url}?exclude_flags={flag_id}"

response = self.client.get(url, **self.gov_headers)
response_data = response.json()["results"]

self.assertEqual(response.status_code, status.HTTP_200_OK)
for search_result_case in response_data["cases"]:
self.assertNotEqual(search_result_case["id"], str(application.id))

@parameterized.expand(["permanent", "temporary"])
def test_get_cases_filter_by_export_type(self, export_type):
expected_id = str(self.application_cases[0].id)
Expand Down
7 changes: 6 additions & 1 deletion api/cases/views/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ def get_case_queryset(self, user, queue_id, is_work_queue, include_hidden, filte
)

def get_filters(self, request):
filters = {key: value for key, value in request.GET.items() if key not in ["hidden", "queue_id", "flags"]}
filters = {
key: value
for key, value in request.GET.items()
if key not in ["hidden", "queue_id", "flags", "exclude_flags"]
}

search_tabs = ("my_cases", "open_queries")
selected_tab = request.GET.get("selected_tab")
Expand All @@ -143,6 +147,7 @@ def get_filters(self, request):
del filters["max_total_value"]

filters["flags"] = request.GET.getlist("flags", [])
filters["exclude_flags"] = request.GET.getlist("exclude_flags", [])
filters["regime_entry"] = [regime for regime in request.GET.getlist("regime_entry", []) if regime]
filters["exclude_regime_entry"] = request.GET.get("exclude_regime_entry", False)
filters["control_list_entry"] = [cle for cle in request.GET.getlist("control_list_entry", []) if cle]
Expand Down
4 changes: 4 additions & 0 deletions api/conf/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ class MaxFiftyPageSizePaginator(MaxPageNumberPagination):
page_size = 50
page_size_query_param = "page_size"
max_page_size = 50


class CreatedAtCursorPagination(pagination.CursorPagination):
ordering = "-created_at"
3 changes: 2 additions & 1 deletion api/data_workspace/v1/good_views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from rest_framework import viewsets
from rest_framework.pagination import LimitOffsetPagination

from api.conf.pagination import CreatedAtCursorPagination
from api.goods import models, serializers
from api.core.authentication import DataWorkspaceOnlyAuthentication


class GoodListView(viewsets.ReadOnlyModelViewSet):
authentication_classes = (DataWorkspaceOnlyAuthentication,)
serializer_class = serializers.GoodSerializerInternalIncludingPrecedents
pagination_class = LimitOffsetPagination
pagination_class = CreatedAtCursorPagination
queryset = models.Good.objects.all()


Expand Down
5 changes: 3 additions & 2 deletions api/data_workspace/v2/tests/bdd/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.urls import reverse
from freezegun import freeze_time
from moto import mock_aws
from operator import itemgetter
from pytest_bdd import (
given,
parsers,
Expand Down Expand Up @@ -522,8 +523,8 @@ def check_rows(client, parse_table, unpage_data, table_name, rows):
for row in parsed_rows[1:]:
expected_data.append({key: value for key, value in zip(keys, row)})
expected_data = cast_to_types(expected_data, table_metadata["fields"])
actual_data = sorted(actual_data, key=lambda item, keys=keys: item[keys[0]])
expected_data = sorted(expected_data, key=lambda item, keys=keys: item[keys[0]])
actual_data = sorted(actual_data, key=itemgetter(*keys))
expected_data = sorted(expected_data, key=itemgetter(*keys))
assert actual_data == expected_data


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h2 class="govuk-heading-l">Products</h3>
<ul class="govuk-list govuk-list--bullet">
{% for good in goods.refuse %}
<li>
{{good.good.name|split_good_name_across_lines}}
{{good.good.name}}
</li>
{% endfor %}
</ul>
Expand Down
4 changes: 2 additions & 2 deletions api/letter_templates/templates/letter_templates/siel.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<h1>Standard Individual Export Licence</h1>
<img class="dbt-logo" src="{% static 'images/dbt.png' %}">

<table id="first-page-table" class="fixed-layout">
<table id="first-page-table">
<!--
Table is broken up into 12 evenly-spaced columns.
Cell width is controlled by colspan attributes on cells.
Expand Down Expand Up @@ -282,7 +282,7 @@ <h1>Standard Individual Export Licence</h1>
<table border="0">
<tr id="row-{{ forloop.counter}}-description-name">
<td><strong>Name:</strong></td>
<td>{% if good.name %}{{ good.name|split_good_name_across_lines }}{% else %}{{ good.description|split_good_name_across_lines }}{% endif %}
<td>{% if good.name %}{{ good.name }}{% else %}{{ good.description }}{% endif %}
</td>
</tr>
<tr>
Expand Down
5 changes: 0 additions & 5 deletions api/letter_templates/templatetags/custom_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,3 @@ def remove_duplicate_provisos(goods_approved):
provisos.add(good_item["proviso_reason"])

return provisos


@register.filter(name="split_good_name_across_lines")
def split_good_name_across_lines(value):
return value.replace(",", "\n") if "," in value else value
4 changes: 2 additions & 2 deletions api/letter_templates/tests/test_letter_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_refusal_template(self):

self.assertIn("Test Good 1", rendered_template)

self.assertIn("Test Good 2\n Another line", rendered_template)
self.assertIn("Test Good 2, Another line", rendered_template)
self.assertIn("Criterion 1", rendered_template)
self.assertIn("Test Description 1", rendered_template)

Expand Down Expand Up @@ -59,7 +59,7 @@ def test_siel_template_uses_correct_quantity_and_value(self):
{"goods": goods_data},
)

self.assertIn("Test Good 2\n Another line", rendered_template)
self.assertIn("Test Good 2, Another line", rendered_template)
self.assertIn("999111", rendered_template)
self.assertIn("999222", rendered_template)
self.assertNotIn("555111", rendered_template)
Expand Down
4 changes: 1 addition & 3 deletions assets/css/siel.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
margin-bottom: 20px;
}
.document table {
table-layout: fixed;
border-collapse: collapse;
width: 100%;
}
Expand All @@ -26,9 +27,6 @@
margin: 0;
padding: 5px;
}
.document table.fixed-layout {
table-layout: fixed;
}
.document .border-black {
border: 1px solid black;
}
Expand Down
4 changes: 1 addition & 3 deletions assets/css/siel_preview.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
margin-bottom: 20px;
}
.document table {
table-layout: fixed;
border-collapse: collapse;
width: 100%;
}
Expand All @@ -26,9 +27,6 @@
margin: 0;
padding: 5px;
}
.document table.fixed-layout {
table-layout: fixed;
}
.document .border-black {
border: 1px solid black;
}
Expand Down
2 changes: 1 addition & 1 deletion lite_routing

0 comments on commit 68774ff

Please sign in to comment.