Skip to content

Commit

Permalink
fix(backend): fix build & tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Dec 17, 2024
1 parent 50d719d commit 8fdc818
Show file tree
Hide file tree
Showing 21 changed files with 184 additions and 59 deletions.
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,12 +12,14 @@ 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 { StructureComponent } from "./components/structure/structure.component";

@NgModule({
declarations: [
AdminStructuresListComponent,
AdminStructuresTableComponent,
NationalStatsComponent,
StructureComponent,
],
imports: [
CommonModule,
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,28 @@
<div class="head-page pt-4">
<div class="container">
<div class="row">
<div class="col-md-9 col-12">
<h1 class="title">
{{ structure.nom }}
</h1>
</div>
</div>

<nav id="statut-selector" class="mt-4 row d-print-none">
<a [routerLink]="['/structures', structure.id]" class="col">
Structure
</a>
<a [routerLink]="['/structures', structure.id, 'users']" class="col">
Utilisateurs
</a>
<a [routerLink]="['/structures', structure.id, 'activity']" class="col">
Activité
</a>
</nav>
</div>
</div>
<div class="content">
<div class="page-content p-4">
<div class="container"></div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ComponentFixture, TestBed } from "@angular/core/testing";

import { StructureComponent } from "./structure.component";

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

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

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

it("should create", () => {
expect(component).toBeTruthy();
});
});
Loading

0 comments on commit 8fdc818

Please sign in to comment.