🚧 User + Permissions
This commit is contained in:
parent
e4d5afbebe
commit
a78bbb1de5
|
@ -1,11 +1,12 @@
|
|||
import { PrimaryGeneratedColumn, Column, OneToMany, Entity } from "typeorm";
|
||||
import { PrimaryGeneratedColumn, Column, OneToMany, Entity, ManyToOne } from "typeorm";
|
||||
import {
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsString,
|
||||
} from "class-validator";
|
||||
|
||||
import { User } from './User';
|
||||
import { UserGroup } from './UserGroup';
|
||||
/**
|
||||
* Defines the Permission interface.
|
||||
*/
|
||||
|
@ -19,6 +20,18 @@ export abstract class Permission {
|
|||
@IsInt()
|
||||
id: number;
|
||||
|
||||
/**
|
||||
* users
|
||||
*/
|
||||
@OneToMany(() => User, user => user.permissions)
|
||||
users: User[]
|
||||
|
||||
/**
|
||||
* groups
|
||||
*/
|
||||
@OneToMany(() => UserGroup, group => group.permissions)
|
||||
groups: UserGroup[]
|
||||
|
||||
/**
|
||||
* The target
|
||||
*/
|
||||
|
|
|
@ -67,9 +67,8 @@ export class User {
|
|||
/**
|
||||
* permissions
|
||||
*/
|
||||
// TODO: Permission implementation
|
||||
// @OneToMany(() => Permission,userpermission=>)
|
||||
// permissions: Permission[];
|
||||
@ManyToOne(() => Permission, permission => permission.users)
|
||||
permissions: Permission[];
|
||||
|
||||
/**
|
||||
* groups
|
||||
|
@ -96,4 +95,15 @@ export class User {
|
|||
*/
|
||||
@IsString()
|
||||
profilepic: string;
|
||||
|
||||
/**
|
||||
* calculate all permissions
|
||||
*/
|
||||
public get calc_permissions(): Permission[] {
|
||||
let final_permissions = this.groups.forEach((permission) => {
|
||||
console.log(permission);
|
||||
})
|
||||
// TODO: add user permissions on top of group permissions + return
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { PrimaryGeneratedColumn, Column, OneToMany, Entity } from "typeorm";
|
||||
import { PrimaryGeneratedColumn, Column, OneToMany, Entity, ManyToOne } from "typeorm";
|
||||
import {
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
|
@ -20,6 +20,12 @@ export abstract class UserGroup {
|
|||
@IsInt()
|
||||
id: number;
|
||||
|
||||
/**
|
||||
* permissions
|
||||
*/
|
||||
@ManyToOne(() => Permission, permission => permission.groups)
|
||||
permissions: Permission[];
|
||||
|
||||
/**
|
||||
* The group's name
|
||||
*/
|
||||
|
@ -35,10 +41,4 @@ export abstract class UserGroup {
|
|||
@IsOptional()
|
||||
@IsString()
|
||||
description: string;
|
||||
|
||||
/**
|
||||
* TODO: Something about permission stuff
|
||||
*/
|
||||
// TODO:
|
||||
// grouppermissions: Permission[];
|
||||
}
|
Loading…
Reference in New Issue