Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(case): remove idpId and idpIds filters and add identityIds filter #1099

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions api/mysagw/case/filters.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
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


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"]
17 changes: 12 additions & 5 deletions api/mysagw/case/tests/test_case_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions api/mysagw/case/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions api/mysagw/identity/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions ember/app/ui/cases/index/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down
16 changes: 3 additions & 13 deletions ember/app/ui/components/case-transfer/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions ember/app/ui/components/filters/identity/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
}

Expand All @@ -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 {
Expand All @@ -37,7 +37,7 @@ export default class FiltersIdentityComponent extends Component {
"identity",
{
filter: {
idpIds,
ids,
},
},
{ adapterOptions: { customEndpoint: "public-identities" } },
Expand Down Expand Up @@ -66,7 +66,6 @@ export default class FiltersIdentityComponent extends Component {
filter: {
search,
isOrganisation: false,
has_idp_id: true,
},
},
{ adapterOptions: { customEndpoint: "public-identities" } },
Expand Down
20 changes: 9 additions & 11 deletions ember/app/ui/components/identity-form/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion ember/app/ui/work-items/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
});
}
Expand Down
2 changes: 1 addition & 1 deletion ember/app/utils/table-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading