Compare commits
16 Commits
9cc50078d1
...
v0.0.9
| Author | SHA1 | Date | |
|---|---|---|---|
| c66b06c2c9 | |||
| 65e605cdc4 | |||
| d2fdb4efd9 | |||
| d0deb9d647 | |||
| 5495c90eaf | |||
| bf3ffae67c | |||
| aa0337ea33 | |||
| 4991d735bf | |||
| 398e61bddb | |||
| e6576f4a54 | |||
| c3b9e135b0 | |||
| 3bd4948c43 | |||
| f3cd1380be | |||
| a2c3dfbf85 | |||
| 3c37aafe1f | |||
| c591c182b3 |
@@ -11,7 +11,7 @@ steps:
|
|||||||
- git checkout $DRONE_SOURCE_BRANCH
|
- git checkout $DRONE_SOURCE_BRANCH
|
||||||
- mv .env.ci .env
|
- mv .env.ci .env
|
||||||
- name: run tests
|
- name: run tests
|
||||||
image: node:alpine
|
image: node:14.15.1-alpine3.12
|
||||||
commands:
|
commands:
|
||||||
- yarn
|
- yarn
|
||||||
- yarn test:ci
|
- yarn test:ci
|
||||||
@@ -39,7 +39,7 @@ steps:
|
|||||||
registry: registry.odit.services
|
registry: registry.odit.services
|
||||||
- name: run full license export
|
- name: run full license export
|
||||||
depends_on: ["clone"]
|
depends_on: ["clone"]
|
||||||
image: node:alpine
|
image: node:14.15.1-alpine3.12
|
||||||
commands:
|
commands:
|
||||||
- yarn
|
- yarn
|
||||||
- yarn licenses:export
|
- yarn licenses:export
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@odit/lfk-backend",
|
"name": "@odit/lfk-backend",
|
||||||
"version": "0.0.8",
|
"version": "0.0.9",
|
||||||
"main": "src/app.ts",
|
"main": "src/app.ts",
|
||||||
"repository": "https://git.odit.services/lfk/backend",
|
"repository": "https://git.odit.services/lfk/backend",
|
||||||
"author": {
|
"author": {
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"routing-controllers": "^0.9.0-alpha.6",
|
"routing-controllers": "^0.9.0-alpha.6",
|
||||||
"routing-controllers-openapi": "^2.1.0",
|
"routing-controllers-openapi": "^2.1.0",
|
||||||
"sqlite3": "^5.0.0",
|
"sqlite3": "5.0.0",
|
||||||
"typeorm": "^0.2.29",
|
"typeorm": "^0.2.29",
|
||||||
"typeorm-routing-controllers-extensions": "^0.2.0",
|
"typeorm-routing-controllers-extensions": "^0.2.0",
|
||||||
"typeorm-seeding": "^1.6.1",
|
"typeorm-seeding": "^1.6.1",
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export class UserController {
|
|||||||
@OpenAPI({ description: 'Lists all users. <br> This includes their groups and permissions directly granted to them (if existing/associated).' })
|
@OpenAPI({ description: 'Lists all users. <br> This includes their groups and permissions directly granted to them (if existing/associated).' })
|
||||||
async getAll() {
|
async getAll() {
|
||||||
let responseUsers: ResponseUser[] = new Array<ResponseUser>();
|
let responseUsers: ResponseUser[] = new Array<ResponseUser>();
|
||||||
const users = await this.userRepository.find({ relations: ['permissions', 'groups'] });
|
const users = await this.userRepository.find({ relations: ['permissions', 'groups', 'groups.permissions'] });
|
||||||
users.forEach(user => {
|
users.forEach(user => {
|
||||||
responseUsers.push(new ResponseUser(user));
|
responseUsers.push(new ResponseUser(user));
|
||||||
});
|
});
|
||||||
@@ -43,7 +43,7 @@ export class UserController {
|
|||||||
@OnUndefined(UserNotFoundError)
|
@OnUndefined(UserNotFoundError)
|
||||||
@OpenAPI({ description: 'Lists all information about the user whose id got provided. <br> Please remember that only permissions granted directly to the user will show up here, not permissions inherited from groups.' })
|
@OpenAPI({ description: 'Lists all information about the user whose id got provided. <br> Please remember that only permissions granted directly to the user will show up here, not permissions inherited from groups.' })
|
||||||
async getOne(@Param('id') id: number) {
|
async getOne(@Param('id') id: number) {
|
||||||
let user = await this.userRepository.findOne({ id: id }, { relations: ['permissions', 'groups'] })
|
let user = await this.userRepository.findOne({ id: id }, { relations: ['permissions', 'groups', 'groups.permissions'] })
|
||||||
if (!user) { throw new UserNotFoundError(); }
|
if (!user) { throw new UserNotFoundError(); }
|
||||||
return new ResponseUser(user);
|
return new ResponseUser(user);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,23 +106,6 @@ export class JwtUser {
|
|||||||
this.refreshTokenCount = user.refreshTokenCount;
|
this.refreshTokenCount = user.refreshTokenCount;
|
||||||
this.uuid = user.uuid;
|
this.uuid = user.uuid;
|
||||||
this.profilePic = user.profilePic;
|
this.profilePic = user.profilePic;
|
||||||
this.permissions = this.getPermissions(user);
|
this.permissions = user.allPermissions;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handels getting the permissions granted to this user (direct or indirect).
|
|
||||||
* @param user User which's permissions shall be gotten.
|
|
||||||
*/
|
|
||||||
public getPermissions(user: User): string[] {
|
|
||||||
let returnPermissions: string[] = new Array<string>();
|
|
||||||
for (let permission of user.permissions) {
|
|
||||||
returnPermissions.push(permission.toString());
|
|
||||||
}
|
|
||||||
for (let group of user.groups) {
|
|
||||||
for (let permission of group.permissions) {
|
|
||||||
returnPermissions.push(permission.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Array.from(new Set(returnPermissions));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@ import { Runner } from '../entities/Runner';
|
|||||||
import { Scan } from '../entities/Scan';
|
import { Scan } from '../entities/Scan';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This classed is used to create a new Scan entity from a json body (post request).
|
* This class is used to create a new Scan entity from a json body (post request).
|
||||||
*/
|
*/
|
||||||
export abstract class CreateScan {
|
export abstract class CreateScan {
|
||||||
/**
|
/**
|
||||||
@@ -46,6 +46,9 @@ export abstract class CreateScan {
|
|||||||
return newScan;
|
return newScan;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a runner based on the runner id provided via this.runner.
|
||||||
|
*/
|
||||||
public async getRunner(): Promise<Runner> {
|
public async getRunner(): Promise<Runner> {
|
||||||
const runner = await getConnection().getRepository(Runner).findOne({ id: this.runner });
|
const runner = await getConnection().getRepository(Runner).findOne({ id: this.runner });
|
||||||
if (!runner) {
|
if (!runner) {
|
||||||
|
|||||||
@@ -8,19 +8,18 @@ import { ScanStation } from '../entities/ScanStation';
|
|||||||
import { Track } from '../entities/Track';
|
import { Track } from '../entities/Track';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This classed is used to create a new StatsClient entity from a json body (post request).
|
* This class is used to create a new StatsClient entity from a json body (post request).
|
||||||
*/
|
*/
|
||||||
export class CreateScanStation {
|
export class CreateScanStation {
|
||||||
/**
|
/**
|
||||||
* The new client's description.
|
* The new station's description.
|
||||||
*/
|
*/
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
description?: string;
|
description?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The scan's associated track.
|
* The station's associated track.
|
||||||
* This is used to determine the scan's distance.
|
|
||||||
*/
|
*/
|
||||||
@IsInt()
|
@IsInt()
|
||||||
@IsPositive()
|
@IsPositive()
|
||||||
@@ -51,6 +50,10 @@ export class CreateScanStation {
|
|||||||
return newStation;
|
return newStation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get's a track by it's id provided via this.track.
|
||||||
|
* Used to link the new station to a track.
|
||||||
|
*/
|
||||||
public async getTrack(): Promise<Track> {
|
public async getTrack(): Promise<Track> {
|
||||||
const track = await getConnection().getRepository(Track).findOne({ id: this.track });
|
const track = await getConnection().getRepository(Track).findOne({ id: this.track });
|
||||||
if (!track) {
|
if (!track) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import * as argon2 from "argon2";
|
import * as argon2 from "argon2";
|
||||||
import { IsBoolean, IsEmail, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
|
import { IsBoolean, IsEmail, IsOptional, IsPhoneNumber, IsString, IsUrl } from 'class-validator';
|
||||||
import { getConnectionManager } from 'typeorm';
|
import { getConnectionManager } from 'typeorm';
|
||||||
import * as uuid from 'uuid';
|
import * as uuid from 'uuid';
|
||||||
import { config } from '../../config';
|
import { config } from '../../config';
|
||||||
@@ -78,7 +78,13 @@ export class CreateUser {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
groups?: number[] | number
|
groups?: number[] | number
|
||||||
|
|
||||||
//TODO: ProfilePics
|
/**
|
||||||
|
* The user's profile pic (or rather a url pointing to it).
|
||||||
|
*/
|
||||||
|
@IsString()
|
||||||
|
@IsUrl()
|
||||||
|
@IsOptional()
|
||||||
|
profilePic?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts this to a User entity.
|
* Converts this to a User entity.
|
||||||
@@ -100,7 +106,9 @@ export class CreateUser {
|
|||||||
newUser.password = await argon2.hash(this.password + newUser.uuid);
|
newUser.password = await argon2.hash(this.password + newUser.uuid);
|
||||||
newUser.groups = await this.getGroups();
|
newUser.groups = await this.getGroups();
|
||||||
newUser.enabled = this.enabled;
|
newUser.enabled = this.enabled;
|
||||||
//TODO: ProfilePics
|
|
||||||
|
if (!this.profilePic) { newUser.profilePic = `https://dev.lauf-fuer-kaya.de/lfk-logo.png`; }
|
||||||
|
else { newUser.profilePic = this.profilePic; }
|
||||||
|
|
||||||
return newUser;
|
return newUser;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { Runner } from '../entities/Runner';
|
|||||||
import { Scan } from '../entities/Scan';
|
import { Scan } from '../entities/Scan';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This classed is used to create a new Scan entity from a json body (post request).
|
* This class is used to update a Scan entity (via put request)
|
||||||
*/
|
*/
|
||||||
export abstract class UpdateScan {
|
export abstract class UpdateScan {
|
||||||
/**
|
/**
|
||||||
@@ -49,6 +49,9 @@ export abstract class UpdateScan {
|
|||||||
return scan;
|
return scan;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a runner based on the runner id provided via this.runner.
|
||||||
|
*/
|
||||||
public async getRunner(): Promise<Runner> {
|
public async getRunner(): Promise<Runner> {
|
||||||
const runner = await getConnection().getRepository(Runner).findOne({ id: this.runner });
|
const runner = await getConnection().getRepository(Runner).findOne({ id: this.runner });
|
||||||
if (!runner) {
|
if (!runner) {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { IsBoolean, IsInt, IsOptional, IsString } from 'class-validator';
|
|||||||
import { ScanStation } from '../entities/ScanStation';
|
import { ScanStation } from '../entities/ScanStation';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This classed is used to create a new StatsClient entity from a json body (post request).
|
* This class is used to update a ScanStation entity (via put request)
|
||||||
*/
|
*/
|
||||||
export class UpdateScanStation {
|
export class UpdateScanStation {
|
||||||
/**
|
/**
|
||||||
@@ -27,8 +27,8 @@ export class UpdateScanStation {
|
|||||||
enabled?: boolean = true;
|
enabled?: boolean = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts this to a ScanStation entity.
|
* Update a ScanStation entity based on this.
|
||||||
* TODO:
|
* @param station The station that shall be updated.
|
||||||
*/
|
*/
|
||||||
public async updateStation(station: ScanStation): Promise<ScanStation> {
|
public async updateStation(station: ScanStation): Promise<ScanStation> {
|
||||||
station.description = this.description;
|
station.description = this.description;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import * as argon2 from "argon2";
|
import * as argon2 from "argon2";
|
||||||
import { IsBoolean, IsEmail, IsInt, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
|
import { IsBoolean, IsEmail, IsInt, IsOptional, IsPhoneNumber, IsString, IsUrl } from 'class-validator';
|
||||||
import { getConnectionManager } from 'typeorm';
|
import { getConnectionManager } from 'typeorm';
|
||||||
import { config } from '../../config';
|
import { config } from '../../config';
|
||||||
import { UsernameOrEmailNeededError } from '../../errors/AuthError';
|
import { UsernameOrEmailNeededError } from '../../errors/AuthError';
|
||||||
@@ -87,7 +87,16 @@ export class UpdateUser {
|
|||||||
groups?: UserGroup[]
|
groups?: UserGroup[]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates a provided User entity based on this.
|
* The user's profile pic (or rather a url pointing to it).
|
||||||
|
*/
|
||||||
|
@IsString()
|
||||||
|
@IsUrl()
|
||||||
|
@IsOptional()
|
||||||
|
profilePic?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates a user entity based on this.
|
||||||
|
* @param user The user that shall be updated.
|
||||||
*/
|
*/
|
||||||
public async updateUser(user: User): Promise<User> {
|
public async updateUser(user: User): Promise<User> {
|
||||||
user.email = this.email;
|
user.email = this.email;
|
||||||
@@ -106,7 +115,9 @@ export class UpdateUser {
|
|||||||
user.lastname = this.lastname
|
user.lastname = this.lastname
|
||||||
user.phone = this.phone;
|
user.phone = this.phone;
|
||||||
user.groups = await this.getGroups();
|
user.groups = await this.getGroups();
|
||||||
//TODO: ProfilePics
|
|
||||||
|
if (!this.profilePic) { user.profilePic = `https://dev.lauf-fuer-kaya.de/lfk-logo.png`; }
|
||||||
|
else { user.profilePic = this.profilePic; }
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { IsBoolean, IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString, IsUUID } from "class-validator";
|
import { IsBoolean, IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString, IsUrl, IsUUID } from "class-validator";
|
||||||
import { ChildEntity, Column, JoinTable, ManyToMany, OneToMany } from "typeorm";
|
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';
|
||||||
@@ -106,10 +106,10 @@ export class User extends Principal {
|
|||||||
* The user's profile picture.
|
* The user's profile picture.
|
||||||
* We haven't decided yet if this will be a bas64 encoded image or just a link to the profile picture.
|
* We haven't decided yet if this will be a bas64 encoded image or just a link to the profile picture.
|
||||||
*/
|
*/
|
||||||
@Column({ nullable: true, unique: false })
|
@Column({ nullable: false, unique: false })
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsUrl()
|
||||||
profilePic?: string;
|
profilePic: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The last time the user requested a password reset.
|
* The last time the user requested a password reset.
|
||||||
@@ -128,6 +128,26 @@ export class User extends Principal {
|
|||||||
@OneToMany(() => UserAction, action => action.user, { nullable: true })
|
@OneToMany(() => UserAction, action => action.user, { nullable: true })
|
||||||
actions: UserAction[]
|
actions: UserAction[]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves all permissions granted to this user through groups or directly to the string enum format.
|
||||||
|
*/
|
||||||
|
public get allPermissions(): string[] {
|
||||||
|
let returnPermissions: string[] = new Array<string>();
|
||||||
|
|
||||||
|
if (!this.permissions) { return returnPermissions; }
|
||||||
|
for (let permission of this.permissions) {
|
||||||
|
returnPermissions.push(permission.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.groups) { return returnPermissions; }
|
||||||
|
for (let group of this.groups) {
|
||||||
|
for (let permission of group.permissions) {
|
||||||
|
returnPermissions.push(permission.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Array.from(new Set(returnPermissions));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turns this entity into it's response class.
|
* Turns this entity into it's response class.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import {
|
|||||||
IsOptional,
|
IsOptional,
|
||||||
IsString
|
IsString
|
||||||
} from "class-validator";
|
} from "class-validator";
|
||||||
import { Permission } from '../entities/Permission';
|
|
||||||
import { User } from '../entities/User';
|
import { User } from '../entities/User';
|
||||||
import { UserGroup } from '../entities/UserGroup';
|
import { UserGroup } from '../entities/UserGroup';
|
||||||
import { ResponsePrincipal } from './ResponsePrincipal';
|
import { ResponsePrincipal } from './ResponsePrincipal';
|
||||||
@@ -57,11 +56,10 @@ export class ResponseUser extends ResponsePrincipal {
|
|||||||
enabled: boolean = true;
|
enabled: boolean = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user's profile pic.
|
* The user's profile pic (or rather a url pointing to it).
|
||||||
*/
|
*/
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
profilePic: string;
|
||||||
profilePic?: string;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The groups that the user is a part of.
|
* The groups that the user is a part of.
|
||||||
@@ -75,7 +73,7 @@ export class ResponseUser extends ResponsePrincipal {
|
|||||||
*/
|
*/
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
permissions: Permission[];
|
permissions: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a ResponseUser object from a user.
|
* Creates a ResponseUser object from a user.
|
||||||
@@ -92,6 +90,7 @@ export class ResponseUser extends ResponsePrincipal {
|
|||||||
this.enabled = user.enabled;
|
this.enabled = user.enabled;
|
||||||
this.profilePic = user.profilePic;
|
this.profilePic = user.profilePic;
|
||||||
this.groups = user.groups;
|
this.groups = user.groups;
|
||||||
this.permissions = user.permissions;
|
this.permissions = user.allPermissions;
|
||||||
|
this.groups.forEach(function (g) { delete g.permissions });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user