-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renomme des éléments liés aux droits
- Loading branch information
1 parent
e9a83d9
commit 72fef25
Showing
37 changed files
with
233 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
backend/src/auth/authorizations/permission-operation.enum.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export enum PermissionOperation { | ||
// Collectivités | ||
COLLECTIVITES_VISITE = 'collectivites.visite', | ||
COLLECTIVITES_LECTURE = 'collectivites.lecture', | ||
// Référentiels | ||
REFERENTIELS_LECTURE = 'referentiels.lecture', | ||
REFERENTIELS_EDITION = 'referentiels.edition', | ||
// Fiches actions | ||
PLANS_FICHES_EDITION = 'plans.fiches.edition', | ||
PLANS_FICHES_LECTURE = 'plans.fiches.lecture', | ||
PLANS_FICHES_VISITE = 'plans.fiches.visite', | ||
// Indicateurs | ||
INDICATEURS_LECTURE = 'indicateurs.lecture', | ||
INDICATEURS_VISITE = 'indicateurs.visite', | ||
INDICATEURS_EDITION = 'indicateurs.edition', | ||
INDICATEURS_TRAJECTOIRES_LECTURE = 'indicateurs.trajectoires.lecture', | ||
INDICATEURS_TRAJECTOIRES_EDITION = 'indicateurs.trajectoires.edition', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { Role } from '@/backend/auth/authorizations/roles/role.enum'; | ||
import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; | ||
|
||
export const Permission: Record<Role, PermissionOperation[]> = { | ||
[Role.CONNECTE]: [], | ||
[Role.VERIFIE]: [PermissionOperation.COLLECTIVITES_VISITE, PermissionOperation.PLANS_FICHES_VISITE, PermissionOperation.INDICATEURS_VISITE], | ||
[Role.SUPPORT]: [ | ||
PermissionOperation.COLLECTIVITES_VISITE, | ||
PermissionOperation.COLLECTIVITES_LECTURE, | ||
PermissionOperation.REFERENTIELS_LECTURE, | ||
PermissionOperation.PLANS_FICHES_VISITE, | ||
PermissionOperation.PLANS_FICHES_LECTURE, | ||
PermissionOperation.INDICATEURS_VISITE, | ||
PermissionOperation.INDICATEURS_LECTURE, | ||
PermissionOperation.INDICATEURS_TRAJECTOIRES_LECTURE, | ||
], | ||
[Role.ADEME]: [ | ||
PermissionOperation.COLLECTIVITES_VISITE, | ||
PermissionOperation.PLANS_FICHES_VISITE, | ||
PermissionOperation.INDICATEURS_VISITE, | ||
PermissionOperation.INDICATEURS_TRAJECTOIRES_LECTURE, | ||
], | ||
[Role.LECTURE]: [ | ||
PermissionOperation.COLLECTIVITES_VISITE, | ||
PermissionOperation.COLLECTIVITES_LECTURE, | ||
PermissionOperation.REFERENTIELS_LECTURE, | ||
PermissionOperation.PLANS_FICHES_VISITE, | ||
PermissionOperation.PLANS_FICHES_LECTURE, | ||
PermissionOperation.INDICATEURS_VISITE, | ||
PermissionOperation.INDICATEURS_LECTURE, | ||
PermissionOperation.INDICATEURS_TRAJECTOIRES_LECTURE, | ||
], | ||
[Role.EDITION]: [ | ||
PermissionOperation.COLLECTIVITES_VISITE, | ||
PermissionOperation.COLLECTIVITES_LECTURE, | ||
PermissionOperation.REFERENTIELS_LECTURE, | ||
PermissionOperation.REFERENTIELS_EDITION, | ||
PermissionOperation.PLANS_FICHES_VISITE, | ||
PermissionOperation.PLANS_FICHES_LECTURE, | ||
PermissionOperation.PLANS_FICHES_EDITION, | ||
PermissionOperation.INDICATEURS_VISITE, | ||
PermissionOperation.INDICATEURS_LECTURE, | ||
PermissionOperation.INDICATEURS_EDITION, | ||
PermissionOperation.INDICATEURS_TRAJECTOIRES_LECTURE, | ||
PermissionOperation.INDICATEURS_TRAJECTOIRES_EDITION, | ||
], | ||
[Role.ADMIN]: [ | ||
PermissionOperation.COLLECTIVITES_VISITE, | ||
PermissionOperation.COLLECTIVITES_LECTURE, | ||
PermissionOperation.REFERENTIELS_LECTURE, | ||
PermissionOperation.REFERENTIELS_EDITION, | ||
PermissionOperation.PLANS_FICHES_VISITE, | ||
PermissionOperation.PLANS_FICHES_LECTURE, | ||
PermissionOperation.PLANS_FICHES_EDITION, | ||
PermissionOperation.INDICATEURS_VISITE, | ||
PermissionOperation.INDICATEURS_LECTURE, | ||
PermissionOperation.INDICATEURS_EDITION, | ||
PermissionOperation.INDICATEURS_TRAJECTOIRES_LECTURE, | ||
PermissionOperation.INDICATEURS_TRAJECTOIRES_EDITION, | ||
], | ||
[Role.AUDITEUR]: [ | ||
PermissionOperation.COLLECTIVITES_VISITE, | ||
PermissionOperation.COLLECTIVITES_LECTURE, | ||
PermissionOperation.REFERENTIELS_LECTURE, | ||
PermissionOperation.REFERENTIELS_EDITION, | ||
PermissionOperation.PLANS_FICHES_VISITE, | ||
PermissionOperation.PLANS_FICHES_LECTURE, | ||
PermissionOperation.INDICATEURS_VISITE, | ||
PermissionOperation.INDICATEURS_LECTURE, | ||
PermissionOperation.INDICATEURS_EDITION, | ||
PermissionOperation.INDICATEURS_TRAJECTOIRES_LECTURE, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { getAuthUser, getTestApp, getTestDatabase, YOULOU_DOUDOU } from '@/backend/test'; | ||
import { INestApplication } from '@nestjs/common'; | ||
import { PermissionService } from '@/backend/auth/gestion-des-droits/permission.service'; | ||
import { PermissionService } from '@/backend/auth/authorizations/permission.service'; | ||
import { AuthenticatedUser } from '@/backend/auth/models/auth.models'; | ||
import { Authorization } from '@/backend/auth/gestion-des-droits/authorization.enum'; | ||
import { ResourceType } from '@/backend/auth/gestion-des-droits/resource-type.enum'; | ||
import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; | ||
import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; | ||
import DatabaseService from '../../common/services/database.service'; | ||
import { eq } from 'drizzle-orm'; | ||
import { utilisateurSupportTable } from '@/backend/auth/gestion-des-droits/roles/utilisateur-support.table'; | ||
import { utilisateurVerifieTable } from '@/backend/auth/gestion-des-droits/roles/utilisateur-verifie.table'; | ||
import { utilisateurSupportTable } from '@/backend/auth/authorizations/roles/utilisateur-support.table'; | ||
import { utilisateurVerifieTable } from '@/backend/auth/authorizations/roles/utilisateur-verifie.table'; | ||
import { dcpTable } from '@/backend/auth'; | ||
import { collectiviteTable } from '@/backend/collectivites/models/collectivite.table'; | ||
|
||
|
@@ -29,9 +29,9 @@ describe('Gestion des droits', () => { | |
describe('Droit en visite sur une collectivité -> NOK', async () => { | ||
test('Utilisateur vérifié -> OK', async () => { | ||
expect( | ||
await permissionService.hasTheRightTo( | ||
await permissionService.isAllowed( | ||
yoloDodoUser, | ||
Authorization.COLLECTIVITES_CONTENT_VISITE, | ||
PermissionOperation.COLLECTIVITES_VISITE, | ||
ResourceType.COLLECTIVITE, | ||
20, | ||
true | ||
|
@@ -44,9 +44,9 @@ describe('Gestion des droits', () => { | |
.set({ verifie: false }) | ||
.where(eq(utilisateurVerifieTable.userId, yoloDodoUser.id)); | ||
expect( | ||
await permissionService.hasTheRightTo( | ||
await permissionService.isAllowed( | ||
yoloDodoUser, | ||
Authorization.COLLECTIVITES_CONTENT_VISITE, | ||
PermissionOperation.COLLECTIVITES_VISITE, | ||
ResourceType.COLLECTIVITE, | ||
20, | ||
true | ||
|
@@ -70,9 +70,9 @@ describe('Gestion des droits', () => { | |
.set({ accessRestreint: true }) | ||
.where(eq(collectiviteTable.id, 20)); | ||
expect( | ||
await permissionService.hasTheRightTo( | ||
await permissionService.isAllowed( | ||
yoloDodoUser, | ||
Authorization.COLLECTIVITES_CONTENT_VISITE, | ||
PermissionOperation.COLLECTIVITES_VISITE, | ||
ResourceType.COLLECTIVITE, | ||
20, | ||
true | ||
|
@@ -94,9 +94,9 @@ describe('Gestion des droits', () => { | |
describe('Droit en lecture sur une collectivité -> NOK', async () => { | ||
test('Utilisateur vérifié sur sa collectivité -> OK', async () => { | ||
expect( | ||
await permissionService.hasTheRightTo( | ||
await permissionService.isAllowed( | ||
yoloDodoUser, | ||
Authorization.COLLECTIVITES_CONTENT_LECTURE, | ||
PermissionOperation.COLLECTIVITES_LECTURE, | ||
ResourceType.COLLECTIVITE, | ||
1, | ||
true | ||
|
@@ -110,9 +110,9 @@ describe('Gestion des droits', () => { | |
.set({ verifie: false }) | ||
.where(eq(utilisateurVerifieTable.userId, yoloDodoUser.id)); | ||
expect( | ||
await permissionService.hasTheRightTo( | ||
await permissionService.isAllowed( | ||
yoloDodoUser, | ||
Authorization.COLLECTIVITES_CONTENT_LECTURE, | ||
PermissionOperation.COLLECTIVITES_LECTURE, | ||
ResourceType.COLLECTIVITE, | ||
1, | ||
true | ||
|
@@ -133,9 +133,9 @@ describe('Gestion des droits', () => { | |
|
||
test('Utilisateur vérifié sur une autre collectivité -> NOK', async () => { | ||
expect( | ||
await permissionService.hasTheRightTo( | ||
await permissionService.isAllowed( | ||
yoloDodoUser, | ||
Authorization.COLLECTIVITES_CONTENT_LECTURE, | ||
PermissionOperation.COLLECTIVITES_LECTURE, | ||
ResourceType.COLLECTIVITE, | ||
20, | ||
true | ||
|
@@ -148,9 +148,9 @@ describe('Gestion des droits', () => { | |
.set({ support: true }) | ||
.where(eq(utilisateurSupportTable.userId, yoloDodoUser.id)); | ||
expect( | ||
await permissionService.hasTheRightTo( | ||
await permissionService.isAllowed( | ||
yoloDodoUser, | ||
Authorization.COLLECTIVITES_CONTENT_LECTURE, | ||
PermissionOperation.COLLECTIVITES_LECTURE, | ||
ResourceType.COLLECTIVITE, | ||
20, | ||
true | ||
|
@@ -170,9 +170,9 @@ describe('Gestion des droits', () => { | |
}); | ||
test('Auditeur sur sa collectivité audité -> OK', async () => { | ||
expect( | ||
await permissionService.hasTheRightTo( | ||
await permissionService.isAllowed( | ||
youlouDoudouUser, | ||
Authorization.COLLECTIVITES_CONTENT_LECTURE, | ||
PermissionOperation.COLLECTIVITES_LECTURE, | ||
ResourceType.COLLECTIVITE, | ||
10, | ||
true | ||
|
@@ -184,9 +184,9 @@ describe('Gestion des droits', () => { | |
describe('Droit en edition sur une collectivité -> NOK', async () => { | ||
test('Sur sa collectivité -> OK', async () => { | ||
expect( | ||
await permissionService.hasTheRightTo( | ||
await permissionService.isAllowed( | ||
yoloDodoUser, | ||
Authorization.FICHES_EDITION, | ||
PermissionOperation.PLANS_FICHES_EDITION, | ||
ResourceType.COLLECTIVITE, | ||
1, | ||
true | ||
|
@@ -195,9 +195,9 @@ describe('Gestion des droits', () => { | |
}); | ||
test('Sur une autre collectivité -> NOK', async () => { | ||
expect( | ||
await permissionService.hasTheRightTo( | ||
await permissionService.isAllowed( | ||
yoloDodoUser, | ||
Authorization.FICHES_EDITION, | ||
PermissionOperation.PLANS_FICHES_EDITION, | ||
ResourceType.COLLECTIVITE, | ||
20, | ||
true | ||
|
@@ -209,9 +209,9 @@ describe('Gestion des droits', () => { | |
describe("Droit en lecture sur la trajectoire d'une collectivité -> NOK", async () => { | ||
test('Sur sa collectivité -> OK', async () => { | ||
expect( | ||
await permissionService.hasTheRightTo( | ||
await permissionService.isAllowed( | ||
yoloDodoUser, | ||
Authorization.INDICATEURS_TRAJECTOIRE_LECTURE, | ||
PermissionOperation.INDICATEURS_TRAJECTOIRES_LECTURE, | ||
ResourceType.COLLECTIVITE, | ||
1, | ||
true | ||
|
@@ -221,9 +221,9 @@ describe('Gestion des droits', () => { | |
|
||
test('Sur une autre collectivité -> NOK', async () => { | ||
expect( | ||
await permissionService.hasTheRightTo( | ||
await permissionService.isAllowed( | ||
yoloDodoUser, | ||
Authorization.INDICATEURS_TRAJECTOIRE_LECTURE, | ||
PermissionOperation.INDICATEURS_TRAJECTOIRES_LECTURE, | ||
ResourceType.COLLECTIVITE, | ||
20, | ||
true | ||
|
@@ -237,9 +237,9 @@ describe('Gestion des droits', () => { | |
.set({ email: '[email protected]' }) | ||
.where(eq(dcpTable.userId, yoloDodoUser.id)); | ||
expect( | ||
await permissionService.hasTheRightTo( | ||
await permissionService.isAllowed( | ||
yoloDodoUser, | ||
Authorization.INDICATEURS_TRAJECTOIRE_LECTURE, | ||
PermissionOperation.INDICATEURS_TRAJECTOIRES_LECTURE, | ||
ResourceType.COLLECTIVITE, | ||
20, | ||
true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Oops, something went wrong.