Skip to content

Commit

Permalink
fix(ember): use id to filter identities
Browse files Browse the repository at this point in the history
  • Loading branch information
Yelinz authored and open-dynaMIX committed Aug 2, 2024
1 parent 304fab1 commit 34846db
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 34 deletions.
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

0 comments on commit 34846db

Please sign in to comment.