Skip to content
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
11 changes: 0 additions & 11 deletions back/src/adapters/primary/routers/admin/createAdminRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,6 @@ export const createAdminRouter = (deps: AppDependencies): Router => {
),
);

sharedAdminRouter.removeUserFromAgency(
deps.connectedUserAuthMiddleware,
(req, res) =>
sendHttpResponse(req, res, () =>
deps.useCases.removeUserFromAgency.execute(
req.params,
getGenericAuthOrThrow(req.payloads?.currentUser),
),
),
);

sharedAdminRouter.rejectIcUserForAgency(
deps.connectedUserAuthMiddleware,
(req, res) =>
Expand Down
2 changes: 1 addition & 1 deletion back/src/config/bootstrap/createUseCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { makeListAgencyOptionsByFilter } from "../../domains/agency/use-cases/Li
import { makeNotifyAgencyHasBeenPutOnHold } from "../../domains/agency/use-cases/NotifyAgencyHasBeenPutOnHold";
import { makeNotifyDelegationConventionReminder } from "../../domains/agency/use-cases/notifications/NotifyDelegationConventionReminder";
import { makeRegisterAgencyToConnectedUser } from "../../domains/agency/use-cases/RegisterAgencyToConnectedUser";
import { makeRemoveUserFromAgency } from "../../domains/agency/use-cases/RemoveUserFromAgency";
import { makeUpdateAgency } from "../../domains/agency/use-cases/UpdateAgency";
import { makeUpdateAgencyReferringToUpdatedAgency } from "../../domains/agency/use-cases/UpdateAgencyReferringToUpdatedAgency";
import { makeUpdateAgencyStatus } from "../../domains/agency/use-cases/UpdateAgencyStatus";
Expand All @@ -27,7 +28,6 @@ import { makeGetConnectedUsers } from "../../domains/connected-users/use-cases/G
import { makeGetUsers } from "../../domains/connected-users/use-cases/GetUsers";
import { makeLinkFranceTravailUsersToTheirAgencies } from "../../domains/connected-users/use-cases/LinkFranceTravailUsersToTheirAgencies";
import { makeRejectUserForAgency } from "../../domains/connected-users/use-cases/RejectUserForAgency";
import { makeRemoveUserFromAgency } from "../../domains/connected-users/use-cases/RemoveUserFromAgency";
import { makeUpdateUserForAgency } from "../../domains/connected-users/use-cases/UpdateUserForAgency";
import { makeAddConvention } from "../../domains/convention/use-cases/AddConvention";
import { makeAddValidatedConventionNps } from "../../domains/convention/use-cases/AddValidatedConventionNps";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {
type WithAgencyIdAndUserId,
withAgencyIdAndUserIdSchema,
} from "shared";
import type { CreateNewEvent } from "../../core/events/ports/EventBus";
import { useCaseBuilder } from "../../core/useCaseBuilder";
import {
rejectIfEditionOfValidatorsOfAgencyWithRefersTo,
validateAgencyRights,
} from "../helpers/agencyRights.helper";
import { throwIfNotAgencyAdminOrBackofficeAdmin } from "../helpers/authorization.helper";
} from "../../connected-users/helpers/agencyRights.helper";
import { throwIfNotAgencyAdminOrBackofficeAdmin } from "../../connected-users/helpers/authorization.helper";
import type { CreateNewEvent } from "../../core/events/ports/EventBus";
import { useCaseBuilder } from "../../core/useCaseBuilder";

export type RemoveUserFromAgency = ReturnType<typeof makeRemoveUserFromAgency>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
type AgencyDto,
AgencyDtoBuilder,
type AgencyRole,
ConnectedUserBuilder,
errors,
expectArraysToMatch,
Expand Down Expand Up @@ -279,152 +280,162 @@ describe("RemoveUserFromAgency", () => {
});
});

