@@ -1,12 +1,11 @@
 | 
				
			|||||||
import {
 | 
					import {
 | 
				
			||||||
  IsInt,
 | 
					  IsInt,
 | 
				
			||||||
  IsNotEmpty,
 | 
					  IsNotEmpty
 | 
				
			||||||
 | 
					 | 
				
			||||||
  IsString
 | 
					 | 
				
			||||||
} from "class-validator";
 | 
					} from "class-validator";
 | 
				
			||||||
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
 | 
					import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
 | 
				
			||||||
import { User } from './User';
 | 
					import { PermissionAction } from '../enums/PermissionAction';
 | 
				
			||||||
import { UserGroup } from './UserGroup';
 | 
					import { PermissionTarget } from '../enums/PermissionTargets';
 | 
				
			||||||
 | 
					import { Principal } from './Principal';
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Defines the Permission interface.
 | 
					 * Defines the Permission interface.
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
@@ -20,30 +19,27 @@ export abstract class Permission {
 | 
				
			|||||||
  id: number;
 | 
					  id: number;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * users
 | 
					   * The permissions principal
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  @OneToMany(() => User, user => user.permissions, { nullable: true })
 | 
					  @ManyToOne(() => Principal, principal => principal.permissions)
 | 
				
			||||||
  users: User[]
 | 
					  principal: Principal[]
 | 
				
			||||||
 | 
					 | 
				
			||||||
  /**
 | 
					 | 
				
			||||||
   * groups
 | 
					 | 
				
			||||||
   */
 | 
					 | 
				
			||||||
  @OneToMany(() => UserGroup, group => group.permissions, { nullable: true })
 | 
					 | 
				
			||||||
  groups: UserGroup[]
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * The target
 | 
					   * The target
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  @Column()
 | 
					  @Column({
 | 
				
			||||||
 | 
					    type: 'simple-enum',
 | 
				
			||||||
 | 
					    enum: PermissionTarget
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
  @IsNotEmpty()
 | 
					  @IsNotEmpty()
 | 
				
			||||||
  @IsString()
 | 
					  target: PermissionTarget;
 | 
				
			||||||
  target: string;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * The action type
 | 
					   * The action type
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  @Column()
 | 
					  @Column({
 | 
				
			||||||
  @IsNotEmpty()
 | 
					    type: 'simple-enum',
 | 
				
			||||||
  @IsString()
 | 
					    enum: PermissionAction
 | 
				
			||||||
  action: string;
 | 
					  })
 | 
				
			||||||
 | 
					  action: PermissionAction;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										24
									
								
								src/models/entities/Principal.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/models/entities/Principal.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
				
			|||||||
 | 
					import { IsInt, IsOptional } from 'class-validator';
 | 
				
			||||||
 | 
					import { Entity, OneToMany, PrimaryGeneratedColumn, TableInheritance } from 'typeorm';
 | 
				
			||||||
 | 
					import { Permission } from './Permission';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Defines a admin user.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					@Entity()
 | 
				
			||||||
 | 
					@TableInheritance({ column: { name: "type", type: "varchar" } })
 | 
				
			||||||
 | 
					export abstract class Principal {
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					  * autogenerated unique id (primary key).
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					  @PrimaryGeneratedColumn()
 | 
				
			||||||
 | 
					  @IsInt()
 | 
				
			||||||
 | 
					  id: number;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					* permissions
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					  @IsOptional()
 | 
				
			||||||
 | 
					  @OneToMany(() => Permission, permission => permission.principal, { nullable: true })
 | 
				
			||||||
 | 
					  permissions?: Permission[];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,22 +1,16 @@
 | 
				
			|||||||
import { IsBoolean, IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString, IsUUID } from "class-validator";
 | 
					import { IsBoolean, IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString, IsUUID } from "class-validator";
 | 
				
			||||||
import { Column, Entity, JoinTable, ManyToMany, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
 | 
					import { ChildEntity, Column, JoinTable, ManyToMany, OneToMany } from "typeorm";
 | 
				
			||||||
import { config } from '../../config';
 | 
					import { config } from '../../config';
 | 
				
			||||||
import { Permission } from './Permission';
 | 
					import { Permission } from './Permission';
 | 
				
			||||||
 | 
					import { Principal } from './Principal';
 | 
				
			||||||
import { UserAction } from './UserAction';
 | 
					import { UserAction } from './UserAction';
 | 
				
			||||||
import { UserGroup } from './UserGroup';
 | 
					import { UserGroup } from './UserGroup';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Defines a admin user.
 | 
					 * Defines a admin user.
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
@Entity()
 | 
					@ChildEntity()
 | 
				
			||||||
export class User {
 | 
					export class User extends Principal {
 | 
				
			||||||
  /**
 | 
					 | 
				
			||||||
  * autogenerated unique id (primary key).
 | 
					 | 
				
			||||||
  */
 | 
					 | 
				
			||||||
  @PrimaryGeneratedColumn()
 | 
					 | 
				
			||||||
  @IsInt()
 | 
					 | 
				
			||||||
  id: number;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
  * uuid
 | 
					  * uuid
 | 
				
			||||||
  */
 | 
					  */
 | 
				
			||||||
@@ -78,13 +72,6 @@ export class User {
 | 
				
			|||||||
  @IsNotEmpty()
 | 
					  @IsNotEmpty()
 | 
				
			||||||
  password: string;
 | 
					  password: string;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					 | 
				
			||||||
  * permissions
 | 
					 | 
				
			||||||
  */
 | 
					 | 
				
			||||||
  @IsOptional()
 | 
					 | 
				
			||||||
  @ManyToOne(() => Permission, permission => permission.users, { nullable: true })
 | 
					 | 
				
			||||||
  permissions?: Permission[];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
  * groups
 | 
					  * groups
 | 
				
			||||||
  */
 | 
					  */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,29 +1,16 @@
 | 
				
			|||||||
import {
 | 
					import {
 | 
				
			||||||
  IsInt,
 | 
					 | 
				
			||||||
  IsNotEmpty,
 | 
					  IsNotEmpty,
 | 
				
			||||||
  IsOptional,
 | 
					  IsOptional,
 | 
				
			||||||
  IsString
 | 
					  IsString
 | 
				
			||||||
} from "class-validator";
 | 
					} from "class-validator";
 | 
				
			||||||
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
 | 
					import { ChildEntity, Column } from "typeorm";
 | 
				
			||||||
import { Permission } from "./Permission";
 | 
					import { Principal } from './Principal';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Defines the UserGroup interface.
 | 
					 * Defines the UserGroup interface.
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
@Entity()
 | 
					@ChildEntity()
 | 
				
			||||||
export class UserGroup {
 | 
					export class UserGroup extends Principal {
 | 
				
			||||||
  /**
 | 
					 | 
				
			||||||
   * Autogenerated unique id (primary key).
 | 
					 | 
				
			||||||
   */
 | 
					 | 
				
			||||||
  @PrimaryGeneratedColumn()
 | 
					 | 
				
			||||||
  @IsInt()
 | 
					 | 
				
			||||||
  id: number;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /**
 | 
					 | 
				
			||||||
     * permissions
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
  @ManyToOne(() => Permission, permission => permission.groups, { nullable: true })
 | 
					 | 
				
			||||||
  permissions: Permission[];
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * The group's name
 | 
					   * The group's name
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										6
									
								
								src/models/enums/PermissionAction.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src/models/enums/PermissionAction.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					export enum PermissionAction {
 | 
				
			||||||
 | 
					    READ = 'READ',
 | 
				
			||||||
 | 
					    ADD = 'ADD',
 | 
				
			||||||
 | 
					    UPDATE = 'UPDATE',
 | 
				
			||||||
 | 
					    DELETE = 'DELETE'
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										8
									
								
								src/models/enums/PermissionTargets.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/models/enums/PermissionTargets.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					export enum PermissionTarget {
 | 
				
			||||||
 | 
					    RUNNER = 'RUNNER',
 | 
				
			||||||
 | 
					    ORGANISATION = 'RUNNERORGANISATION',
 | 
				
			||||||
 | 
					    TEAM = 'RUNNERTEAM',
 | 
				
			||||||
 | 
					    TRACK = 'TRACK',
 | 
				
			||||||
 | 
					    USER = 'USER',
 | 
				
			||||||
 | 
					    GROUP = 'USERGROUP'
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user