Merge branch 'dev' into feature/18-exported-env-vars
This commit is contained in:
commit
0fc0b87c67
@ -53,9 +53,11 @@ docker-compose up --build
|
|||||||
|
|
||||||
## File Structure
|
## File Structure
|
||||||
|
|
||||||
- src/models/\* - database models (typeorm entities)
|
- src/models/entities\* - database models (typeorm entities)
|
||||||
|
- src/models/actions\* - actions models
|
||||||
|
- src/models/responses\* - response models
|
||||||
- src/controllers/\* - routing-controllers
|
- src/controllers/\* - routing-controllers
|
||||||
- src/loaders/\* - loaders for the different init steps of the api server
|
- src/loaders/\* - loaders for the different init steps of the api server
|
||||||
- src/routes/\* - express routes for everything we don't do via routing-controllers (shouldn't be much)
|
|
||||||
- src/middlewares/\* - express middlewares (mainly auth r/n)
|
- src/middlewares/\* - express middlewares (mainly auth r/n)
|
||||||
- src/errors/* - our custom (http) errors
|
- src/errors/* - our custom (http) errors
|
||||||
|
- src/routes/\* - express routes for everything we don't do via routing-controllers (depreciated)
|
@ -2,11 +2,11 @@ import { Body, JsonController, Post } from 'routing-controllers';
|
|||||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||||
import { IllegalJWTError, InvalidCredentialsError, JwtNotProvidedError, PasswordNeededError, RefreshTokenCountInvalidError, UsernameOrEmailNeededError } from '../errors/AuthError';
|
import { IllegalJWTError, InvalidCredentialsError, JwtNotProvidedError, PasswordNeededError, RefreshTokenCountInvalidError, UsernameOrEmailNeededError } from '../errors/AuthError';
|
||||||
import { UserNotFoundError } from '../errors/UserErrors';
|
import { UserNotFoundError } from '../errors/UserErrors';
|
||||||
import { CreateAuth } from '../models/creation/CreateAuth';
|
import { CreateAuth } from '../models/actions/CreateAuth';
|
||||||
import { HandleLogout } from '../models/creation/HandleLogout';
|
import { HandleLogout } from '../models/actions/HandleLogout';
|
||||||
import { RefreshAuth } from '../models/creation/RefreshAuth';
|
import { RefreshAuth } from '../models/actions/RefreshAuth';
|
||||||
import { Auth } from '../models/responses/Auth';
|
import { Auth } from '../models/responses/ResponseAuth';
|
||||||
import { Logout } from '../models/responses/Logout';
|
import { Logout } from '../models/responses/ResponseLogout';
|
||||||
|
|
||||||
@JsonController('/auth')
|
@JsonController('/auth')
|
||||||
export class AuthController {
|
export class AuthController {
|
||||||
@ -25,7 +25,6 @@ export class AuthController {
|
|||||||
let auth;
|
let auth;
|
||||||
try {
|
try {
|
||||||
auth = await createAuth.toAuth();
|
auth = await createAuth.toAuth();
|
||||||
console.log(auth);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@ -44,7 +43,6 @@ export class AuthController {
|
|||||||
let logout;
|
let logout;
|
||||||
try {
|
try {
|
||||||
logout = await handleLogout.logout()
|
logout = await handleLogout.logout()
|
||||||
console.log(logout);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@ -62,7 +60,6 @@ export class AuthController {
|
|||||||
let auth;
|
let auth;
|
||||||
try {
|
try {
|
||||||
auth = await refreshAuth.toAuth();
|
auth = await refreshAuth.toAuth();
|
||||||
console.log(auth);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,9 @@ import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, Query
|
|||||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||||
import { getConnectionManager, Repository } from 'typeorm';
|
import { getConnectionManager, Repository } from 'typeorm';
|
||||||
import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
|
import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
|
||||||
import { RunnerGroupNeededError, RunnerGroupNotFoundError, RunnerIdsNotMatchingError, RunnerNotFoundError, RunnerOnlyOneGroupAllowedError } from '../errors/RunnerErrors';
|
import { RunnerGroupNeededError, RunnerIdsNotMatchingError, RunnerNotFoundError } from '../errors/RunnerErrors';
|
||||||
import { CreateRunner } from '../models/creation/CreateRunner';
|
import { RunnerGroupNotFoundError } from '../errors/RunnerGroupErrors';
|
||||||
|
import { CreateRunner } from '../models/actions/CreateRunner';
|
||||||
import { Runner } from '../models/entities/Runner';
|
import { Runner } from '../models/entities/Runner';
|
||||||
import { ResponseRunner } from '../models/responses/ResponseRunner';
|
import { ResponseRunner } from '../models/responses/ResponseRunner';
|
||||||
|
|
||||||
@ -38,12 +39,13 @@ export class RunnerController {
|
|||||||
@OnUndefined(RunnerNotFoundError)
|
@OnUndefined(RunnerNotFoundError)
|
||||||
@OpenAPI({ description: 'Returns a runner of a specified id (if it exists)' })
|
@OpenAPI({ description: 'Returns a runner of a specified id (if it exists)' })
|
||||||
async getOne(@Param('id') id: number) {
|
async getOne(@Param('id') id: number) {
|
||||||
return new ResponseRunner(await this.runnerRepository.findOne({ id: id }, { relations: ['scans', 'group'] }));
|
let runner = await this.runnerRepository.findOne({ id: id }, { relations: ['scans', 'group'] })
|
||||||
|
if (!runner) { throw new RunnerNotFoundError(); }
|
||||||
|
return new ResponseRunner(runner);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ResponseSchema(ResponseRunner)
|
@ResponseSchema(ResponseRunner)
|
||||||
@ResponseSchema(RunnerOnlyOneGroupAllowedError)
|
|
||||||
@ResponseSchema(RunnerGroupNeededError)
|
@ResponseSchema(RunnerGroupNeededError)
|
||||||
@ResponseSchema(RunnerGroupNotFoundError)
|
@ResponseSchema(RunnerGroupNotFoundError)
|
||||||
@OpenAPI({ description: 'Create a new runner object (id will be generated automagicly).' })
|
@OpenAPI({ description: 'Create a new runner object (id will be generated automagicly).' })
|
||||||
|
@ -3,14 +3,14 @@ import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
|||||||
import { getConnectionManager, Repository } from 'typeorm';
|
import { getConnectionManager, Repository } from 'typeorm';
|
||||||
import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
|
import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
|
||||||
import { RunnerOrganisationHasRunnersError, RunnerOrganisationHasTeamsError, RunnerOrganisationIdsNotMatchingError, RunnerOrganisationNotFoundError } from '../errors/RunnerOrganisationErrors';
|
import { RunnerOrganisationHasRunnersError, RunnerOrganisationHasTeamsError, RunnerOrganisationIdsNotMatchingError, RunnerOrganisationNotFoundError } from '../errors/RunnerOrganisationErrors';
|
||||||
import { CreateRunnerOrganisation } from '../models/creation/CreateRunnerOrganisation';
|
import { CreateRunnerOrganisation } from '../models/actions/CreateRunnerOrganisation';
|
||||||
import { RunnerOrganisation } from '../models/entities/RunnerOrganisation';
|
import { RunnerOrganisation } from '../models/entities/RunnerOrganisation';
|
||||||
import { ResponseRunnerOrganisation } from '../models/responses/ResponseRunnerOrganisation';
|
import { ResponseRunnerOrganisation } from '../models/responses/ResponseRunnerOrganisation';
|
||||||
import { RunnerController } from './RunnerController';
|
import { RunnerController } from './RunnerController';
|
||||||
import { RunnerTeamController } from './RunnerTeamController';
|
import { RunnerTeamController } from './RunnerTeamController';
|
||||||
|
|
||||||
|
|
||||||
@JsonController('/organisation')
|
@JsonController('/organisations')
|
||||||
//@Authorized('RUNNERS:read')
|
//@Authorized('RUNNERS:read')
|
||||||
export class RunnerOrganisationController {
|
export class RunnerOrganisationController {
|
||||||
private runnerOrganisationRepository: Repository<RunnerOrganisation>;
|
private runnerOrganisationRepository: Repository<RunnerOrganisation>;
|
||||||
@ -41,7 +41,9 @@ export class RunnerOrganisationController {
|
|||||||
@OnUndefined(RunnerOrganisationNotFoundError)
|
@OnUndefined(RunnerOrganisationNotFoundError)
|
||||||
@OpenAPI({ description: 'Returns a runnerOrganisation of a specified id (if it exists)' })
|
@OpenAPI({ description: 'Returns a runnerOrganisation of a specified id (if it exists)' })
|
||||||
async getOne(@Param('id') id: number) {
|
async getOne(@Param('id') id: number) {
|
||||||
return new ResponseRunnerOrganisation(await this.runnerOrganisationRepository.findOne({ id: id }, { relations: ['address', 'contact', 'teams'] }));
|
let runnerOrg = await this.runnerOrganisationRepository.findOne({ id: id }, { relations: ['address', 'contact', 'teams'] });
|
||||||
|
if (!runnerOrg) { throw new RunnerOrganisationNotFoundError(); }
|
||||||
|
return new ResponseRunnerOrganisation(runnerOrg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ -66,7 +68,7 @@ export class RunnerOrganisationController {
|
|||||||
@ResponseSchema(RunnerOrganisationIdsNotMatchingError, { statusCode: 406 })
|
@ResponseSchema(RunnerOrganisationIdsNotMatchingError, { statusCode: 406 })
|
||||||
@OpenAPI({ description: "Update a runnerOrganisation object (id can't be changed)." })
|
@OpenAPI({ description: "Update a runnerOrganisation object (id can't be changed)." })
|
||||||
async put(@Param('id') id: number, @EntityFromBody() runnerOrganisation: RunnerOrganisation) {
|
async put(@Param('id') id: number, @EntityFromBody() runnerOrganisation: RunnerOrganisation) {
|
||||||
let oldRunnerOrganisation = await this.runnerOrganisationRepository.findOne({ id: id }, { relations: ['address', 'contact', 'teams'] });
|
let oldRunnerOrganisation = await this.runnerOrganisationRepository.findOne({ id: id });
|
||||||
|
|
||||||
if (!oldRunnerOrganisation) {
|
if (!oldRunnerOrganisation) {
|
||||||
throw new RunnerOrganisationNotFoundError();
|
throw new RunnerOrganisationNotFoundError();
|
||||||
|
@ -3,7 +3,7 @@ import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
|||||||
import { getConnectionManager, Repository } from 'typeorm';
|
import { getConnectionManager, Repository } from 'typeorm';
|
||||||
import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
|
import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
|
||||||
import { RunnerTeamHasRunnersError, RunnerTeamIdsNotMatchingError, RunnerTeamNotFoundError } from '../errors/RunnerTeamErrors';
|
import { RunnerTeamHasRunnersError, RunnerTeamIdsNotMatchingError, RunnerTeamNotFoundError } from '../errors/RunnerTeamErrors';
|
||||||
import { CreateRunnerTeam } from '../models/creation/CreateRunnerTeam';
|
import { CreateRunnerTeam } from '../models/actions/CreateRunnerTeam';
|
||||||
import { RunnerTeam } from '../models/entities/RunnerTeam';
|
import { RunnerTeam } from '../models/entities/RunnerTeam';
|
||||||
import { ResponseRunnerTeam } from '../models/responses/ResponseRunnerTeam';
|
import { ResponseRunnerTeam } from '../models/responses/ResponseRunnerTeam';
|
||||||
import { RunnerController } from './RunnerController';
|
import { RunnerController } from './RunnerController';
|
||||||
@ -40,7 +40,9 @@ export class RunnerTeamController {
|
|||||||
@OnUndefined(RunnerTeamNotFoundError)
|
@OnUndefined(RunnerTeamNotFoundError)
|
||||||
@OpenAPI({ description: 'Returns a runnerTeam of a specified id (if it exists)' })
|
@OpenAPI({ description: 'Returns a runnerTeam of a specified id (if it exists)' })
|
||||||
async getOne(@Param('id') id: number) {
|
async getOne(@Param('id') id: number) {
|
||||||
return new ResponseRunnerTeam(await this.runnerTeamRepository.findOne({ id: id }, { relations: ['parentGroup', 'contact'] }));
|
let runnerTeam = await this.runnerTeamRepository.findOne({ id: id }, { relations: ['parentGroup', 'contact'] });
|
||||||
|
if (!runnerTeam) { throw new RunnerTeamNotFoundError(); }
|
||||||
|
return new ResponseRunnerTeam(runnerTeam);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
|
@ -3,7 +3,7 @@ import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
|||||||
import { getConnectionManager, Repository } from 'typeorm';
|
import { getConnectionManager, Repository } from 'typeorm';
|
||||||
import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
|
import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
|
||||||
import { TrackIdsNotMatchingError, TrackNotFoundError } from "../errors/TrackErrors";
|
import { TrackIdsNotMatchingError, TrackNotFoundError } from "../errors/TrackErrors";
|
||||||
import { CreateTrack } from '../models/creation/CreateTrack';
|
import { CreateTrack } from '../models/actions/CreateTrack';
|
||||||
import { Track } from '../models/entities/Track';
|
import { Track } from '../models/entities/Track';
|
||||||
import { ResponseTrack } from '../models/responses/ResponseTrack';
|
import { ResponseTrack } from '../models/responses/ResponseTrack';
|
||||||
|
|
||||||
@ -37,7 +37,9 @@ export class TrackController {
|
|||||||
@OnUndefined(TrackNotFoundError)
|
@OnUndefined(TrackNotFoundError)
|
||||||
@OpenAPI({ description: "Returns a track of a specified id (if it exists)" })
|
@OpenAPI({ description: "Returns a track of a specified id (if it exists)" })
|
||||||
async getOne(@Param('id') id: number) {
|
async getOne(@Param('id') id: number) {
|
||||||
return new ResponseTrack(await this.trackRepository.findOne({ id: id }));
|
let track = await this.trackRepository.findOne({ id: id });
|
||||||
|
if (!track) { throw new TrackNotFoundError(); }
|
||||||
|
return new ResponseTrack(track);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
|
@ -2,8 +2,9 @@ import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put } from
|
|||||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||||
import { getConnectionManager, Repository } from 'typeorm';
|
import { getConnectionManager, Repository } from 'typeorm';
|
||||||
import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
|
import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
|
||||||
import { UserGroupNotFoundError, UserIdsNotMatchingError, UserNotFoundError } from '../errors/UserErrors';
|
import { UserIdsNotMatchingError, UserNotFoundError } from '../errors/UserErrors';
|
||||||
import { CreateUser } from '../models/creation/CreateUser';
|
import { UserGroupNotFoundError } from '../errors/UserGroupErrors';
|
||||||
|
import { CreateUser } from '../models/actions/CreateUser';
|
||||||
import { User } from '../models/entities/User';
|
import { User } from '../models/entities/User';
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
|||||||
import { getConnectionManager, Repository } from 'typeorm';
|
import { getConnectionManager, Repository } from 'typeorm';
|
||||||
import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
|
import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
|
||||||
import { UserGroupIdsNotMatchingError, UserGroupNotFoundError } from '../errors/UserGroupErrors';
|
import { UserGroupIdsNotMatchingError, UserGroupNotFoundError } from '../errors/UserGroupErrors';
|
||||||
import { CreateUserGroup } from '../models/creation/CreateUserGroup';
|
import { CreateUserGroup } from '../models/actions/CreateUserGroup';
|
||||||
import { UserGroup } from '../models/entities/UserGroup';
|
import { UserGroup } from '../models/entities/UserGroup';
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import { IsString } from 'class-validator';
|
import { IsString } from 'class-validator';
|
||||||
import { NotAcceptableError, NotFoundError } from 'routing-controllers';
|
import { NotAcceptableError, NotFoundError } from 'routing-controllers';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error to throw, when to provided address doesn't belong to the accepted types.
|
||||||
|
*/
|
||||||
export class AddressWrongTypeError extends NotAcceptableError {
|
export class AddressWrongTypeError extends NotAcceptableError {
|
||||||
@IsString()
|
@IsString()
|
||||||
name = "AddressWrongTypeError"
|
name = "AddressWrongTypeError"
|
||||||
@ -9,6 +12,9 @@ export class AddressWrongTypeError extends NotAcceptableError {
|
|||||||
message = "The address must be an existing adress's id. \n You provided a object of another type."
|
message = "The address must be an existing adress's id. \n You provided a object of another type."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error to throw, when a non-existant address get's loaded.
|
||||||
|
*/
|
||||||
export class AddressNotFoundError extends NotFoundError {
|
export class AddressNotFoundError extends NotFoundError {
|
||||||
@IsString()
|
@IsString()
|
||||||
name = "AddressNotFoundError"
|
name = "AddressNotFoundError"
|
||||||
|
@ -2,7 +2,7 @@ import { IsString } from 'class-validator';
|
|||||||
import { ForbiddenError, NotAcceptableError, NotFoundError, UnauthorizedError } from 'routing-controllers';
|
import { ForbiddenError, NotAcceptableError, NotFoundError, UnauthorizedError } from 'routing-controllers';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error to throw when a jwt is expired
|
* Error to throw when a jwt is expired.
|
||||||
*/
|
*/
|
||||||
export class ExpiredJWTError extends UnauthorizedError {
|
export class ExpiredJWTError extends UnauthorizedError {
|
||||||
@IsString()
|
@IsString()
|
||||||
@ -13,7 +13,7 @@ export class ExpiredJWTError extends UnauthorizedError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error to throw when a jwt could not be parsed
|
* Error to throw when a jwt could not be parsed.
|
||||||
*/
|
*/
|
||||||
export class IllegalJWTError extends UnauthorizedError {
|
export class IllegalJWTError extends UnauthorizedError {
|
||||||
@IsString()
|
@IsString()
|
||||||
@ -24,7 +24,7 @@ export class IllegalJWTError extends UnauthorizedError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error to throw when user is nonexistant or refreshtoken is invalid
|
* Error to throw when user is nonexistant or refreshtoken is invalid.
|
||||||
*/
|
*/
|
||||||
export class UserNonexistantOrRefreshtokenInvalidError extends UnauthorizedError {
|
export class UserNonexistantOrRefreshtokenInvalidError extends UnauthorizedError {
|
||||||
@IsString()
|
@IsString()
|
||||||
@ -35,7 +35,7 @@ export class UserNonexistantOrRefreshtokenInvalidError extends UnauthorizedError
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error to throw when provided credentials are invalid
|
* Error to throw when provided credentials are invalid.
|
||||||
*/
|
*/
|
||||||
export class InvalidCredentialsError extends UnauthorizedError {
|
export class InvalidCredentialsError extends UnauthorizedError {
|
||||||
@IsString()
|
@IsString()
|
||||||
@ -46,7 +46,7 @@ export class InvalidCredentialsError extends UnauthorizedError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error to throw when a jwt does not have permission for this route/ action
|
* Error to throw when a jwt does not have permission for this route/action.
|
||||||
*/
|
*/
|
||||||
export class NoPermissionError extends ForbiddenError {
|
export class NoPermissionError extends ForbiddenError {
|
||||||
@IsString()
|
@IsString()
|
||||||
@ -57,7 +57,7 @@ export class NoPermissionError extends ForbiddenError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error to thow when no username and no email is set
|
* Error to throw when no username and no email is set.
|
||||||
*/
|
*/
|
||||||
export class UsernameOrEmailNeededError extends NotAcceptableError {
|
export class UsernameOrEmailNeededError extends NotAcceptableError {
|
||||||
@IsString()
|
@IsString()
|
||||||
@ -68,7 +68,7 @@ export class UsernameOrEmailNeededError extends NotAcceptableError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error to thow when no password is provided
|
* Error to throw when no password is provided.
|
||||||
*/
|
*/
|
||||||
export class PasswordNeededError extends NotAcceptableError {
|
export class PasswordNeededError extends NotAcceptableError {
|
||||||
@IsString()
|
@IsString()
|
||||||
@ -79,7 +79,7 @@ export class PasswordNeededError extends NotAcceptableError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error to thow when no user could be found for provided credential
|
* Error to throw when no user could be found mating the provided credential.
|
||||||
*/
|
*/
|
||||||
export class UserNotFoundError extends NotFoundError {
|
export class UserNotFoundError extends NotFoundError {
|
||||||
@IsString()
|
@IsString()
|
||||||
@ -90,7 +90,7 @@ export class UserNotFoundError extends NotFoundError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error to thow when no jwt token was provided
|
* Error to throw when no jwt token was provided (but one had to be).
|
||||||
*/
|
*/
|
||||||
export class JwtNotProvidedError extends NotAcceptableError {
|
export class JwtNotProvidedError extends NotAcceptableError {
|
||||||
@IsString()
|
@IsString()
|
||||||
@ -101,7 +101,7 @@ export class JwtNotProvidedError extends NotAcceptableError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error to thow when user was not found or refresh token count was invalid
|
* Error to throw when user was not found or refresh token count was invalid.
|
||||||
*/
|
*/
|
||||||
export class UserNotFoundOrRefreshTokenCountInvalidError extends NotAcceptableError {
|
export class UserNotFoundOrRefreshTokenCountInvalidError extends NotAcceptableError {
|
||||||
@IsString()
|
@IsString()
|
||||||
@ -112,7 +112,7 @@ export class UserNotFoundOrRefreshTokenCountInvalidError extends NotAcceptableEr
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error to thow when refresh token count was invalid
|
* Error to throw when refresh token count was invalid
|
||||||
*/
|
*/
|
||||||
export class RefreshTokenCountInvalidError extends NotAcceptableError {
|
export class RefreshTokenCountInvalidError extends NotAcceptableError {
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import { IsString } from 'class-validator';
|
import { IsString } from 'class-validator';
|
||||||
import { NotAcceptableError, NotFoundError } from 'routing-controllers';
|
import { NotAcceptableError, NotFoundError } from 'routing-controllers';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error to throw, when a provided groupContact doesn't belong to the accepted types.
|
||||||
|
*/
|
||||||
export class GroupContactWrongTypeError extends NotAcceptableError {
|
export class GroupContactWrongTypeError extends NotAcceptableError {
|
||||||
@IsString()
|
@IsString()
|
||||||
name = "GroupContactWrongTypeError"
|
name = "GroupContactWrongTypeError"
|
||||||
@ -9,6 +12,9 @@ export class GroupContactWrongTypeError extends NotAcceptableError {
|
|||||||
message = "The groupContact must be an existing groupContact's id. \n You provided a object of another type."
|
message = "The groupContact must be an existing groupContact's id. \n You provided a object of another type."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error to throw, when a non-existant groupContact get's loaded.
|
||||||
|
*/
|
||||||
export class GroupContactNotFoundError extends NotFoundError {
|
export class GroupContactNotFoundError extends NotFoundError {
|
||||||
@IsString()
|
@IsString()
|
||||||
name = "GroupContactNotFoundError"
|
name = "GroupContactNotFoundError"
|
||||||
|
@ -26,14 +26,9 @@ export class RunnerIdsNotMatchingError extends NotAcceptableError {
|
|||||||
message = "The id's don't match!! \n And if you wanted to change a runner's id: This isn't allowed"
|
message = "The id's don't match!! \n And if you wanted to change a runner's id: This isn't allowed"
|
||||||
}
|
}
|
||||||
|
|
||||||
export class RunnerOnlyOneGroupAllowedError extends NotAcceptableError {
|
/**
|
||||||
@IsString()
|
* Error to throw when a runner is missing his group association.
|
||||||
name = "RunnerOnlyOneGroupAllowedError"
|
*/
|
||||||
|
|
||||||
@IsString()
|
|
||||||
message = "Runner's can only be part of one group (team or organisiation)! \n You provided an id for both."
|
|
||||||
}
|
|
||||||
|
|
||||||
export class RunnerGroupNeededError extends NotAcceptableError {
|
export class RunnerGroupNeededError extends NotAcceptableError {
|
||||||
@IsString()
|
@IsString()
|
||||||
name = "RunnerGroupNeededError"
|
name = "RunnerGroupNeededError"
|
||||||
@ -41,12 +36,3 @@ export class RunnerGroupNeededError extends NotAcceptableError {
|
|||||||
@IsString()
|
@IsString()
|
||||||
message = "Runner's need to be part of one group (team or organisiation)! \n You provided neither."
|
message = "Runner's need to be part of one group (team or organisiation)! \n You provided neither."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export class RunnerGroupNotFoundError extends NotFoundError {
|
|
||||||
@IsString()
|
|
||||||
name = "RunnerGroupNotFoundError"
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
message = "The group you provided couldn't be located in the system. \n Please check your request."
|
|
||||||
}
|
|
14
src/errors/RunnerGroupErrors.ts
Normal file
14
src/errors/RunnerGroupErrors.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { IsString } from 'class-validator';
|
||||||
|
import { NotFoundError } from 'routing-controllers';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error to throw when a runner group couldn't be found.
|
||||||
|
* Implemented this ways to work with the json-schema conversion for openapi.
|
||||||
|
*/
|
||||||
|
export class RunnerGroupNotFoundError extends NotFoundError {
|
||||||
|
@IsString()
|
||||||
|
name = "RunnerGroupNotFoundError"
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
message = "RunnerGroup not found!"
|
||||||
|
}
|
@ -50,6 +50,9 @@ export class RunnerOrganisationHasTeamsError extends NotAcceptableError {
|
|||||||
message = "This organisation still has teams associated with it. \n If you want to delete this organisation with all it's runners and teams ass `?force` to your query."
|
message = "This organisation still has teams associated with it. \n If you want to delete this organisation with all it's runners and teams ass `?force` to your query."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error to throw, when a provided runnerOrganisation doesn't belong to the accepted types.
|
||||||
|
*/
|
||||||
export class RunnerOrganisationWrongTypeError extends NotAcceptableError {
|
export class RunnerOrganisationWrongTypeError extends NotAcceptableError {
|
||||||
@IsString()
|
@IsString()
|
||||||
name = "RunnerOrganisationWrongTypeError"
|
name = "RunnerOrganisationWrongTypeError"
|
||||||
|
@ -1,16 +1,6 @@
|
|||||||
import { IsString } from 'class-validator';
|
import { IsString } from 'class-validator';
|
||||||
import { NotAcceptableError, NotFoundError } from 'routing-controllers';
|
import { NotAcceptableError, NotFoundError } from 'routing-controllers';
|
||||||
|
|
||||||
/**
|
|
||||||
* Error to throw when a usergroup couldn't be found.
|
|
||||||
*/
|
|
||||||
export class UserGroupNotFoundError extends NotFoundError {
|
|
||||||
@IsString()
|
|
||||||
name = "UserGroupNotFoundError"
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
message = "User Group not found!"
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error to throw when no username or email is set
|
* Error to throw when no username or email is set
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import { createConnection } from "typeorm";
|
import { createConnection } from "typeorm";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loader for the database that creates the database connection and initializes the database tabels.
|
||||||
|
*/
|
||||||
export default async () => {
|
export default async () => {
|
||||||
const connection = await createConnection();
|
const connection = await createConnection();
|
||||||
connection.synchronize();
|
connection.synchronize();
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
import { Application } from "express";
|
import { Application } from "express";
|
||||||
import bodyParser from 'body-parser';
|
|
||||||
import cors from 'cors';
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loader for express related configurations.
|
||||||
|
* Currently only enables the proxy trust.
|
||||||
|
*/
|
||||||
export default async (app: Application) => {
|
export default async (app: Application) => {
|
||||||
app.enable('trust proxy');
|
app.enable('trust proxy');
|
||||||
return app;
|
return app;
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
|
import { Application } from "express";
|
||||||
|
import databaseLoader from "./database";
|
||||||
import expressLoader from "./express";
|
import expressLoader from "./express";
|
||||||
import openapiLoader from "./openapi";
|
import openapiLoader from "./openapi";
|
||||||
import databaseLoader from "./database";
|
|
||||||
import { Application } from "express";
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Index Loader that executes the other loaders in the right order.
|
||||||
|
*/
|
||||||
export default async (app: Application) => {
|
export default async (app: Application) => {
|
||||||
await databaseLoader();
|
await databaseLoader();
|
||||||
await openapiLoader(app);
|
await openapiLoader(app);
|
||||||
|
@ -4,11 +4,16 @@ import { getMetadataArgsStorage } from "routing-controllers";
|
|||||||
import { routingControllersToSpec } from "routing-controllers-openapi";
|
import { routingControllersToSpec } from "routing-controllers-openapi";
|
||||||
import * as swaggerUiExpress from "swagger-ui-express";
|
import * as swaggerUiExpress from "swagger-ui-express";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loader for everything openapi related - from creating the schema to serving it via a static route.
|
||||||
|
*/
|
||||||
export default async (app: Application) => {
|
export default async (app: Application) => {
|
||||||
const storage = getMetadataArgsStorage();
|
const storage = getMetadataArgsStorage();
|
||||||
const schemas = validationMetadatasToSchemas({
|
const schemas = validationMetadatasToSchemas({
|
||||||
refPointerPrefix: "#/components/schemas/",
|
refPointerPrefix: "#/components/schemas/",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Spec creation based on the previously created schemas
|
||||||
const spec = routingControllersToSpec(
|
const spec = routingControllersToSpec(
|
||||||
storage,
|
storage,
|
||||||
{
|
{
|
||||||
@ -32,6 +37,8 @@ export default async (app: Application) => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//Options for swaggerUiExpress
|
||||||
const options = {
|
const options = {
|
||||||
explorer: true,
|
explorer: true,
|
||||||
};
|
};
|
||||||
|
@ -1,20 +1,14 @@
|
|||||||
import {
|
import { ExpressErrorMiddlewareInterface, Middleware } from "routing-controllers";
|
||||||
Middleware,
|
|
||||||
ExpressErrorMiddlewareInterface
|
|
||||||
} from "routing-controllers";
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Our Error handling middlware that returns our custom httperrors to the user
|
||||||
|
*/
|
||||||
@Middleware({ type: "after" })
|
@Middleware({ type: "after" })
|
||||||
export class ErrorHandler implements ExpressErrorMiddlewareInterface {
|
export class ErrorHandler implements ExpressErrorMiddlewareInterface {
|
||||||
public error(
|
public error(error: any, request: any, response: any, next: (err: any) => any) {
|
||||||
error: any,
|
|
||||||
request: any,
|
|
||||||
response: any,
|
|
||||||
next: (err: any) => any
|
|
||||||
) {
|
|
||||||
if (response.headersSent) {
|
if (response.headersSent) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
response.json(error);
|
response.json(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import { config } from '../../config';
|
|||||||
import { InvalidCredentialsError, PasswordNeededError, UserNotFoundError } from '../../errors/AuthError';
|
import { InvalidCredentialsError, PasswordNeededError, UserNotFoundError } from '../../errors/AuthError';
|
||||||
import { UsernameOrEmailNeededError } from '../../errors/UserErrors';
|
import { UsernameOrEmailNeededError } from '../../errors/UserErrors';
|
||||||
import { User } from '../entities/User';
|
import { User } from '../entities/User';
|
||||||
import { Auth } from '../responses/Auth';
|
import { Auth } from '../responses/ResponseAuth';
|
||||||
|
|
||||||
export class CreateAuth {
|
export class CreateAuth {
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@ -28,13 +28,14 @@ export class CreateAuth {
|
|||||||
if (!this.password) {
|
if (!this.password) {
|
||||||
throw new PasswordNeededError()
|
throw new PasswordNeededError()
|
||||||
}
|
}
|
||||||
const found_users = await getConnectionManager().get().getRepository(User).find({ where: [{ username: this.username }, { email: this.email }] });
|
const found_users = await getConnectionManager().get().getRepository(User).find({ relations: ['groups', 'permissions'], where: [{ username: this.username }, { email: this.email }] });
|
||||||
if (found_users.length === 0) {
|
if (found_users.length === 0) {
|
||||||
throw new UserNotFoundError()
|
throw new UserNotFoundError()
|
||||||
} else {
|
} else {
|
||||||
const found_user = found_users[0]
|
const found_user = found_users[0]
|
||||||
if (await argon2.verify(found_user.password, this.password + found_user.uuid)) {
|
if (await argon2.verify(found_user.password, this.password + found_user.uuid)) {
|
||||||
const timestamp_accesstoken_expiry = Math.floor(Date.now() / 1000) + 5 * 60
|
const timestamp_accesstoken_expiry = Math.floor(Date.now() / 1000) + 5 * 60
|
||||||
|
found_user.permissions = found_user.permissions || []
|
||||||
delete found_user.password;
|
delete found_user.password;
|
||||||
newAuth.access_token = jsonwebtoken.sign({
|
newAuth.access_token = jsonwebtoken.sign({
|
||||||
userdetails: found_user,
|
userdetails: found_user,
|
@ -1,6 +1,6 @@
|
|||||||
import { IsInt } from 'class-validator';
|
import { IsInt } from 'class-validator';
|
||||||
import { getConnectionManager } from 'typeorm';
|
import { getConnectionManager } from 'typeorm';
|
||||||
import { RunnerGroupNotFoundError } from '../../errors/RunnerErrors';
|
import { RunnerGroupNotFoundError } from '../../errors/RunnerGroupErrors';
|
||||||
import { RunnerOrganisationWrongTypeError } from '../../errors/RunnerOrganisationErrors';
|
import { RunnerOrganisationWrongTypeError } from '../../errors/RunnerOrganisationErrors';
|
||||||
import { RunnerTeamNeedsParentError } from '../../errors/RunnerTeamErrors';
|
import { RunnerTeamNeedsParentError } from '../../errors/RunnerTeamErrors';
|
||||||
import { Runner } from '../entities/Runner';
|
import { Runner } from '../entities/Runner';
|
@ -35,7 +35,12 @@ export class CreateRunnerTeam extends CreateRunnerGroup {
|
|||||||
let newRunnerTeam: RunnerTeam = new RunnerTeam();
|
let newRunnerTeam: RunnerTeam = new RunnerTeam();
|
||||||
|
|
||||||
newRunnerTeam.name = this.name;
|
newRunnerTeam.name = this.name;
|
||||||
newRunnerTeam.parentGroup = await this.getParent();
|
try {
|
||||||
|
newRunnerTeam.parentGroup = await this.getParent();
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
newRunnerTeam.contact = await this.getContact()
|
newRunnerTeam.contact = await this.getContact()
|
||||||
|
|
||||||
return newRunnerTeam;
|
return newRunnerTeam;
|
@ -2,7 +2,8 @@ import * as argon2 from "argon2";
|
|||||||
import { IsEmail, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
|
import { IsEmail, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
|
||||||
import { getConnectionManager } from 'typeorm';
|
import { getConnectionManager } from 'typeorm';
|
||||||
import * as uuid from 'uuid';
|
import * as uuid from 'uuid';
|
||||||
import { UserGroupNotFoundError, UsernameOrEmailNeededError } from '../../errors/UserErrors';
|
import { UsernameOrEmailNeededError } from '../../errors/UserErrors';
|
||||||
|
import { UserGroupNotFoundError } from '../../errors/UserGroupErrors';
|
||||||
import { User } from '../entities/User';
|
import { User } from '../entities/User';
|
||||||
import { UserGroup } from '../entities/UserGroup';
|
import { UserGroup } from '../entities/UserGroup';
|
||||||
|
|
@ -4,7 +4,7 @@ import { getConnectionManager } from 'typeorm';
|
|||||||
import { config } from '../../config';
|
import { config } from '../../config';
|
||||||
import { IllegalJWTError, JwtNotProvidedError, RefreshTokenCountInvalidError, UserNotFoundError } from '../../errors/AuthError';
|
import { IllegalJWTError, JwtNotProvidedError, RefreshTokenCountInvalidError, UserNotFoundError } from '../../errors/AuthError';
|
||||||
import { User } from '../entities/User';
|
import { User } from '../entities/User';
|
||||||
import { Logout } from '../responses/Logout';
|
import { Logout } from '../responses/ResponseLogout';
|
||||||
|
|
||||||
export class HandleLogout {
|
export class HandleLogout {
|
||||||
@IsString()
|
@IsString()
|
@ -4,7 +4,7 @@ import { getConnectionManager } from 'typeorm';
|
|||||||
import { config } from '../../config';
|
import { config } from '../../config';
|
||||||
import { IllegalJWTError, JwtNotProvidedError, RefreshTokenCountInvalidError, UserNotFoundError } from '../../errors/AuthError';
|
import { IllegalJWTError, JwtNotProvidedError, RefreshTokenCountInvalidError, UserNotFoundError } from '../../errors/AuthError';
|
||||||
import { User } from '../entities/User';
|
import { User } from '../entities/User';
|
||||||
import { Auth } from '../responses/Auth';
|
import { Auth } from '../responses/ResponseAuth';
|
||||||
|
|
||||||
export class RefreshAuth {
|
export class RefreshAuth {
|
||||||
@IsString()
|
@IsString()
|
||||||
@ -21,13 +21,14 @@ export class RefreshAuth {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new IllegalJWTError()
|
throw new IllegalJWTError()
|
||||||
}
|
}
|
||||||
const found_user = await getConnectionManager().get().getRepository(User).findOne({ id: decoded["userid"] });
|
const found_user = await getConnectionManager().get().getRepository(User).findOne({ id: decoded["userid"] }, { relations: ['groups', 'permissions'] });
|
||||||
if (!found_user) {
|
if (!found_user) {
|
||||||
throw new UserNotFoundError()
|
throw new UserNotFoundError()
|
||||||
}
|
}
|
||||||
if (found_user.refreshTokenCount !== decoded["refreshtokencount"]) {
|
if (found_user.refreshTokenCount !== decoded["refreshtokencount"]) {
|
||||||
throw new RefreshTokenCountInvalidError()
|
throw new RefreshTokenCountInvalidError()
|
||||||
}
|
}
|
||||||
|
found_user.permissions = found_user.permissions || []
|
||||||
delete found_user.password;
|
delete found_user.password;
|
||||||
const timestamp_accesstoken_expiry = Math.floor(Date.now() / 1000) + 5 * 60
|
const timestamp_accesstoken_expiry = Math.floor(Date.now() / 1000) + 5 * 60
|
||||||
delete found_user.password;
|
delete found_user.password;
|
Loading…
x
Reference in New Issue
Block a user