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: add script to automatically disable accounts that are no longer valid #1042

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
4 changes: 4 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ fileignoreconfig:
checksum: 8abd2b819601d46cc6a3d0a61a60b76391601f2d89d9126f5167b684878bd2d1
- filename: frontend/src/index.tsx
checksum: 25a58ba4ecfb8606daf5efbae6a1f0f2efe4e87a4a8a18e745712b39198d93a5
- filename: frontend/src/views/Account/AccountCreation/AccountPasswordCreationView.tsx
checksum: a80e1f108214c16e96a5c7eed234b6e54f048413e9f5ee52e06730b06e9d415c
- filename: packages/api-sdk/src/test/campaign-api.test.ts
checksum: b200d9e1fec310660a91e99cd048b24cbe983e0f9f965861d061a7f0992af43e
- filename: packages/healthcheck/src/checks/brevo.ts
Expand All @@ -27,6 +29,8 @@ fileignoreconfig:
checksum: 459ad7c52a09b1a5d885f0e13acd68a894b862470125529ecc28a4116c737df7
- filename: server/src/services/ceremaService/ceremaService.ts
checksum: 2005ee48d86de2c6e6e57b187862cdeaafcb9f0c49e9a82ec7031910957174e8
- filename: server/src/test/testFixtures.ts
checksum: 2e71680c14d925c4bb84b15262df05f4f588ee67976e144d5842a22337c0ba18
scopeconfig:
- scope: node
allowed_patterns:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useLocation } from 'react-router-dom';

import { useEffect } from 'react';
import { createModal } from '@codegouvfr/react-dsfr/Modal';
import Grid from '@mui/material/Unstable_Grid2';
Expand Down
1 change: 1 addition & 0 deletions frontend/src/hooks/useActivationEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ export function useActivationEmail() {
sendActivationEmail
};
}

9 changes: 9 additions & 0 deletions frontend/src/hooks/useActivationEmailLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useGetActivationEmailQuery } from '../services/signup-link.service';

export function useActivationEmailLink(id: string) {
const { data, isLoading, error } = useGetActivationEmailQuery(id);
return {
activationEmailLink: error ? null : data,
isLoading
};
}
11 changes: 11 additions & 0 deletions frontend/src/hooks/usePortailDFAccess.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { SignupLinkDTO } from '@zerologementvacant/models';
import { useGetUserAccessQuery } from '../services/portaildf.service';

export function useUserAccess(signupLink: SignupLinkDTO | null | undefined) {
const { data, isLoading, error } = useGetUserAccessQuery(signupLink?.prospectEmail ?? '', {skip: !signupLink});

return {
access: error ? null : data,
isLoading
};
}
30 changes: 0 additions & 30 deletions frontend/src/hooks/useProspect.tsx

This file was deleted.

