mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-23 08:58:26 +00:00
Created base for APIs related to page permission endpoints and DTO
This commit is contained in:
parent
87fa9e71a1
commit
6923d7ef15
12 changed files with 154 additions and 8 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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]: {},
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<any> {
|
||||
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<any> {
|
||||
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<any> {
|
||||
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<any> {
|
||||
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<any> {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
26
server/src/modules/app-permissions/dto/index.ts
Normal file
26
server/src/modules/app-permissions/dto/index.ts
Normal file
|
|
@ -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[];
|
||||
}
|
||||
|
|
@ -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<any>;
|
||||
|
||||
fetchUserGroups(user: User, appId: string, response: Response): Promise<any>;
|
||||
|
||||
fetchPagePermissions(user: User, appId: string, pageId: string, response: Response): Promise<any>;
|
||||
|
||||
createPagePermissions(
|
||||
user: User,
|
||||
appId: string,
|
||||
pageId: string,
|
||||
body: CreatePagePermissionDto,
|
||||
response: Response
|
||||
): Promise<any>;
|
||||
|
||||
updatePagePermissions(
|
||||
user: User,
|
||||
appId: string,
|
||||
pageId: string,
|
||||
body: CreatePagePermissionDto,
|
||||
response: Response
|
||||
): Promise<any>;
|
||||
|
||||
deletePagePermissions(user: User, appId: string, pageId: string, response: Response): Promise<any>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,16 @@
|
|||
import { User } from '@entities/user.entity';
|
||||
import { CreatePagePermissionDto } from '../dto';
|
||||
|
||||
export interface IAppPermissionsService {
|
||||
fetchUsers(appId: string, user: User): Promise<any>;
|
||||
|
||||
fetchUserGroups(appId: string, user: User): Promise<any>;
|
||||
|
||||
fetchPagePermissions(pageId: string): Promise<any>;
|
||||
|
||||
createPagePermissions(pageId: string, body: CreatePagePermissionDto): Promise<any>;
|
||||
|
||||
updatePagePermissions(appId: string, pageId: string, body: CreatePagePermissionDto, user: User): Promise<any>;
|
||||
|
||||
deletePagePermissions(pageId: string): Promise<any>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<User[]>;
|
||||
|
||||
getUserGroupsWithViewAccess(appId: string, organizationId: string): Promise<GroupPermissions[]>;
|
||||
|
||||
createPagePermission(pageId: string, body: CreatePagePermissionDto): Promise<any>;
|
||||
|
||||
updatePagePermission(pageId: string, body: CreatePagePermissionDto): Promise<any>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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<User[]> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
async createPagePermission(pageId: string, body: CreatePagePermissionDto): Promise<any> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
async updatePagePermission(pageId: string, body: CreatePagePermissionDto): Promise<any> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue