🚧 User + Permissions

This commit is contained in:
Philipp Dormann 2020-12-02 18:46:36 +01:00
parent e4d5afbebe
commit a78bbb1de5
3 changed files with 35 additions and 12 deletions

View File

@ -1,11 +1,12 @@
import { PrimaryGeneratedColumn, Column, OneToMany, Entity } from "typeorm"; import { PrimaryGeneratedColumn, Column, OneToMany, Entity, ManyToOne } from "typeorm";
import { import {
IsInt, IsInt,
IsNotEmpty, IsNotEmpty,
IsOptional, IsOptional,
IsString, IsString,
} from "class-validator"; } from "class-validator";
import { User } from './User';
import { UserGroup } from './UserGroup';
/** /**
* Defines the Permission interface. * Defines the Permission interface.
*/ */
@ -19,6 +20,18 @@ export abstract class Permission {
@IsInt() @IsInt()
id: number; id: number;
/**
* users
*/
@OneToMany(() => User, user => user.permissions)
users: User[]
/**
* groups
*/
@OneToMany(() => UserGroup, group => group.permissions)
groups: UserGroup[]
/** /**
* The target * The target
*/ */

View File

@ -67,9 +67,8 @@ export class User {
/** /**
* permissions * permissions
*/ */
// TODO: Permission implementation @ManyToOne(() => Permission, permission => permission.users)
// @OneToMany(() => Permission,userpermission=>) permissions: Permission[];
// permissions: Permission[];
/** /**
* groups * groups
@ -96,4 +95,15 @@ export class User {
*/ */
@IsString() @IsString()
profilepic: string; 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 []
}
} }

View File

@ -1,4 +1,4 @@
import { PrimaryGeneratedColumn, Column, OneToMany, Entity } from "typeorm"; import { PrimaryGeneratedColumn, Column, OneToMany, Entity, ManyToOne } from "typeorm";
import { import {
IsInt, IsInt,
IsNotEmpty, IsNotEmpty,
@ -20,6 +20,12 @@ export abstract class UserGroup {
@IsInt() @IsInt()
id: number; id: number;
/**
* permissions
*/
@ManyToOne(() => Permission, permission => permission.groups)
permissions: Permission[];
/** /**
* The group's name * The group's name
*/ */
@ -35,10 +41,4 @@ export abstract class UserGroup {
@IsOptional() @IsOptional()
@IsString() @IsString()
description: string; description: string;
/**
* TODO: Something about permission stuff
*/
// TODO:
// grouppermissions: Permission[];
} }