Skip to content

Commit 99eb0a4

Browse files
committed
feat(backend): add new role 'agent'
1 parent 1cc06f4 commit 99eb0a4

File tree

67 files changed

+384
-253
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+384
-253
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { UserStructureRole } from "@domifa/common";
2+
3+
export const USER_STRUCTURE_ROLES_NOT_FACTEUR: UserStructureRole[] = [
4+
"simple",
5+
"admin",
6+
"agent",
7+
"responsable",
8+
];

packages/backend/src/_common/model/users/user-structure/constants/USER_STRUCTURE_ROLE_ALL.const.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ export const USER_STRUCTURE_ROLE_ALL: UserStructureRole[] = [
44
"simple",
55
"admin",
66
"facteur",
7+
"agent",
78
"responsable",
89
];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
// @index('./*', f => `export * from '${f.path}'`)
22
export * from "./USER_STRUCTURE_ROLE_ALL.const";
3+
export * from "./USER_STRUCTURE_ROLES_NOT_FACTEUR";

packages/backend/src/auth/guards/usager-doc-access.guard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class UsagerDocAccessGuard implements CanActivate {
3030
throw new HttpException("USAGER_DOC_NOT_FOUND", HttpStatus.BAD_REQUEST);
3131
}
3232

33-
if (user?.role === "facteur") {
33+
if (user?.role === "facteur" || user?.role === "agent") {
3434
throw new HttpException("CANNOT_GET_DOC", HttpStatus.UNAUTHORIZED);
3535
}
3636

packages/backend/src/auth/structures-auth.controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { domifaConfig } from "../config";
2929
import { userSecurityPasswordChecker } from "../modules/users/services";
3030
import { AllowUserStructureRoles } from "./decorators";
3131
import { UserStructure } from "@domifa/common";
32+
import { appLogger } from "../util";
3233

3334
const userProfile: UserProfile = "structure";
3435

@@ -55,6 +56,7 @@ export class StructuresAuthController {
5556

5657
return res.status(HttpStatus.OK).json(accessToken);
5758
} catch (err) {
59+
appLogger.error(err);
5860
return res
5961
.status(HttpStatus.UNAUTHORIZED)
6062
.json({ message: "LOGIN_FAILED" });

packages/backend/src/modules/portail-admin/dto/register-user-structure-admin.dto.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import { Transform, TransformFnParams } from "class-transformer";
1313
import { LowerCaseTransform } from "../../../_common/decorators";
1414
import { UserStructureRole, UserFonction } from "@domifa/common";
15+
import { USER_STRUCTURE_ROLE_ALL } from "../../../_common/model";
1516

1617
export class RegisterUserStructureAdminDto {
1718
@ApiProperty({
@@ -78,10 +79,10 @@ export class RegisterUserStructureAdminDto {
7879
@ApiProperty({
7980
type: String,
8081
required: true,
81-
enum: ["admin", "simple", "facteur", "responsable"],
82+
enum: USER_STRUCTURE_ROLE_ALL,
8283
})
8384
@IsNotEmpty()
84-
@IsIn(["admin", "simple", "facteur", "responsable"])
85+
@IsIn(USER_STRUCTURE_ROLE_ALL)
8586
public readonly role!: UserStructureRole;
8687

8788
@IsNotEmpty()

packages/backend/src/modules/portail-usagers/controllers/portail-usagers-manager/portail-usagers-manager.controller.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import * as XLSX from "xlsx";
5353
@ApiTags("portail-usagers-manager")
5454
@UseGuards(AuthGuard("jwt"), AppUserGuard)
5555
@AllowUserProfiles("structure")
56-
@AllowUserStructureRoles(...USER_STRUCTURE_ROLE_ALL)
56+
@AllowUserStructureRoles("responsable", "admin")
5757
@ApiBearerAuth()
5858
export class PortailUsagersManagerController {
5959
constructor(private readonly appLogsService: AppLogsService) {}
@@ -114,15 +114,13 @@ export class PortailUsagersManagerController {
114114
}
115115
}
116116

117-
@AllowUserStructureRoles(...USER_STRUCTURE_ROLE_ALL)
118117
@Get("stats")
119118
public async getUserUsagerStats(
120119
@CurrentUser() currentUser: UserStructureAuthenticated
121120
): Promise<UsagersCountByStatus> {
122121
return usagerRepository.countUsagersByStatus(currentUser.structureId, true);
123122
}
124123

125-
@AllowUserStructureRoles(...USER_STRUCTURE_ROLE_ALL)
126124
@Get("export/all-accounts")
127125
public async exportAccountsToExcel(
128126
@Res() res: Response,
@@ -197,7 +195,6 @@ export class PortailUsagersManagerController {
197195
res.send(excelBuffer);
198196
}
199197

200-
@AllowUserStructureRoles("admin", "responsable")
201198
@Get("generate-all-accounts")
202199
public async generateAllAccounts(
203200
@Res() res: Response,
@@ -272,9 +269,9 @@ export class PortailUsagersManagerController {
272269
}
273270

274271
@UseGuards(UsagerAccessGuard)
275-
@AllowUserStructureRoles("simple", "responsable", "admin")
272+
@AllowUserStructureRoles("simple", "responsable", "admin", "agent")
276273
@Post("enable-access/:usagerRef")
277-
public async editPreupdatePortailUsagerOptionsference(
274+
public async enablePortailForUsager(
278275
@Res() res: Response,
279276
@Body() dto: UpdatePortailUsagerOptionsDto,
280277
@CurrentUsager() usager: Usager,
@@ -333,7 +330,6 @@ export class PortailUsagersManagerController {
333330
}
334331
}
335332

336-
@AllowUserStructureRoles(...USER_STRUCTURE_ROLE_ALL)
337333
@Post("all-accounts")
338334
public async getAllAccounts(
339335
@Body() pageOptionsDto: PageOptionsDto,

packages/backend/src/modules/structures/controllers/structure-doc.controller.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { join } from "path";
3737
import { FileManagerService } from "../../../util/file-manager/file-manager.service";
3838
import { validateDocTemplate } from "../../../usagers/utils/custom-docs";
3939
import { StructureDocTypesAvailable } from "@domifa/common";
40+
import { appLogger } from "../../../util";
4041

4142
@ApiTags("structure-docs")
4243
@ApiBearerAuth()
@@ -171,7 +172,8 @@ export class StructureDocController {
171172
});
172173

173174
return res.status(HttpStatus.OK).json(docs);
174-
} catch (e) {
175+
} catch (err) {
176+
appLogger.error(err);
175177
return res
176178
.status(HttpStatus.BAD_REQUEST)
177179
.json({ message: "UPLOAD_FAIL" });
@@ -211,7 +213,8 @@ export class StructureDocController {
211213
structureId: user.structureId,
212214
});
213215
return res.status(HttpStatus.OK).json(docs);
214-
} catch (e) {
216+
} catch (err) {
217+
appLogger.error(err);
215218
return res
216219
.status(HttpStatus.BAD_REQUEST)
217220
.json({ message: "DOC_NOT_FOUND" });

packages/backend/src/modules/users/controllers/users.controller.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import {
5252
UserStructureCreateLogContext,
5353
UserStructureRoleChangeLogContext,
5454
} from "../../app-logs/app-log-context.types";
55+
import { appLogger } from "../../../util";
5556

5657
const userProfile: UserProfile = "structure";
5758

@@ -62,16 +63,19 @@ const userProfile: UserProfile = "structure";
6263
@UseGuards(AuthGuard("jwt"), AppUserGuard)
6364
export class UsersController {
6465
constructor(private readonly appLogService: AppLogsService) {}
65-
@ApiBearerAuth()
66-
@ApiOperation({ summary: "Liste des utilisateurs" })
66+
6767
@Get("")
6868
public async getUsers(
6969
@CurrentUser() user: UserStructureAuthenticated
7070
): Promise<UserStructureProfile[]> {
7171
const users = await userStructureRepository.getVerifiedUsersByStructureId(
7272
user.structureId
7373
);
74-
if (user.role === "facteur" || user.role === "simple") {
74+
if (
75+
user.role === "facteur" ||
76+
user.role === "agent" ||
77+
user.role === "simple"
78+
) {
7579
return users.map((user) => {
7680
return {
7781
id: user.id,
@@ -83,7 +87,6 @@ export class UsersController {
8387
return users;
8488
}
8589

86-
@ApiOperation({ summary: "Accepter les CGU" })
8790
@Get("accept-terms")
8891
public async acceptTerms(@CurrentUser() user: UserStructureAuthenticated) {
8992
await userStructureRepository.update(
@@ -100,7 +103,6 @@ export class UsersController {
100103
return true;
101104
}
102105

103-
@ApiOperation({ summary: "Edition du mot de passe depuis le compte user" })
104106
@Get("last-password-update")
105107
public async getLastPasswordUpdate(
106108
@CurrentUser() user: UserStructureAuthenticated,
@@ -115,8 +117,6 @@ export class UsersController {
115117
}
116118

117119
@AllowUserStructureRoles("admin")
118-
@ApiBearerAuth("Administrateurs")
119-
@ApiOperation({ summary: "Editer le rôle d'un utilisateur" })
120120
@UseGuards(CanGetUserStructureGuard)
121121
@Patch("update-role/:userUuid")
122122
public async updateRole(
@@ -234,6 +234,7 @@ export class UsersController {
234234
}
235235

236236
@Patch()
237+
@ApiOperation({ summary: "Modifier mes informations" })
237238
public async patch(
238239
@CurrentUser() user: UserStructureAuthenticated,
239240
@Body() userDto: UserEditDto,
@@ -338,6 +339,7 @@ export class UsersController {
338339
});
339340
return res.status(HttpStatus.OK).json({ message: "OK" });
340341
} catch (err) {
342+
appLogger.error(err);
341343
return res
342344
.status(HttpStatus.BAD_REQUEST)
343345
.json({ message: "EDIT_PASSWORD_FAIL" });

packages/backend/src/modules/users/controllers/users.public.controller.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const userProfile: UserProfile = "structure";
2525
@Controller("users")
2626
@ApiTags("users")
2727
export class UsersPublicController {
28+
// TODO: add a limit for this endpoint by ip
2829
@Post("validate-email")
2930
public async validateEmail(
3031
@Body() emailDto: EmailDto,
@@ -57,6 +58,7 @@ export class UsersPublicController {
5758
});
5859
return res.status(HttpStatus.OK).json({ message: "OK" });
5960
} catch (err) {
61+
appLogger.error(err);
6062
return res
6163
.status(HttpStatus.BAD_REQUEST)
6264
.json({ message: "TOKEN_INVALID" });
@@ -77,6 +79,7 @@ export class UsersPublicController {
7779
});
7880
return res.status(HttpStatus.OK).json({ message: "OK" });
7981
} catch (err) {
82+
appLogger.error(err);
8083
return res
8184
.status(HttpStatus.BAD_REQUEST)
8285
.json({ message: "TOKEN_INVALID" });
@@ -101,7 +104,7 @@ export class UsersPublicController {
101104
userProfile,
102105
});
103106
} catch (err) {
104-
appLogger.error("Cannot reset password");
107+
appLogger.error(err);
105108
}
106109
return res.status(HttpStatus.OK).json({ message: "OK" });
107110
}

0 commit comments

Comments
 (0)