diff --git a/src/models/actions/CreateAuth.ts b/src/models/actions/CreateAuth.ts index a29f28a..2584aa2 100644 --- a/src/models/actions/CreateAuth.ts +++ b/src/models/actions/CreateAuth.ts @@ -27,7 +27,7 @@ export class CreateAuth { if (!this.password) { throw new PasswordNeededError(); } - const found_user = await getConnectionManager().get().getRepository(User).findOne({ relations: ['groups', 'permissions'], where: [{ username: this.username }, { email: this.email }] }); + const found_user = await getConnectionManager().get().getRepository(User).findOne({ relations: ['groups', 'permissions', 'groups.permissions'], where: [{ username: this.username }, { email: this.email }] }); if (!found_user) { throw new UserNotFoundError(); } diff --git a/src/models/actions/CreateUser.ts b/src/models/actions/CreateUser.ts index 7b7fb29..1f80ee3 100644 --- a/src/models/actions/CreateUser.ts +++ b/src/models/actions/CreateUser.ts @@ -101,22 +101,11 @@ export class CreateUser { if (!Array.isArray(this.group)) { this.group = [this.group] } - const groupIDs: number[] = this.group - let errors = 0 - const validateusergroups = async () => { - for (const g of groupIDs) { - const found = await getConnectionManager().get().getRepository(UserGroup).find({ id: g }); - if (found.length === 0) { - errors++ - } else { - groups.push(found[0]); - } - } - return groups; - } - await validateusergroups() - if (errors !== 0) { - throw new UserGroupNotFoundError(); + for (let group of this.group) { + let found = await getConnectionManager().get().getRepository(UserGroup).findOne({ id: group }); + if (!found) { throw new UserGroupNotFoundError(); } + groups.push(found); } + return groups; } } \ No newline at end of file diff --git a/src/models/entities/User.ts b/src/models/entities/User.ts index 27e14ba..21970c4 100644 --- a/src/models/entities/User.ts +++ b/src/models/entities/User.ts @@ -3,7 +3,6 @@ import { ChildEntity, Column, JoinTable, ManyToMany, OneToMany } from "typeorm"; import { config } from '../../config'; import { ResponsePrincipal } from '../responses/ResponsePrincipal'; import { ResponseUser } from '../responses/ResponseUser'; -import { Permission } from './Permission'; import { Principal } from './Principal'; import { UserAction } from './UserAction'; import { UserGroup } from './UserGroup'; @@ -111,24 +110,6 @@ export class User extends Principal { @OneToMany(() => UserAction, action => action.user, { nullable: true }) actions: UserAction[] - /** - * calculate all permissions - */ - public get calc_permissions(): Permission[] { - let final_permissions = [] - this.groups.forEach((permission) => { - if (!final_permissions.includes(permission)) { - final_permissions.push(permission) - } - }) - this.permissions.forEach((permission) => { - if (!final_permissions.includes(permission)) { - final_permissions.push(permission) - } - }) - return final_permissions - } - /** * Turn this into a response. */