it("User to-review can remove himself", async () => {
const agency2 = new AgencyDtoBuilder().withId("agency-2-id").build();
const otherUserWithRightOnAgencies: User = {
...notAdmin,
id: "other-user-id",
};

uow.userRepository.users = [notAdminUser, otherUserWithRightOnAgencies];
uow.agencyRepository.agencies = [
toAgencyWithRights(agency, {
[notAdminUser.id]: {
roles: ["to-review"],
isNotifiedByEmail: false,
},
[otherUserWithRightOnAgencies.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
}),
toAgencyWithRights(agency2, {
[notAdminUser.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
[otherUserWithRightOnAgencies.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
}),
];

const inputParams: WithAgencyIdAndUserId = {
agencyId: agency.id,
userId: notAdminUser.id,
};
await removeUserFromAgency.execute(inputParams, notAdmin);

expectToEqual(uow.agencyRepository.agencies, [
toAgencyWithRights(agency, {
[otherUserWithRightOnAgencies.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
}),
toAgencyWithRights(agency2, {
[notAdminUser.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
[otherUserWithRightOnAgencies.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
}),
]);
expectArraysToMatch(uow.outboxRepository.events, [
{
topic: "ConnectedUserAgencyRightChanged",
payload: {
...inputParams,
triggeredBy: {
kind: "connected-user",
userId: notAdmin.id,
describe("Right paths", () => {
describe("user can remove himself from agency", () => {
it.each([
"to-review",
"agency-viewer",
"counsellor",
"validator",
"agency-admin",
] satisfies AgencyRole[])("with right %s", async (role) => {
const agency2 = new AgencyDtoBuilder().withId("agency-2-id").build();
const otherUserWithRightOnAgencies: User = {
...notAdmin,
id: "other-user-id",
};

uow.userRepository.users = [notAdminUser, otherUserWithRightOnAgencies];
uow.agencyRepository.agencies = [
toAgencyWithRights(agency, {
[notAdminUser.id]: {
roles: [role],
isNotifiedByEmail: false,
},
[otherUserWithRightOnAgencies.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
}),
toAgencyWithRights(agency2, {
[notAdminUser.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
[otherUserWithRightOnAgencies.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
}),
];

const inputParams: WithAgencyIdAndUserId = {
agencyId: agency.id,
userId: notAdminUser.id,
};
await removeUserFromAgency.execute(inputParams, notAdmin);

expectToEqual(uow.agencyRepository.agencies, [
toAgencyWithRights(agency, {
[otherUserWithRightOnAgencies.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
}),
toAgencyWithRights(agency2, {
[notAdminUser.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
[otherUserWithRightOnAgencies.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
}),
]);
expectArraysToMatch(uow.outboxRepository.events, [
{
topic: "ConnectedUserAgencyRightChanged",
payload: {
...inputParams,
triggeredBy: {
kind: "connected-user",
userId: notAdmin.id,
},
},
},
},
},
]);
});
]);
});
});

it.each([
{
triggeredByRole: "backoffice-admin",
triggeredByUser: connectedAdmin,
},
{
triggeredByRole: "agency-admin",
triggeredByUser: agencyAdminUser,
},
])("$triggeredByRole can remove user from agency", async ({
triggeredByUser,
}) => {
const agency2 = new AgencyDtoBuilder().withId("agency-2-id").build();
const otherUserWithRightOnAgencies: User = {
...notAdmin,
id: "other-user-id",
};

uow.userRepository.users = [notAdminUser, otherUserWithRightOnAgencies];
uow.agencyRepository.agencies = [
toAgencyWithRights(agency, {
[notAdminUser.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
[otherUserWithRightOnAgencies.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
}),
toAgencyWithRights(agency2, {
[notAdminUser.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
[otherUserWithRightOnAgencies.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
}),
];

const inputParams: WithAgencyIdAndUserId = {
agencyId: agency.id,
userId: notAdminUser.id,
};
await removeUserFromAgency.execute(inputParams, triggeredByUser);

expectToEqual(uow.agencyRepository.agencies, [
toAgencyWithRights(agency, {
[otherUserWithRightOnAgencies.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
}),
toAgencyWithRights(agency2, {
[notAdminUser.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
describe("can remove another user from agency", () => {
it.each([
{
triggeredByRole: "backoffice-admin",
triggeredByUser: connectedAdmin,
},
[otherUserWithRightOnAgencies.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
{
triggeredByRole: "agency-admin",
triggeredByUser: agencyAdminUser,
},
}),
]);
expectArraysToMatch(uow.outboxRepository.events, [
{
topic: "ConnectedUserAgencyRightChanged",
payload: {
...inputParams,
triggeredBy: {
kind: "connected-user",
userId: triggeredByUser.id,
])("when user has $triggeredByRole role", async ({ triggeredByUser }) => {
const agency2 = new AgencyDtoBuilder().withId("agency-2-id").build();
const otherUserWithRightOnAgencies: User = {
...notAdmin,
id: "other-user-id",
};

uow.userRepository.users = [notAdminUser, otherUserWithRightOnAgencies];
uow.agencyRepository.agencies = [
toAgencyWithRights(agency, {
[notAdminUser.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
[otherUserWithRightOnAgencies.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
}),
toAgencyWithRights(agency2, {
[notAdminUser.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
[otherUserWithRightOnAgencies.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
}),
];

const inputParams: WithAgencyIdAndUserId = {
agencyId: agency.id,
userId: notAdminUser.id,
};
await removeUserFromAgency.execute(inputParams, triggeredByUser);

expectToEqual(uow.agencyRepository.agencies, [
toAgencyWithRights(agency, {
[otherUserWithRightOnAgencies.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
}),
toAgencyWithRights(agency2, {
[notAdminUser.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
[otherUserWithRightOnAgencies.id]: {
roles: ["validator"],
isNotifiedByEmail: true,
},
}),
]);
expectArraysToMatch(uow.outboxRepository.events, [
{
topic: "ConnectedUserAgencyRightChanged",
payload: {
...inputParams,
triggeredBy: {
kind: "connected-user",
userId: triggeredByUser.id,
},
},
},
},
},
]);
]);
});
});
});
});
Loading
Loading