15 changes: 8 additions & 7 deletions frontend/src/mocks/handlers/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
HousingDTO,
NoteDTO,
OwnerDTO,
ProspectDTO,
SignupLinkDTO,
UserDTO
UserDTO,
CeremaUser
} from '@zerologementvacant/models';
import {
genCampaignDTO,
Expand All @@ -23,7 +23,8 @@ import {
genHousingDTO,
genOwnerDTO,
genSenderDTO,
genUserDTO
genUserDTO,
genCeremaUser
} from '@zerologementvacant/models/fixtures';

const campaigns: CampaignDTO[] = Array.from({ length: 10 }, genCampaignDTO);
Expand All @@ -39,6 +40,8 @@ const drafts: DraftDTO[] = campaigns.map<DraftDTO>(() =>

const users: UserDTO[] = Array.from({ length: 10 }, () => genUserDTO());

const ceremaUsers: CeremaUser[] = Array.from({ length: 10 }, () => genCeremaUser());

const groups: GroupDTO[] = Array.from({ length: 5 }, () =>
genGroupDTO(faker.helpers.arrayElement(users))
);
Expand Down Expand Up @@ -112,8 +115,6 @@ const housingEvents = new Map<HousingDTO['id'], EventDTO<HousingDTO>[]>();

const housingNotes = new Map<HousingDTO['id'], NoteDTO[]>();

const prospects: ProspectDTO[] = [];

const signupLinks: SignupLinkDTO[] = [];

const data = {
Expand All @@ -131,9 +132,9 @@ const data = {
housingNotes,
housingOwners,
owners,
prospects,
signupLinks,
users
users,
ceremaUsers,
};

export default data;
6 changes: 3 additions & 3 deletions frontend/src/mocks/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { housingHandlers } from './housing-handlers';
import { noteHandlers } from './note-handlers';
import { ownerHandlers } from './owner-handlers';
import { signupLinksHandlers } from './signup-links-handlers';
import { userAccessHandlers } from './user-access-handlers';
import { userHandlers } from './user-handlers';
import { prospectHandlers } from './prospect-handlers';

export const handlers: RequestHandler[] = [
...authHandlers,
Expand All @@ -25,7 +25,7 @@ export const handlers: RequestHandler[] = [
...housingHandlers,
...noteHandlers,
...ownerHandlers,
...prospectHandlers,
...signupLinksHandlers,
...userHandlers
...userHandlers,
...userAccessHandlers
];
66 changes: 0 additions & 66 deletions frontend/src/mocks/handlers/prospect-handlers.ts

This file was deleted.

28 changes: 28 additions & 0 deletions frontend/src/mocks/handlers/signup-links-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@zerologementvacant/models';
import data from './data';
import config from '../../utils/config';
import { isPast } from 'date-fns';

export const signupLinksHandlers: RequestHandler[] = [
http.post<never, SignupLinkPayloadDTO, SignupLinkDTO>(
Expand All @@ -24,5 +25,32 @@ export const signupLinksHandlers: RequestHandler[] = [
status: constants.HTTP_STATUS_CREATED
});
}
),
http.get<never, SignupLinkDTO>(
`${config.apiEndpoint}/api/signup-links/:id`,
({ params }) => {
const { id } = params;
const signupLink = data.signupLinks.find((link) => link.id === id);

if (!signupLink) {
return HttpResponse.json({
name: 'SignupLinkMissingError',
message: `Signup ${id} link missing`
},
{ status: constants.HTTP_STATUS_NOT_FOUND });
}

if (isPast(signupLink.expiresAt)) {
return HttpResponse.json({
name: 'SignupLinkExpiredError',
message: `Signup link expired`
},
{ status: constants.HTTP_STATUS_GONE });
}

return HttpResponse.json(signupLink, {
status: constants.HTTP_STATUS_OK
});
}
)
];
59 changes: 59 additions & 0 deletions frontend/src/mocks/handlers/user-access-handlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { constants } from 'http2';
import { http, HttpResponse, RequestHandler } from 'msw';

import {
SignupLinkDTO
} from '@zerologementvacant/models';
import data from './data';
import config from '../../utils/config';
import { isPast } from 'date-fns';

export const userAccessHandlers: RequestHandler[] = [
http.get<never, SignupLinkDTO>(
`${config.apiEndpoint}/api/user-access`,
({ request }) => {

const url = new URL(request.url);
const email = url.searchParams.get('email');
const signupLink = data.signupLinks.find((link) => link.prospectEmail === email);

if (!signupLink) {
return HttpResponse.json({
name: 'SignupLinkMissingError',
message: `Signup ${email} link missing`
},
{ status: constants.HTTP_STATUS_NOT_FOUND });
}

if (isPast(signupLink.expiresAt)) {
return HttpResponse.json({
name: 'SignupLinkExpiredError',
message: `Signup link expired`
},
{ status: constants.HTTP_STATUS_GONE });
}

const user = data.ceremaUsers.find((user) => user.email === email);
if(!user) {
return HttpResponse.json({
name: 'AuthenticationFailedError',
message: `Authentication failed.`
},
{ status: constants.HTTP_STATUS_UNAUTHORIZED });
}

if(user !== null) {
if(user.establishmentId === null) {
return HttpResponse.json({
name: 'EstablishmentMissingError',
message: `Establishment ${undefined} missing`
},
{ status: constants.HTTP_STATUS_NOT_FOUND });
}
return HttpResponse.json(user, {
status: constants.HTTP_STATUS_OK
});
}
}
)
];
10 changes: 0 additions & 10 deletions frontend/src/models/Prospect.tsx

This file was deleted.

65 changes: 0 additions & 65 deletions frontend/src/services/owner-prospect.service.ts

This file was deleted.

Loading
Loading