Merge branch 'dev' into feature/105-addresses
# Conflicts: # src/errors/AddressErrors.ts # src/models/actions/create/CreateAddress.ts # src/models/actions/create/CreateDonor.ts # src/models/actions/create/CreateGroupContact.ts # src/models/actions/create/CreateParticipant.ts # src/models/actions/create/CreateRunner.ts # src/models/actions/create/CreateRunnerOrganisation.ts # src/models/actions/update/UpdateDonor.ts # src/models/actions/update/UpdateRunner.ts # src/models/actions/update/UpdateRunnerOrganisation.ts # src/models/entities/Address.ts # src/models/entities/IAddressUser.ts # src/models/entities/RunnerOrganisation.ts # src/models/responses/ResponseParticipant.ts # src/tests/donors/donor_add.spec.ts # src/tests/donors/donor_update.spec.ts # src/tests/runnerOrgs/org_add.spec.ts # src/tests/runnerOrgs/org_delete.spec.ts # src/tests/runnerOrgs/org_update.spec.ts # src/tests/runnerTeams/team_update.spec.ts # src/tests/runners/runner_update.spec.ts
This commit is contained in:
@@ -138,8 +138,10 @@ export class User extends Principal {
|
||||
|
||||
if (!this.groups) { return returnPermissions; }
|
||||
for (let group of this.groups) {
|
||||
for (let permission of group.permissions) {
|
||||
returnPermissions.push(permission);
|
||||
if (group.permissions) {
|
||||
for (let permission of group.permissions) {
|
||||
returnPermissions.push(permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnPermissions;
|
||||
@@ -159,8 +161,10 @@ export class User extends Principal {
|
||||
|
||||
if (!this.groups) { return returnPermissions; }
|
||||
for (let group of this.groups) {
|
||||
for (let permission of group.permissions) {
|
||||
returnPermissions.push(permission.toString());
|
||||
if (group.permissions) {
|
||||
for (let permission of group.permissions) {
|
||||
returnPermissions.push(permission.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return Array.from(new Set(returnPermissions));
|
||||
|
||||
@@ -1,39 +1,40 @@
|
||||
import {
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsString
|
||||
} from "class-validator";
|
||||
import { ChildEntity, Column } from "typeorm";
|
||||
import { ResponseUserGroup } from '../responses/ResponseUserGroup';
|
||||
import { Principal } from './Principal';
|
||||
|
||||
/**
|
||||
* Defines the UserGroup entity.
|
||||
* This entity describes a group of users with a set of permissions.
|
||||
*/
|
||||
@ChildEntity()
|
||||
export class UserGroup extends Principal {
|
||||
|
||||
/**
|
||||
* The group's name
|
||||
*/
|
||||
@Column()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* The group's description
|
||||
*/
|
||||
@Column({ nullable: true })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string;
|
||||
|
||||
/**
|
||||
* Turns this entity into it's response class.
|
||||
*/
|
||||
public toResponse(): ResponseUserGroup {
|
||||
return new ResponseUserGroup(this);
|
||||
}
|
||||
import {
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsString
|
||||
} from "class-validator";
|
||||
import { ChildEntity, Column } from "typeorm";
|
||||
import { ResponsePrincipal } from '../responses/ResponsePrincipal';
|
||||
import { ResponseUserGroup } from '../responses/ResponseUserGroup';
|
||||
import { Principal } from './Principal';
|
||||
|
||||
/**
|
||||
* Defines the UserGroup entity.
|
||||
* This entity describes a group of users with a set of permissions.
|
||||
*/
|
||||
@ChildEntity()
|
||||
export class UserGroup extends Principal {
|
||||
|
||||
/**
|
||||
* The group's name
|
||||
*/
|
||||
@Column()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* The group's description
|
||||
*/
|
||||
@Column({ nullable: true })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string;
|
||||
|
||||
/**
|
||||
* Turns this entity into it's response class.
|
||||
*/
|
||||
public toResponse(): ResponsePrincipal {
|
||||
return new ResponseUserGroup(this);
|
||||
}
|
||||
}
|
||||
@@ -1,101 +1,99 @@
|
||||
import {
|
||||
IsArray,
|
||||
IsBoolean,
|
||||
|
||||
IsOptional,
|
||||
IsString
|
||||
} from "class-validator";
|
||||
import { User } from '../entities/User';
|
||||
import { ResponsePrincipal } from './ResponsePrincipal';
|
||||
import { ResponseUserGroup } from './ResponseUserGroup';
|
||||
|
||||
/**
|
||||
* Defines the user response.
|
||||
*/
|
||||
export class ResponseUser extends ResponsePrincipal {
|
||||
/**
|
||||
* The user's first name.
|
||||
*/
|
||||
@IsString()
|
||||
firstname: string;
|
||||
|
||||
/**
|
||||
* The user's middle name.
|
||||
*/
|
||||
@IsString()
|
||||
middlename?: string;
|
||||
|
||||
/**
|
||||
* The user's last name.
|
||||
*/
|
||||
@IsString()
|
||||
lastname: string;
|
||||
|
||||
/**
|
||||
* The user's phone number.
|
||||
*/
|
||||
@IsString()
|
||||
phone?: string;
|
||||
|
||||
/**
|
||||
* The user's e-mail address.
|
||||
*/
|
||||
@IsString()
|
||||
email?: string;
|
||||
|
||||
/**
|
||||
* The user's username.
|
||||
*/
|
||||
@IsString()
|
||||
username?: string;
|
||||
|
||||
/**
|
||||
* Is user enabled?
|
||||
*/
|
||||
@IsBoolean()
|
||||
enabled: boolean = true;
|
||||
|
||||
/**
|
||||
* The user's profile pic (or rather a url pointing to it).
|
||||
*/
|
||||
@IsString()
|
||||
profilePic: string;
|
||||
|
||||
/**
|
||||
* The groups that the user is a part of.
|
||||
*/
|
||||
@IsArray()
|
||||
@IsOptional()
|
||||
groups: ResponseUserGroup[];
|
||||
|
||||
/**
|
||||
* The user's permissions.
|
||||
* Directly granted or inherited converted to their string form and deduplicated.
|
||||
*/
|
||||
@IsArray()
|
||||
@IsOptional()
|
||||
permissions: string[];
|
||||
|
||||
/**
|
||||
* Creates a ResponseUser object from a user.
|
||||
* @param user The user the response shall be build for.
|
||||
*/
|
||||
public constructor(user: User) {
|
||||
super(user);
|
||||
this.firstname = user.firstname;
|
||||
this.middlename = user.middlename;
|
||||
this.lastname = user.lastname;
|
||||
this.phone = user.phone;
|
||||
this.email = user.email;
|
||||
this.username = user.username;
|
||||
this.enabled = user.enabled;
|
||||
this.profilePic = user.profilePic;
|
||||
if (user.groups) {
|
||||
for (let group of user.groups) {
|
||||
this.groups.push(group.toResponse());
|
||||
}
|
||||
}
|
||||
this.permissions = user.allPermissions;
|
||||
this.groups.forEach(function (g) { delete g.permissions });
|
||||
}
|
||||
}
|
||||
import {
|
||||
IsArray,
|
||||
IsBoolean,
|
||||
|
||||
IsOptional,
|
||||
IsString
|
||||
} from "class-validator";
|
||||
import { User } from '../entities/User';
|
||||
import { UserGroup } from '../entities/UserGroup';
|
||||
import { ResponsePrincipal } from './ResponsePrincipal';
|
||||
|
||||
/**
|
||||
* Defines the user response.
|
||||
*/
|
||||
export class ResponseUser extends ResponsePrincipal {
|
||||
/**
|
||||
* The user's first name.
|
||||
*/
|
||||
@IsString()
|
||||
firstname: string;
|
||||
|
||||
/**
|
||||
* The user's middle name.
|
||||
*/
|
||||
@IsString()
|
||||
middlename?: string;
|
||||
|
||||
/**
|
||||
* The user's last name.
|
||||
*/
|
||||
@IsString()
|
||||
lastname: string;
|
||||
|
||||
/**
|
||||
* The user's phone number.
|
||||
*/
|
||||
@IsString()
|
||||
phone?: string;
|
||||
|
||||
/**
|
||||
* The user's e-mail address.
|
||||
*/
|
||||
@IsString()
|
||||
email?: string;
|
||||
|
||||
/**
|
||||
* The user's username.
|
||||
*/
|
||||
@IsString()
|
||||
username?: string;
|
||||
|
||||
/**
|
||||
* Is user enabled?
|
||||
*/
|
||||
@IsBoolean()
|
||||
enabled: boolean = true;
|
||||
|
||||
/**
|
||||
* The user's profile pic (or rather a url pointing to it).
|
||||
*/
|
||||
@IsString()
|
||||
profilePic: string;
|
||||
|
||||
/**
|
||||
* The groups that the user is a part of.
|
||||
*/
|
||||
@IsArray()
|
||||
@IsOptional()
|
||||
groups: UserGroup[];
|
||||
|
||||
/**
|
||||
* The user's permissions.
|
||||
* Directly granted or inherited converted to their string form and deduplicated.
|
||||
*/
|
||||
@IsArray()
|
||||
@IsOptional()
|
||||
permissions: string[];
|
||||
|
||||
/**
|
||||
* Creates a ResponseUser object from a user.
|
||||
* @param user The user the response shall be build for.
|
||||
*/
|
||||
public constructor(user: User) {
|
||||
super(user);
|
||||
this.firstname = user.firstname;
|
||||
this.middlename = user.middlename;
|
||||
this.lastname = user.lastname;
|
||||
this.phone = user.phone;
|
||||
this.email = user.email;
|
||||
this.username = user.username;
|
||||
this.enabled = user.enabled;
|
||||
this.profilePic = user.profilePic;
|
||||
this.groups = user.groups;
|
||||
this.permissions = user.allPermissions;
|
||||
if (this.groups) {
|
||||
this.groups.forEach(function (g) { delete g.permissions });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +1,41 @@
|
||||
import { IsArray, IsNotEmpty, IsOptional, IsString } from "class-validator";
|
||||
import { UserGroup } from '../entities/UserGroup';
|
||||
import { ResponsePermission } from './ResponsePermission';
|
||||
import { ResponsePrincipal } from './ResponsePrincipal';
|
||||
|
||||
/**
|
||||
* Defines the userGroup response.
|
||||
*/
|
||||
export class ResponseUserGroup extends ResponsePrincipal {
|
||||
/**
|
||||
* The userGroup's name.
|
||||
*/
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* The userGroup's description.
|
||||
*/
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string;
|
||||
|
||||
/**
|
||||
* The userGroup's permissions.
|
||||
*/
|
||||
@IsArray()
|
||||
@IsOptional()
|
||||
permissions: ResponsePermission[];
|
||||
|
||||
/**
|
||||
* Creates a ResponseUserGroup object from a userGroup.
|
||||
* @param group The userGroup the response shall be build for.
|
||||
*/
|
||||
public constructor(group: UserGroup) {
|
||||
super(group);
|
||||
this.name = group.name;
|
||||
this.description = group.description;
|
||||
if (group.permissions) {
|
||||
for (let permission of group.permissions) {
|
||||
this.permissions.push(permission.toResponse());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
import { IsArray, IsNotEmpty, IsOptional, IsString } from "class-validator";
|
||||
import { Permission } from '../entities/Permission';
|
||||
import { UserGroup } from '../entities/UserGroup';
|
||||
import { ResponsePrincipal } from './ResponsePrincipal';
|
||||
|
||||
/**
|
||||
* Defines the userGroup response.
|
||||
*/
|
||||
export class ResponseUserGroup extends ResponsePrincipal {
|
||||
/**
|
||||
* The userGroup's name.
|
||||
*/
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* The userGroup's description.
|
||||
*/
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string;
|
||||
|
||||
/**
|
||||
* The userGroup's permissions.
|
||||
*/
|
||||
@IsArray()
|
||||
@IsOptional()
|
||||
permissions: Permission[];
|
||||
|
||||
/**
|
||||
* Creates a ResponseUserGroup object from a userGroup.
|
||||
* @param group The userGroup the response shall be build for.
|
||||
*/
|
||||
public constructor(group: UserGroup) {
|
||||
super(group);
|
||||
this.name = group.name;
|
||||
this.description = group.description;
|
||||
this.permissions = group.permissions;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user