Compare commits

...

16 Commits

Author SHA1 Message Date
c66b06c2c9 Merge pull request 'Alpha Release 0.0.9' (#82) from dev into main
All checks were successful
continuous-integration/drone/tag Build is passing
continuous-integration/drone/push Build is passing
Reviewed-on: #82
Reviewed-by: Philipp Dormann <philipp@philippdormann.de>
2021-01-08 19:52:55 +00:00
65e605cdc4 Version bump
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2021-01-08 20:49:19 +01:00
d2fdb4efd9 Merge pull request 'All users get profile pics feature/79-profile_pics' (#81) from feature/79-profile_pics into dev
Some checks failed
continuous-integration/drone/push Build is failing
Reviewed-on: #81
closes #79
2021-01-08 19:48:22 +00:00
d0deb9d647 Fixed wrong relation getting resolved
All checks were successful
continuous-integration/drone/pr Build is passing
ref #79
2021-01-08 20:40:15 +01:00
5495c90eaf Merge branch 'dev' into feature/79-profile_pics
Some checks failed
continuous-integration/drone/pr Build is failing
2021-01-08 20:19:08 +01:00
bf3ffae67c Merge pull request 'Added scan (station) apis feature/67-scan_apis' (#80) from feature/67-scan_apis into dev
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #80
closes #67
2021-01-08 19:18:39 +00:00
aa0337ea33 Fixed getting all permissions for users
ref #79
2021-01-08 20:17:05 +01:00
4991d735bf Pinned sqlite3 to 5.0.0 as a temporary bugfix
All checks were successful
continuous-integration/drone/pr Build is passing
ref #67
2021-01-08 20:04:04 +01:00
398e61bddb Merge branch 'feature/67-scan_apis' of git.odit.services:lfk/backend into feature/67-scan_apis
Some checks failed
continuous-integration/drone/pr Build is failing
# Conflicts:
#	.drone.yml
2021-01-08 19:37:25 +01:00
e6576f4a54 Finned node version for ci
ref #67
2021-01-08 19:37:13 +01:00
c3b9e135b0 Finned node version for ci
Some checks failed
continuous-integration/drone/pr Build is failing
ref #67
2021-01-08 19:34:39 +01:00
3bd4948c43 Merge branch 'feature/79-profile_pics' of git.odit.services:lfk/backend into feature/79-profile_pics 2021-01-08 19:32:13 +01:00
f3cd1380be First part of the permission return (buggy!)
ref #79
2021-01-08 19:32:11 +01:00
a2c3dfbf85 First part of the permission return (buggy!)
ref #71
2021-01-08 19:32:04 +01:00
3c37aafe1f Added profile pics to all user related models
ref #79
2021-01-08 19:11:50 +01:00
c591c182b3 Updated comments
Some checks failed
continuous-integration/drone/pr Build is failing
ref #67
2021-01-08 18:37:33 +01:00
12 changed files with 79 additions and 49 deletions

View File

@@ -11,7 +11,7 @@ steps:
- git checkout $DRONE_SOURCE_BRANCH
- mv .env.ci .env
- name: run tests
image: node:alpine
image: node:14.15.1-alpine3.12
commands:
- yarn
- yarn test:ci
@@ -39,7 +39,7 @@ steps:
registry: registry.odit.services
- name: run full license export
depends_on: ["clone"]
image: node:alpine
image: node:14.15.1-alpine3.12
commands:
- yarn
- yarn licenses:export

View File

@@ -1,6 +1,6 @@
{
"name": "@odit/lfk-backend",
"version": "0.0.8",
"version": "0.0.9",
"main": "src/app.ts",
"repository": "https://git.odit.services/lfk/backend",
"author": {
@@ -40,7 +40,7 @@
"reflect-metadata": "^0.1.13",
"routing-controllers": "^0.9.0-alpha.6",
"routing-controllers-openapi": "^2.1.0",
"sqlite3": "^5.0.0",
"sqlite3": "5.0.0",
"typeorm": "^0.2.29",
"typeorm-routing-controllers-extensions": "^0.2.0",
"typeorm-seeding": "^1.6.1",

View File

@@ -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).' })
async getAll() {
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 => {
responseUsers.push(new ResponseUser(user));
});
@@ -43,7 +43,7 @@ export class UserController {
@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.' })
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(); }
return new ResponseUser(user);
}

View File

@@ -106,23 +106,6 @@ export class JwtUser {
this.refreshTokenCount = user.refreshTokenCount;
this.uuid = user.uuid;
this.profilePic = user.profilePic;
this.permissions = this.getPermissions(user);
}
/**
* 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));
this.permissions = user.allPermissions;
}
}

View File

@@ -5,7 +5,7 @@ import { Runner } from '../entities/Runner';
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 {
/**
@@ -46,6 +46,9 @@ export abstract class CreateScan {
return newScan;
}
/**
* Gets a runner based on the runner id provided via this.runner.
*/
public async getRunner(): Promise<Runner> {
const runner = await getConnection().getRepository(Runner).findOne({ id: this.runner });
if (!runner) {

View File

@@ -8,19 +8,18 @@ import { ScanStation } from '../entities/ScanStation';
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 {
/**
* The new client's description.
* The new station's description.
*/
@IsString()
@IsOptional()
description?: string;
/**
* The scan's associated track.
* This is used to determine the scan's distance.
* The station's associated track.
*/
@IsInt()
@IsPositive()
@@ -51,6 +50,10 @@ export class CreateScanStation {
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> {
const track = await getConnection().getRepository(Track).findOne({ id: this.track });
if (!track) {

View File

@@ -1,5 +1,5 @@
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 * as uuid from 'uuid';
import { config } from '../../config';
@@ -78,7 +78,13 @@ export class CreateUser {
@IsOptional()
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.
@@ -100,7 +106,9 @@ export class CreateUser {
newUser.password = await argon2.hash(this.password + newUser.uuid);
newUser.groups = await this.getGroups();
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;
}

View File

@@ -5,7 +5,7 @@ import { Runner } from '../entities/Runner';
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 {
/**
@@ -49,6 +49,9 @@ export abstract class UpdateScan {
return scan;
}
/**
* Gets a runner based on the runner id provided via this.runner.
*/
public async getRunner(): Promise<Runner> {
const runner = await getConnection().getRepository(Runner).findOne({ id: this.runner });
if (!runner) {

View File

@@ -2,7 +2,7 @@ import { IsBoolean, IsInt, IsOptional, IsString } from 'class-validator';
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 {
/**
@@ -27,8 +27,8 @@ export class UpdateScanStation {
enabled?: boolean = true;
/**
* Converts this to a ScanStation entity.
* TODO:
* Update a ScanStation entity based on this.
* @param station The station that shall be updated.
*/
public async updateStation(station: ScanStation): Promise<ScanStation> {
station.description = this.description;

View File

@@ -1,5 +1,5 @@
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 { config } from '../../config';
import { UsernameOrEmailNeededError } from '../../errors/AuthError';
@@ -87,7 +87,16 @@ export class UpdateUser {
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> {
user.email = this.email;
@@ -106,7 +115,9 @@ export class UpdateUser {
user.lastname = this.lastname
user.phone = this.phone;
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;
}

View File

@@ -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 { config } from '../../config';
import { ResponsePrincipal } from '../responses/ResponsePrincipal';
@@ -106,10 +106,10 @@ export class User extends Principal {
* 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.
*/
@Column({ nullable: true, unique: false })
@Column({ nullable: false, unique: false })
@IsString()
@IsOptional()
profilePic?: string;
@IsUrl()
profilePic: string;
/**
* 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 })
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.
*/

View File

@@ -5,7 +5,6 @@ import {
IsOptional,
IsString
} from "class-validator";
import { Permission } from '../entities/Permission';
import { User } from '../entities/User';
import { UserGroup } from '../entities/UserGroup';
import { ResponsePrincipal } from './ResponsePrincipal';
@@ -57,11 +56,10 @@ export class ResponseUser extends ResponsePrincipal {
enabled: boolean = true;
/**
* The user's profile pic.
* The user's profile pic (or rather a url pointing to it).
*/
@IsString()
@IsOptional()
profilePic?: string;
profilePic: string;
/**
* The groups that the user is a part of.
@@ -75,7 +73,7 @@ export class ResponseUser extends ResponsePrincipal {
*/
@IsArray()
@IsOptional()
permissions: Permission[];
permissions: string[];
/**
* Creates a ResponseUser object from a user.
@@ -92,6 +90,7 @@ export class ResponseUser extends ResponsePrincipal {
this.enabled = user.enabled;
this.profilePic = user.profilePic;
this.groups = user.groups;
this.permissions = user.permissions;
this.permissions = user.allPermissions;
this.groups.forEach(function (g) { delete g.permissions });
}
}