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 cerfa dates #3598

Merged
merged 2 commits into from
Dec 17, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class StructureInformationAccessGuard implements CanActivate {
typeof r.user.structureId === "undefined"
) {
appLogger.error(
`[StructureInformationAccessGuard] invalid uuid or structureId`,
"[StructureInformationAccessGuard] invalid uuid or structureId",
{
sentry: true,
context: {
Expand Down Expand Up @@ -49,7 +49,7 @@ export class StructureInformationAccessGuard implements CanActivate {
r.structureInformation = structureInformation;
return r;
} catch (e) {
appLogger.error(`[UsagerAccessGuard] structureInformation not found`, {
appLogger.error("[UsagerAccessGuard] structureInformation not found", {
sentry: true,
context: {
uuid,
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/auth/services/auth-checker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function checkRole(
const isValidRole = user && expectedRoles.includes(user.role);

if (user && !isValidRole) {
appLogger.error(`[authChecker] invalid role`, {
appLogger.error("[authChecker] invalid role", {
sentry: true,
context: { role: user.role, user: user.id, expectedRoles },
});
Expand All @@ -37,7 +37,7 @@ function checkProfile(
const isValidRole = user && expectedProfiles.includes(userProfile);

if (user && !isValidRole) {
appLogger.error(`[authChecker] invalid profile`, {
appLogger.error("[authChecker] invalid profile", {
context: { userProfile, user: user._userId, expectedProfiles },
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async function sendMail({
meta: { "lien de ré-initialisation": lien },
};

messageEmailSender.sendMessageLater(messageContent, {
await messageEmailSender.sendMessageLater(messageContent, {
messageEmailId,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
HttpStatus,
Res,
UseGuards,
Param,
} from "@nestjs/common";
import { AuthGuard } from "@nestjs/passport";
import { ApiBearerAuth, ApiTags } from "@nestjs/swagger";
Expand All @@ -23,14 +24,21 @@ import { ExpressResponse } from "../../../../util/express";
import {
UserAdminAuthenticated,
UserStructureAuthenticated,
UserStructureSecurityEvent,
UserStructureTokens,
} from "../../../../_common/model";
import { AdminStructuresService } from "../../services";
import { CurrentUser } from "../../../../auth/decorators/current-user.decorator";
import { UsersController } from "../../../../users/controllers/users.controller";
import { RegisterUserAdminDto } from "../../../../users/dto";
import { format } from "date-fns";
import { structureCreatorService } from "../../../../structures/services";
import { DEPARTEMENTS_MAP, REGIONS_LISTE, Structure } from "@domifa/common";
import {
DEPARTEMENTS_MAP,
REGIONS_LISTE,
Structure,
UserStructure,
} from "@domifa/common";
import { MetabaseStatsDto } from "../../_dto/MetabaseStats.dto";
import { domifaConfig } from "../../../../config";
import { sign } from "jsonwebtoken";
Expand All @@ -40,6 +48,10 @@ import { StructureConfirmationDto } from "../../_dto";
import { StructureAdminForList } from "../../types";
import { userAccountActivatedEmailSender } from "../../../mails/services/templates-renderers";

export type UserStructureWithSecurity = UserStructure & {
temporaryTokens: UserStructureTokens;
events: UserStructureSecurityEvent;
};
@UseGuards(AuthGuard("jwt"), AppUserGuard)
@Controller("admin/structures")
@ApiTags("dashboard")
Expand Down Expand Up @@ -98,6 +110,42 @@ export class AdminStructuresController {
return await this.adminStructuresService.getAdminStructuresListData();
}

@Get("structure/:structureId")
@AllowUserProfiles("super-admin-domifa")
public async getStructure(
@CurrentUser() _user: UserAdminAuthenticated,
@Param("structureId") structureId: number
): Promise<Structure> {
return await structureRepository.findOneOrFail({
where: { id: structureId },
});
}

@Get("structure/:structureId/users")
@AllowUserProfiles("super-admin-domifa")
public async getUsers(
@CurrentUser() _user: UserAdminAuthenticated,
@Param("structureId") structureId: number
): Promise<Array<UserStructureWithSecurity>> {
return (await userStructureRepository
.createQueryBuilder("u")
.leftJoinAndSelect("user_structure_security", "uss", "u.id = uss.user_id")
.select([
"u.nom",
"u.prenom",
"u.mail",
"u.role",
"u.lastLogin",
"u.id",
"u.uuid",
"u.createdAt",
"uss.temporaryTokens",
"uss.eventsHistory",
])
.where({ structureId })
.getMany()) as unknown as UserStructureWithSecurity[];
}

@AllowUserProfiles("super-admin-domifa")
@Post("confirm-structure-creation")
public async confirmStructureCreation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const getLocation = async (address: string): Promise<Point | null> => {
apiUrl,
{
params,
timeout: 4000,
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
userStructureSecurityResetPasswordUpdater,
userStructureSecurityResetPasswordInitiator,
} from "../../database";
import { ExpressResponse } from "../../util";
import { appLogger, ExpressResponse } from "../../util";
import { EmailDto, ResetPasswordDto } from "../dto";
import { userResetPasswordEmailSender } from "../../modules/mails/services/templates-renderers";

Expand Down Expand Up @@ -94,7 +94,9 @@ export class UsersPublicController {
user,
token: userSecurity.temporaryTokens.token,
});
} catch (err) {}
} catch (err) {
appLogger.error("Cannot reset password");
}
return res.status(HttpStatus.OK).json({ message: "OK" });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ <h2 class="text-primary">Votre fichier est prêt à être importé !</h2>
</p>
</div>

<form #form [formGroup]="uploadForm" (ngSubmit)="submitFile('confirm')">
<form
#form
[formGroup]="uploadForm"
(ngSubmit)="submitFile(UsagersImportMode.confirm)"
>
<div>
<input
type="hidden"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class ImportComponent implements OnInit, OnDestroy {

public previewTable?: ImportPreviewTable;
public visibleRows: ImportPreviewRow[];
public readonly UsagersImportMode = UsagersImportMode;
public readonly COL = USAGERS_IMPORT_COLUMNS;
public readonly USAGERS_IMPORT_COLUMNS_AYANT_DROIT =
USAGERS_IMPORT_COLUMNS_AYANT_DROIT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
<button
ngbDropdownItem
type="button"
(click)="getCerfa(usager.ref, 'demande')"
(click)="getCerfa(usager.ref, CerfaDocType.demande)"
>
Télécharger le Cerfa d'attestation de demande
</button>
<button
ngbDropdownItem
type="button"
(click)="getCerfa(usager.ref, 'attestation')"
(click)="getCerfa(usager.ref, CerfaDocType.attestation)"
*ngIf="
usager.decision.statut !== 'REFUS' && usager.decision.statut !== 'RADIE'
"
Expand All @@ -40,15 +40,25 @@
"
ngbDropdownItem
type="button"
(click)="getDomifaCustomDoc(usager.ref, 'courrier_radiation')"
(click)="
getDomifaCustomDoc(
usager.ref,
StructureDocTypesAvailable.courrier_radiation
)
"
>
Télécharger le courrier de radiation
</button>
<button
*ngIf="usager.decision.statut === 'VALIDE'"
ngbDropdownItem
type="button"
(click)="getDomifaCustomDoc(usager.ref, 'attestation_postale')"
(click)="
getDomifaCustomDoc(
usager.ref,
StructureDocTypesAvailable.attestation_postale
)
"
>
Télécharger l'attestation postale
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export class ManageDownloadDocsComponent implements OnDestroy {

public me!: UserStructure | null;
@Input() public usager!: UsagerFormModel;
public readonly CerfaDocType = CerfaDocType;
public readonly StructureDocTypesAvailable = StructureDocTypesAvailable;

constructor(
private readonly documentService: DocumentService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h2 class="form-title">
<br />
<button
type="button"
(click)="getCerfa('demande')"
(click)="getCerfa(CerfaDocType.demande)"
class="btn btn-outline-primary"
>
<fa-icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { NationalStatsComponent } from "./components/national-stats/national-sta
import { StatsService } from "./services/stats.service";
import { AdminStructuresTableComponent } from "./components/admin-structures-table/admin-structures-table.component";
import { TableHeadSortComponent } from "../shared/components/table-head-sort/table-head-sort.component";
import { SortArrayPipe } from "../shared/pipes/sort-array.pipe";

@NgModule({
declarations: [
Expand All @@ -28,6 +29,7 @@ import { TableHeadSortComponent } from "../shared/components/table-head-sort/tab
FormsModule,
ReactiveFormsModule,
TableHeadSortComponent,
SortArrayPipe,
],
providers: [StatsService],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,6 @@
<app-admin-structures-export></app-admin-structures-export>
</div>
</div>
<nav id="statut-selector" class="mt-4 row d-print-none">
<button type="button" class="col-md-2">
Structures
<span *ngIf="!!structures && !!filteredStructures"
>({{ filteredStructures.length
}}<span *ngIf="totalStructures !== filteredStructures.length"
>/{{ totalStructures }}</span
>)</span
>
</button>
<button type="button" class="col-md-2">Utilisateurs (à venir)</button>
</nav>
</div>
</div>

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Pipe, PipeTransform } from "@angular/core";
import { compareAttributes } from "@domifa/common";

@Pipe({
name: "sortArray",
standalone: true,
})
export class SortArrayPipe implements PipeTransform {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
transform(array: any[], sortKey: string, sortValue: "asc" | "desc"): any[] {
if (!array || array.length <= 1) {
return array;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
return array.sort((a: any, b: any) => {
const valA = a[sortKey];
const valB = b[sortKey];

return compareAttributes(valA, valB, sortValue === "asc");
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export class AdminStructuresApiClient {
this.http = http;
}

public getStructure(structureUuid: string): Observable<Structure> {
return this.http.get<Structure>(
`${environment.apiUrl}admin/structures/${structureUuid}`
);
}
public deleteSendInitialMail(structureUuid: string) {
return this.http.put(
`${environment.apiUrl}admin/structures-delete/send-mail/${structureUuid}`,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>structure-page works!</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ComponentFixture, TestBed } from "@angular/core/testing";

import { StructurePageComponent } from "./structure-page.component";

describe("StructurePageComponent", () => {
let component: StructurePageComponent;
let fixture: ComponentFixture<StructurePageComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [StructurePageComponent],
}).compileComponents();

fixture = TestBed.createComponent(StructurePageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it("should create", () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component } from "@angular/core";

@Component({
selector: "app-structure-page",
standalone: true,
imports: [],
templateUrl: "./structure-page.component.html",
styleUrl: "./structure-page.component.css",
})
export class StructurePageComponent {}
Loading
Loading