🚧 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 {
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
*/

View File

@ -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 []
}
}

View File

@ -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[];
}