diff --git a/server/src/entities/page_permissions.entity.ts b/server/src/entities/page_permissions.entity.ts index 877afc5e29..7d265b696b 100644 --- a/server/src/entities/page_permissions.entity.ts +++ b/server/src/entities/page_permissions.entity.ts @@ -1,11 +1,7 @@ import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, CreateDateColumn, OneToMany } from 'typeorm'; import { Page } from './page.entity'; import { PageUser } from './page_users.entity'; - -export enum PermissionType { - SINGLE = 'SINGLE', - GROUP = 'GROUP', -} +import { PAGE_PERMISSION_TYPE } from '@modules/app-permissions/constants'; @Entity('page_permissions') export class PagePermission { @@ -17,9 +13,9 @@ export class PagePermission { @Column({ type: 'enum', - enum: PermissionType, + enum: PAGE_PERMISSION_TYPE, }) - type: PermissionType; + type: PAGE_PERMISSION_TYPE; @CreateDateColumn({ name: 'created_at' }) createdAt: Date; diff --git a/server/src/modules/app-permissions/constants/features.ts b/server/src/modules/app-permissions/constants/features.ts index a6ec529c26..6d77625ec5 100644 --- a/server/src/modules/app-permissions/constants/features.ts +++ b/server/src/modules/app-permissions/constants/features.ts @@ -6,5 +6,9 @@ export const FEATURES: FeaturesConfig = { [MODULES.APP_PERMISSIONS]: { [FEATURE_KEY.FETCH_USERS]: {}, [FEATURE_KEY.FETCH_USER_GROUPS]: {}, + [FEATURE_KEY.FETCH_PAGE_PERMISSIONS]: {}, + [FEATURE_KEY.CREATE_PAGE_PERMISSIONS]: {}, + [FEATURE_KEY.UPDATE_PAGE_PERMISSIONS]: {}, + [FEATURE_KEY.DELETE_PAGE_PERMISSIONS]: {}, }, }; diff --git a/server/src/modules/app-permissions/constants/index.ts b/server/src/modules/app-permissions/constants/index.ts index dc0862e88c..ef0b13f325 100644 --- a/server/src/modules/app-permissions/constants/index.ts +++ b/server/src/modules/app-permissions/constants/index.ts @@ -1,4 +1,13 @@ +export enum PAGE_PERMISSION_TYPE { + SINGLE = 'SINGLE', + GROUP = 'GROUP', +} + export enum FEATURE_KEY { FETCH_USERS = 'fetch_users', FETCH_USER_GROUPS = 'fetch_user_groups', + FETCH_PAGE_PERMISSIONS = 'fetch_page_permissions', + CREATE_PAGE_PERMISSIONS = 'create_page_permissions', + UPDATE_PAGE_PERMISSIONS = 'update_page_permissions', + DELETE_PAGE_PERMISSIONS = 'delete_page_permissions', } diff --git a/server/src/modules/app-permissions/controller.ts b/server/src/modules/app-permissions/controller.ts index 3a301cf732..2d0ccea9ce 100644 --- a/server/src/modules/app-permissions/controller.ts +++ b/server/src/modules/app-permissions/controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, NotFoundException, Param, Res, UseGuards } from '@nestjs/common'; +import { Body, Controller, Delete, Get, NotFoundException, Param, Post, Put, Res, UseGuards } from '@nestjs/common'; import { Response } from 'express'; import { User } from '@modules/app/decorators/user.decorator'; import { IAppPermissionsController } from './interfaces/IController'; @@ -8,6 +8,7 @@ import { MODULES } from '@modules/app/constants/modules'; import { InitFeature } from '@modules/app/decorators/init-feature.decorator'; import { FEATURE_KEY } from './constants'; import { JwtAuthGuard } from '@modules/session/guards/jwt-auth.guard'; +import { CreatePagePermissionDto } from './dto'; @InitModule(MODULES.APP_PERMISSIONS) @UseGuards(JwtAuthGuard, FeatureAbilityGuard) @@ -34,4 +35,50 @@ export class AppPermissionsController implements IAppPermissionsController { ): Promise { throw new NotFoundException(); } + + @InitFeature(FEATURE_KEY.FETCH_PAGE_PERMISSIONS) + @Get(':appId/pages/:pageId') + async fetchPagePermissions( + @User() user, + @Param('appId') appId: string, + @Param('pageId') pageId: string, + @Res({ passthrough: true }) response: Response + ): Promise { + throw new NotFoundException(); + } + + @InitFeature(FEATURE_KEY.CREATE_PAGE_PERMISSIONS) + @Post(':appId/pages/:pageId') + async createPagePermissions( + @User() user, + @Param('appId') appId: string, + @Param('pageId') pageId: string, + @Body() body: CreatePagePermissionDto, + @Res({ passthrough: true }) response: Response + ): Promise { + throw new NotFoundException(); + } + + @InitFeature(FEATURE_KEY.UPDATE_PAGE_PERMISSIONS) + @Put(':appId/pages/:pageId') + async updatePagePermissions( + @User() user, + @Param('appId') appId: string, + @Param('pageId') pageId: string, + @Body() body: CreatePagePermissionDto, + @Res({ passthrough: true }) response: Response + ): Promise { + throw new NotFoundException(); + } + + @InitFeature(FEATURE_KEY.DELETE_PAGE_PERMISSIONS) + @Delete(':appId/pages/:pageId') + async deletePagePermissions( + @User() user, + @Param('appId') appId: string, + @Param('pageId') pageId: string, + @Res({ passthrough: true }) response: Response + ): Promise { + throw new NotFoundException(); + } } diff --git a/server/src/modules/app-permissions/dto/index.ts b/server/src/modules/app-permissions/dto/index.ts new file mode 100644 index 0000000000..20a1bd98b8 --- /dev/null +++ b/server/src/modules/app-permissions/dto/index.ts @@ -0,0 +1,26 @@ +import { IsUUID, IsEnum, IsArray, IsString, IsOptional, ValidateIf } from 'class-validator'; +import { Type } from 'class-transformer'; +import { PAGE_PERMISSION_TYPE } from '../constants'; + +export class CreatePagePermissionDto { + @IsUUID(4) + @IsOptional() + pageId: string; + + @IsEnum(PAGE_PERMISSION_TYPE) + type: PAGE_PERMISSION_TYPE; + + @ValidateIf((o) => o.type === PAGE_PERMISSION_TYPE.SINGLE) + @IsArray() + @IsString({ each: true }) + @IsOptional() + @Type(() => String) + users?: string[]; + + @ValidateIf((o) => o.type === PAGE_PERMISSION_TYPE.GROUP) + @IsArray() + @IsString({ each: true }) + @IsOptional() + @Type(() => String) + groups?: string[]; +} diff --git a/server/src/modules/app-permissions/interfaces/IController.ts b/server/src/modules/app-permissions/interfaces/IController.ts index 615873e1ed..bfa35aa730 100644 --- a/server/src/modules/app-permissions/interfaces/IController.ts +++ b/server/src/modules/app-permissions/interfaces/IController.ts @@ -1,8 +1,29 @@ import { User } from '@entities/user.entity'; import { Response } from 'express'; +import { CreatePagePermissionDto } from '../dto'; export interface IAppPermissionsController { fetchUsers(user: User, appId: string, response: Response): Promise; fetchUserGroups(user: User, appId: string, response: Response): Promise; + + fetchPagePermissions(user: User, appId: string, pageId: string, response: Response): Promise; + + createPagePermissions( + user: User, + appId: string, + pageId: string, + body: CreatePagePermissionDto, + response: Response + ): Promise; + + updatePagePermissions( + user: User, + appId: string, + pageId: string, + body: CreatePagePermissionDto, + response: Response + ): Promise; + + deletePagePermissions(user: User, appId: string, pageId: string, response: Response): Promise; } diff --git a/server/src/modules/app-permissions/interfaces/IService.ts b/server/src/modules/app-permissions/interfaces/IService.ts index 8d6ee9eee5..cad5fef726 100644 --- a/server/src/modules/app-permissions/interfaces/IService.ts +++ b/server/src/modules/app-permissions/interfaces/IService.ts @@ -1,7 +1,16 @@ import { User } from '@entities/user.entity'; +import { CreatePagePermissionDto } from '../dto'; export interface IAppPermissionsService { fetchUsers(appId: string, user: User): Promise; fetchUserGroups(appId: string, user: User): Promise; + + fetchPagePermissions(pageId: string): Promise; + + createPagePermissions(pageId: string, body: CreatePagePermissionDto): Promise; + + updatePagePermissions(appId: string, pageId: string, body: CreatePagePermissionDto, user: User): Promise; + + deletePagePermissions(pageId: string): Promise; } diff --git a/server/src/modules/app-permissions/interfaces/IUtilService.ts b/server/src/modules/app-permissions/interfaces/IUtilService.ts index b453efd251..0d2be25315 100644 --- a/server/src/modules/app-permissions/interfaces/IUtilService.ts +++ b/server/src/modules/app-permissions/interfaces/IUtilService.ts @@ -1,8 +1,13 @@ import { User } from '@entities/user.entity'; import { GroupPermissions } from '@entities/group_permissions.entity'; +import { CreatePagePermissionDto } from '../dto'; export interface IUtilService { getUsersWithViewAccess(appId: string, organizationId: string, endUserIds: string[]): Promise; getUserGroupsWithViewAccess(appId: string, organizationId: string): Promise; + + createPagePermission(pageId: string, body: CreatePagePermissionDto): Promise; + + updatePagePermission(pageId: string, body: CreatePagePermissionDto): Promise; } diff --git a/server/src/modules/app-permissions/repositories/repository.ts b/server/src/modules/app-permissions/repositories/repository.ts deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/server/src/modules/app-permissions/service.ts b/server/src/modules/app-permissions/service.ts index e97a39fb84..c6b5bc640d 100644 --- a/server/src/modules/app-permissions/service.ts +++ b/server/src/modules/app-permissions/service.ts @@ -12,4 +12,20 @@ export class AppPermissionsService implements IAppPermissionsService { async fetchUserGroups(appId, user) { throw new Error('Method not implemented.'); } + + async fetchPagePermissions(pageId) { + throw new Error('Method not implemented.'); + } + + async createPagePermissions(pageId, body) { + throw new Error('Method not implemented.'); + } + + async updatePagePermissions(appId, pageId, body, user) { + throw new Error('Method not implemented.'); + } + + async deletePagePermissions(pageId) { + throw new Error('Method not implemented.'); + } } diff --git a/server/src/modules/app-permissions/types/index.ts b/server/src/modules/app-permissions/types/index.ts index ecced6b47c..86a41afba1 100644 --- a/server/src/modules/app-permissions/types/index.ts +++ b/server/src/modules/app-permissions/types/index.ts @@ -5,6 +5,10 @@ import { MODULES } from '@modules/app/constants/modules'; interface Features { [FEATURE_KEY.FETCH_USERS]: FeatureConfig; [FEATURE_KEY.FETCH_USER_GROUPS]: FeatureConfig; + [FEATURE_KEY.FETCH_PAGE_PERMISSIONS]: FeatureConfig; + [FEATURE_KEY.CREATE_PAGE_PERMISSIONS]: FeatureConfig; + [FEATURE_KEY.UPDATE_PAGE_PERMISSIONS]: FeatureConfig; + [FEATURE_KEY.DELETE_PAGE_PERMISSIONS]: FeatureConfig; } export interface FeaturesConfig { diff --git a/server/src/modules/app-permissions/util.service.ts b/server/src/modules/app-permissions/util.service.ts index 2705e60668..377c693a26 100644 --- a/server/src/modules/app-permissions/util.service.ts +++ b/server/src/modules/app-permissions/util.service.ts @@ -2,6 +2,7 @@ import { User } from '@entities/user.entity'; import { IUtilService } from './interfaces/IUtilService'; import { Injectable } from '@nestjs/common'; import { GroupPermissions } from '@entities/group_permissions.entity'; +import { CreatePagePermissionDto } from './dto'; @Injectable() export class AppPermissionsUtilService implements IUtilService { @@ -14,4 +15,12 @@ export class AppPermissionsUtilService implements IUtilService { async getUsersWithViewAccess(appId: string, organizationId: string, endUserIds: string[]): Promise { throw new Error('Method not implemented.'); } + + async createPagePermission(pageId: string, body: CreatePagePermissionDto): Promise { + throw new Error('Method not implemented.'); + } + + async updatePagePermission(pageId: string, body: CreatePagePermissionDto): Promise { + throw new Error('Method not implemented.'); + } }