mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 09:28:31 +00:00
rebase
This commit is contained in:
commit
c65e8ed9a9
4 changed files with 26 additions and 2 deletions
|
|
@ -3,6 +3,7 @@ import {
|
|||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
Index,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
|
|
@ -20,6 +21,7 @@ export class GroupPermissions extends BaseEntity {
|
|||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Index()
|
||||
@Column({ name: 'organization_id', nullable: false })
|
||||
organizationId: string;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import {
|
|||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
Index,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
|
|
@ -16,9 +17,11 @@ export class GroupUsers extends BaseEntity {
|
|||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Index()
|
||||
@Column({ name: 'user_id', nullable: false })
|
||||
userId: string;
|
||||
|
||||
@Index()
|
||||
@Column({ name: 'group_id', nullable: false })
|
||||
groupId: string;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, CreateDateColumn } from 'typeorm';
|
||||
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, CreateDateColumn, Index } from 'typeorm';
|
||||
import { User } from './user.entity';
|
||||
import { PagePermission } from './page_permissions.entity';
|
||||
import { GroupPermissions } from './group_permissions.entity';
|
||||
|
|
@ -8,12 +8,15 @@ export class PageUser {
|
|||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Index()
|
||||
@Column({ name: 'page_permissions_id', type: 'uuid' })
|
||||
pagePermissionsId: string;
|
||||
|
||||
@Index()
|
||||
@Column({ name: 'user_id', type: 'uuid', nullable: true })
|
||||
userId: string | null;
|
||||
|
||||
@Index()
|
||||
@Column({ name: 'permission_groups_id', type: 'uuid', nullable: true })
|
||||
permissionGroupsId: string | null;
|
||||
|
||||
|
|
|
|||
|
|
@ -13,10 +13,21 @@ export class PagePermissionsRepository extends Repository<PagePermission> {
|
|||
|
||||
async getPagePermissions(pageId: string, manager?: EntityManager): Promise<PagePermission[]> {
|
||||
return dbTransactionWrap(async (manager: EntityManager) => {
|
||||
return manager.find(PagePermission, {
|
||||
const pagePermissions = await manager.find(PagePermission, {
|
||||
where: { pageId },
|
||||
relations: ['users', 'users.user', 'users.permissionGroup'],
|
||||
});
|
||||
|
||||
return pagePermissions.map((permission) => {
|
||||
if (permission.type === PAGE_PERMISSION_TYPE.GROUP) {
|
||||
return {
|
||||
...permission,
|
||||
groups: permission.users,
|
||||
users: undefined,
|
||||
};
|
||||
}
|
||||
return permission;
|
||||
});
|
||||
}, manager || this.manager);
|
||||
}
|
||||
|
||||
|
|
@ -26,6 +37,11 @@ export class PagePermissionsRepository extends Repository<PagePermission> {
|
|||
manager?: EntityManager
|
||||
): Promise<PagePermission> {
|
||||
return dbTransactionWrap(async (manager: EntityManager) => {
|
||||
const existingPermission = await manager.findOne(PagePermission, { where: { pageId } });
|
||||
if (existingPermission) {
|
||||
throw new Error(`Page permission already exists for Page id: ${pageId}`);
|
||||
}
|
||||
|
||||
const pagePermission = manager.create(PagePermission, {
|
||||
pageId,
|
||||
type,
|
||||
|
|
|
|||
Loading…
Reference in a new issue