Skip to content

Commit

Permalink
fix establishment tutor can get conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
enguerranws committed Sep 19, 2024
1 parent 41ae377 commit c7bee69
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
47 changes: 47 additions & 0 deletions back/src/domains/convention/use-cases/GetConvention.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ describe("Get Convention", () => {
.withValidatorEmails(["[email protected]"])
.build();
const convention = new ConventionDtoBuilder().withAgencyId(agency.id).build();
const conventionWithEstablishmentTutor = new ConventionDtoBuilder()
.withAgencyId(agency.id)
.withEstablishmentTutor({
email: "[email protected]",
firstName: "John",
lastName: "Doe",
role: "establishment-tutor",
phone: "+33602010203",
job: "Job",
})
.build();
let getConvention: GetConvention;
let uow: InMemoryUnitOfWork;

Expand Down Expand Up @@ -257,6 +268,42 @@ describe("Get Convention", () => {
});
});

it("that establishment tutor is also the inclusion connected user", async () => {
uow.conventionRepository.setConventions([
conventionWithEstablishmentTutor,
]);
const user: InclusionConnectedUser = {
id: "my-tutor-user-id",
email: conventionWithEstablishmentTutor.establishmentTutor.email,
firstName: "John",
lastName: "Doe",
agencyRights: [],
dashboards: { agencies: {}, establishments: {} },
externalId: "john-tutor-external-id",
createdAt: new Date().toISOString(),
};
uow.userRepository.setInclusionConnectedUsers([user]);

const jwtPayload: InclusionConnectDomainJwtPayload = {
userId: user.id,
};

const fetchedConvention = await getConvention.execute(
{ conventionId: conventionWithEstablishmentTutor.id },
jwtPayload,
);

expectToEqual(fetchedConvention, {
...conventionWithEstablishmentTutor,
agencyName: agency.name,
agencyDepartment: agency.address.departmentCode,
agencyKind: agency.kind,
agencySiret: agency.agencySiret,
agencyCounsellorEmails: agency.counsellorEmails,
agencyValidatorEmails: agency.validatorEmails,
});
});

it("the user is backofficeAdmin", async () => {
const backofficeAdminUser = new InclusionConnectedUserBuilder()
.withIsAdmin(true)
Expand Down
8 changes: 5 additions & 3 deletions shared/src/inclusionConnect/inclusionConnect.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
InclusionConnectedUser,
User,
} from "../inclusionConnectedAllowed/inclusionConnectedAllowed.dto";
import { SignatoryRole } from "../role/role.dto";
import { EstablishmentRole } from "../role/role.dto";
import { allowedStartInclusionConnectLoginPages } from "../routes/routes";
import { ExcludeFromExisting, ExtractFromExisting } from "../utils";
import { ExcludeFromExisting } from "../utils";

export type AuthenticateWithInclusionCodeConnectParams = WithSourcePage & {
code: string;
Expand All @@ -26,7 +26,7 @@ export type AuthenticatedUserQueryParams = {

type InclusionConnectConventionManageAllowedRole =
| ExcludeFromExisting<AgencyRole, "toReview">
| ExtractFromExisting<SignatoryRole, "establishment-representative">
| EstablishmentRole
| "backOffice";

export const getIcUserRoleForAccessingConvention = (
Expand All @@ -37,6 +37,8 @@ export const getIcUserRoleForAccessingConvention = (
if (user.isBackofficeAdmin) roles.push("backOffice");
if (convention.signatories.establishmentRepresentative.email === user.email)
roles.push("establishment-representative");
if (convention.establishmentTutor.email === user.email)
roles.push("establishment-tutor");
const agencyRight = user.agencyRights.find(
(agencyRight) => agencyRight.agency.id === convention.agencyId,
);
Expand Down

0 comments on commit c7bee69

Please sign in to comment.