From 304fab14a2ef1cea233af0f2b2425f41f51dca2f Mon Sep 17 00:00:00 2001 From: Fabio Ambauen Date: Mon, 24 Jun 2024 09:49:35 +0200 Subject: [PATCH 1/2] feat(case): remove idpId and idpIds filters and add identityIds filter --- api/mysagw/case/filters.py | 6 +++--- api/mysagw/case/tests/test_case_views.py | 17 ++++++++++++----- api/mysagw/case/views.py | 6 ++---- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/api/mysagw/case/filters.py b/api/mysagw/case/filters.py index 6a0cde8c8..149cdf5c3 100644 --- a/api/mysagw/case/filters.py +++ b/api/mysagw/case/filters.py @@ -1,7 +1,7 @@ from django_filters import CharFilter from django_filters.rest_framework import FilterSet -from mysagw.filters import CharMultiValueFilter, UUIDMultiValueFilter +from mysagw.filters import UUIDMultiValueFilter from . import models @@ -9,8 +9,8 @@ class CaseAccessFilterSet(FilterSet): idp_id = CharFilter(field_name="identity__idp_id") case_ids = UUIDMultiValueFilter(field_name="case_id") - idp_ids = CharMultiValueFilter(field_name="identity__idp_id") + identity_ids = UUIDMultiValueFilter(field_name="identity_id") class Meta: model = models.CaseAccess - fields = ["idp_id", "case_ids", "idp_ids"] + fields = ["case_ids", "identity_ids"] diff --git a/api/mysagw/case/tests/test_case_views.py b/api/mysagw/case/tests/test_case_views.py index 3ff31dd0c..db19d4657 100644 --- a/api/mysagw/case/tests/test_case_views.py +++ b/api/mysagw/case/tests/test_case_views.py @@ -34,15 +34,22 @@ def test_case_list( identity_factory, case_access_factory, ): - identity_0 = identity_factory(idp_id="00000000-0000-0000-0000-000000000000") - identity_1 = identity_factory(idp_id="11111111-1111-1111-1111-111111111111") - case_access_factory.create_batch(2, identity=identity_0, email=None) - case_access_factory(identity=identity_1, email=None) + identity_0 = identity_factory() + identity_1 = identity_factory() + case_access_factory( + identity=identity_0, email=None, case_id="00000000-0000-0000-0000-000000000000" + ) + case_access_factory( + identity=identity_0, email=None, case_id="11111111-1111-1111-1111-111111111111" + ) + case_access_factory( + identity=identity_1, email=None, case_id="00000000-0000-0000-0000-000000000000" + ) case_access_factory() url = reverse("caseaccess-list") - response = client.get(url, {"filter[idpId]": filter_id} if filter_id else None) + response = client.get(url, {"filter[caseIds]": filter_id} if filter_id else None) assert response.status_code == expected_status diff --git a/api/mysagw/case/views.py b/api/mysagw/case/views.py index 51460656e..240caad3e 100644 --- a/api/mysagw/case/views.py +++ b/api/mysagw/case/views.py @@ -41,12 +41,10 @@ class CaseAccessViewSet( permission_classes = (IsAuthenticated & (IsAdmin | IsStaff | HasCaseAccess),) def list(self, request, *args, **kwargs): - expected_keys = ["filter[idpId]", "filter[caseIds]", "filter[idpIds]"] + expected_keys = ["filter[idpId]", "filter[caseIds]", "filter[identityIds]"] if not request.GET or set(expected_keys).isdisjoint(request.GET.keys()): msg = f"At least one of following filters must be used: {', '.join(expected_keys)}" - raise ValidationError( - msg, - ) + raise ValidationError(msg) return super().list(request, *args, **kwargs) def destroy(self, request, *args, **kwargs): From 34846db3cd89329e704fead1c31698f80ab7f652 Mon Sep 17 00:00:00 2001 From: yelinz Date: Thu, 4 Jul 2024 09:48:26 +0200 Subject: [PATCH 2/2] fix(ember): use id to filter identities --- api/mysagw/identity/filters.py | 1 + ember/app/ui/cases/index/controller.js | 6 +++--- .../ui/components/case-transfer/component.js | 16 +++------------ .../components/filters/identity/component.js | 9 ++++----- .../ui/components/identity-form/component.js | 20 +++++++++---------- ember/app/ui/work-items/controller.js | 11 +++++++++- ember/app/utils/table-controller.js | 2 +- 7 files changed, 31 insertions(+), 34 deletions(-) diff --git a/api/mysagw/identity/filters.py b/api/mysagw/identity/filters.py index 98573d5ee..1ea10f7c7 100644 --- a/api/mysagw/identity/filters.py +++ b/api/mysagw/identity/filters.py @@ -14,6 +14,7 @@ class IdentityFilterSet(FilterSet): + ids = CharMultiValueFilter(field_name="pk") idp_ids = CharMultiValueFilter(field_name="idp_id") has_idp_id = BooleanFilter(field_name="idp_id", lookup_expr="isnull", exclude=True) member_of_organisations = CharMultiValueFilter( diff --git a/ember/app/ui/cases/index/controller.js b/ember/app/ui/cases/index/controller.js index 6c68207a1..ece3c50c1 100644 --- a/ember/app/ui/cases/index/controller.js +++ b/ember/app/ui/cases/index/controller.js @@ -106,15 +106,15 @@ export default class CasesIndexController extends TableController { return filters; }); - async fetchAccesses(idpIds) { - if (!idpIds) { + async fetchAccesses(ids) { + if (!ids) { return []; } try { const accesses = ( await this.store.query("case-access", { - filter: { idpIds: idpIds.join(",") }, + filter: { identityIds: ids.join(",") }, }) ).map((access) => access.get("caseId")); diff --git a/ember/app/ui/components/case-transfer/component.js b/ember/app/ui/components/case-transfer/component.js index 8413560a5..5488ea735 100644 --- a/ember/app/ui/components/case-transfer/component.js +++ b/ember/app/ui/components/case-transfer/component.js @@ -15,17 +15,7 @@ export default class CaseTransfer extends Component { @action selectNewAssignees(value) { - this.newAssignees = value.map((assignee) => assignee.idpId); - } - - idpIdsToIds(idpIds) { - const idpIdSet = new Set(idpIds); - return this.store.peekAll("identity").reduce((ids, identity) => { - if (idpIdSet.has(identity.idpId)) { - return ids.push(identity.id), ids; - } - return ids; - }, []); + this.newAssignees = value.map((assignee) => assignee.id); } @action @@ -43,12 +33,12 @@ export default class CaseTransfer extends Component { const body = { case_ids: caseIds, dossier_nrs: dossierNrs, - new_assignees: this.idpIdsToIds(this.newAssignees), + new_assignees: this.newAssignees, to_remove_assignees: [], }; if (this.removeAccess) { - body.to_remove_assignees = this.idpIdsToIds(this.args.toRemove); + body.to_remove_assignees = this.args.toRemove; } const headers = adapter.headers; diff --git a/ember/app/ui/components/filters/identity/component.js b/ember/app/ui/components/filters/identity/component.js index 95dcdce78..db02eaacf 100644 --- a/ember/app/ui/components/filters/identity/component.js +++ b/ember/app/ui/components/filters/identity/component.js @@ -17,7 +17,7 @@ export default class FiltersIdentityComponent extends Component { : this.args.selected; return this.identityOptions.value?.filter((option) => - selected.includes(option.idpId), + selected.includes(option.id), ); } @@ -26,9 +26,9 @@ export default class FiltersIdentityComponent extends Component { return []; } - let idpIds = this.args.selected; + let ids = this.args.selected; if (typeof this.args.selected !== "string") { - idpIds = this.args.selected.join(","); + ids = this.args.selected.join(","); } try { @@ -37,7 +37,7 @@ export default class FiltersIdentityComponent extends Component { "identity", { filter: { - idpIds, + ids, }, }, { adapterOptions: { customEndpoint: "public-identities" } }, @@ -66,7 +66,6 @@ export default class FiltersIdentityComponent extends Component { filter: { search, isOrganisation: false, - has_idp_id: true, }, }, { adapterOptions: { customEndpoint: "public-identities" } }, diff --git a/ember/app/ui/components/identity-form/component.js b/ember/app/ui/components/identity-form/component.js index 987834431..67fe2ac3d 100644 --- a/ember/app/ui/components/identity-form/component.js +++ b/ember/app/ui/components/identity-form/component.js @@ -133,17 +133,15 @@ export default class IdentityFormComponent extends Component { try { let message = this.intl.t("components.identity-form.delete.prompt"); - if (this.args.identity.idpId) { - const accesses = yield this.store.query("case-access", { - filter: { idpIds: this.args.identity.idpId }, - }); - message += `\n${this.intl.t( - "components.identity-form.delete.promptInfo", - { - caseAmount: accesses.length, - }, - )}`; - } + const accesses = yield this.store.query("case-access", { + filter: { identityIds: this.args.identity.id }, + }); + message += `\n${this.intl.t( + "components.identity-form.delete.promptInfo", + { + caseAmount: accesses.length, + }, + )}`; const modal = UIkit.modal.confirm(message); // We need to add css white-space rule for the new line diff --git a/ember/app/ui/work-items/controller.js b/ember/app/ui/work-items/controller.js index d29d9b27b..eba70bddf 100644 --- a/ember/app/ui/work-items/controller.js +++ b/ember/app/ui/work-items/controller.js @@ -65,8 +65,17 @@ export default class WorkItemsIndexController extends TableController { } if (this.filters.identities) { + const idSet = new Set(arrayFromString(this.filters.identities)); + const assignedUsers = this.store + .peekAll("identity") + .reduce((ids, identity) => { + if (idSet.has(identity.id)) { + return ids.push(identity.idpId), ids; + } + return ids; + }, []); filter.push({ - assignedUsers: arrayFromString(this.filters.identities), + assignedUsers, invert: Boolean(this.invertedFilters.identities), }); } diff --git a/ember/app/utils/table-controller.js b/ember/app/utils/table-controller.js index e2eee91a9..64a38ab04 100644 --- a/ember/app/utils/table-controller.js +++ b/ember/app/utils/table-controller.js @@ -61,7 +61,7 @@ export default class TableController extends Controller { if (Array.isArray(eventOrValue)) { this.filters[type] = stringFromArray( eventOrValue, - type === "identities" ? "idpId" : "value", + type === "identities" ? "id" : "value", ); } else { this.filters[type] = eventOrValue.target?.value ?? eventOrValue;