parent
1a9c860188
commit
d670b814a4
@ -27,7 +27,7 @@ export class CreateAuth {
|
|||||||
if (!this.password) {
|
if (!this.password) {
|
||||||
throw new PasswordNeededError();
|
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) {
|
if (!found_user) {
|
||||||
throw new UserNotFoundError();
|
throw new UserNotFoundError();
|
||||||
}
|
}
|
||||||
|
@ -101,22 +101,11 @@ export class CreateUser {
|
|||||||
if (!Array.isArray(this.group)) {
|
if (!Array.isArray(this.group)) {
|
||||||
this.group = [this.group]
|
this.group = [this.group]
|
||||||
}
|
}
|
||||||
const groupIDs: number[] = this.group
|
for (let group of this.group) {
|
||||||
let errors = 0
|
let found = await getConnectionManager().get().getRepository(UserGroup).findOne({ id: group });
|
||||||
const validateusergroups = async () => {
|
if (!found) { throw new UserGroupNotFoundError(); }
|
||||||
for (const g of groupIDs) {
|
groups.push(found);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
return groups;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,7 +3,6 @@ import { ChildEntity, Column, JoinTable, ManyToMany, OneToMany } from "typeorm";
|
|||||||
import { config } from '../../config';
|
import { config } from '../../config';
|
||||||
import { ResponsePrincipal } from '../responses/ResponsePrincipal';
|
import { ResponsePrincipal } from '../responses/ResponsePrincipal';
|
||||||
import { ResponseUser } from '../responses/ResponseUser';
|
import { ResponseUser } from '../responses/ResponseUser';
|
||||||
import { Permission } from './Permission';
|
|
||||||
import { Principal } from './Principal';
|
import { Principal } from './Principal';
|
||||||
import { UserAction } from './UserAction';
|
import { UserAction } from './UserAction';
|
||||||
import { UserGroup } from './UserGroup';
|
import { UserGroup } from './UserGroup';
|
||||||
@ -111,24 +110,6 @@ export class User extends Principal {
|
|||||||
@OneToMany(() => UserAction, action => action.user, { nullable: true })
|
@OneToMany(() => UserAction, action => action.user, { nullable: true })
|
||||||
actions: UserAction[]
|
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.
|
* Turn this into a response.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user