Compare commits

...

9 Commits

Author SHA1 Message Date
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
d948fe2631 Merge pull request 'Fixed relative paths not being updated + version bump for bugfix release' (#75) from dev into main
Some checks failed
continuous-integration/drone/tag Build is passing
continuous-integration/drone/push Build is failing
Reviewed-on: #75
Reviewed-by: Philipp Dormann <philipp@philippdormann.de>
2021-01-03 18:13:10 +00:00
2b5525323b Fixed relative paths not being updated + version bump for bugfix release
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2021-01-03 19:10:46 +01:00
b57fde9b0a Merge pull request 'Bugfix for the openapi exporter' (#74) from dev into main
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #74
Reviewed-by: Philipp Dormann <philipp@philippdormann.de>
2021-01-03 17:29:35 +00:00
86706f9422 Merge branch 'main' into dev
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2021-01-03 17:29:24 +00:00
0687f268fc Fixed switch up between node/js and ts-node/ts
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2021-01-03 18:27:58 +01:00
9 changed files with 58 additions and 40 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@odit/lfk-backend",
"version": "0.0.7",
"version": "0.0.8",
"main": "src/app.ts",
"repository": "https://git.odit.services/lfk/backend",
"author": {
@@ -75,7 +75,7 @@
"test:watch": "jest --watchAll",
"test:ci": "start-server-and-test dev http://localhost:4010/api/docs/openapi.json test",
"seed": "ts-node ./node_modules/typeorm/cli.js schema:sync && ts-node ./node_modules/typeorm-seeding/dist/cli.js seed",
"openapi:export": "node scripts/openapi_export.js",
"openapi:export": "ts-node scripts/openapi_export.ts",
"licenses:export": "license-exporter --md"
},
"nodemonConfig": {

View File

@@ -15,7 +15,7 @@ createExpressServer({
development: config.development,
cors: true,
routePrefix: "/api",
controllers: [`${__dirname}/controllers/*.${CONTROLLERS_FILE_EXTENSION}`],
controllers: [`${__dirname}/../src/controllers/*.${CONTROLLERS_FILE_EXTENSION}`],
});
const storage = getMetadataArgsStorage();
@@ -55,7 +55,7 @@ const spec = routingControllersToSpec(
info: {
description: "The the backend API for the LfK! runner system.",
title: "LfK! Backend API",
version: "0.0.5",
version: "0.0.8",
},
}
);

View File

@@ -27,7 +27,7 @@ export class RunnerController {
@OpenAPI({ description: 'Lists all runners from all teams/orgs. <br> This includes the runner\'s group and distance ran.' })
async getAll() {
let responseRunners: ResponseRunner[] = new Array<ResponseRunner>();
const runners = await this.runnerRepository.find({ relations: ['scans', 'group'] });
const runners = await this.runnerRepository.find({ relations: ['scans', 'group', 'group.permissions', 'permissions'] });
runners.forEach(runner => {
responseRunners.push(new ResponseRunner(runner));
});

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

@@ -46,7 +46,7 @@ export default async (app: Application) => {
info: {
description: "The the backend API for the LfK! runner system.",
title: "LfK! Backend API",
version: "0.0.5",
version: "0.0.8",
},
}
);

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

@@ -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,24 @@ 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 allPermissions = new Array<string>();
for (let permission in this.permissions) {
allPermissions.push(permission.toString());
}
for (let group of this.groups) {
for (let permission in group.permissions) {
allPermissions.push(permission.toString());
}
}
console.log(allPermissions)
return Array.from(new Set(allPermissions));
}
/**
* 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,6 @@ 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;
}
}