In this PR - introducing roles module to separate roles logic (assign a Role, get a workspace's roles etc.) from permission logic (check if a user has a permission) - Introduces getRoles endpoint to fetch a workspace's roles - introduces the first permission check: getRoles in only accessible to users with permission on ROLE setting. Implemented validatesUserHasWorkspaceSettingPermissionOrThrow
42 lines
929 B
TypeScript
42 lines
929 B
TypeScript
import {
|
|
Column,
|
|
CreateDateColumn,
|
|
Entity,
|
|
JoinColumn,
|
|
ManyToOne,
|
|
PrimaryGeneratedColumn,
|
|
Relation,
|
|
Unique,
|
|
UpdateDateColumn,
|
|
} from 'typeorm';
|
|
|
|
import { RoleEntity } from 'src/engine/metadata-modules/role/role.entity';
|
|
|
|
@Entity('userWorkspaceRole')
|
|
@Unique('IndexOnUserWorkspaceRoleUnique', ['userWorkspaceId', 'roleId'])
|
|
export class UserWorkspaceRoleEntity {
|
|
@PrimaryGeneratedColumn('uuid')
|
|
id: string;
|
|
|
|
@Column({ nullable: false, type: 'uuid' })
|
|
workspaceId: string;
|
|
|
|
@Column({ nullable: false, type: 'uuid' })
|
|
roleId: string;
|
|
|
|
@ManyToOne(() => RoleEntity, (role) => role.userWorkspaceRoles, {
|
|
onDelete: 'CASCADE',
|
|
})
|
|
@JoinColumn({ name: 'roleId' })
|
|
role: Relation<RoleEntity>;
|
|
|
|
@Column({ nullable: false, type: 'uuid' })
|
|
userWorkspaceId: string;
|
|
|
|
@CreateDateColumn({ type: 'timestamptz' })
|
|
createdAt: Date;
|
|
|
|
@UpdateDateColumn({ type: 'timestamptz' })
|
|
updatedAt: Date;
|
|
}
|