Added dto for Admin Panel, moved UserRole to dto
This commit is contained in:
		| @@ -1,3 +1,8 @@ | ||||
| export * as Requests from './requests'; | ||||
| export * as Responses from './responses'; | ||||
| export { validateSync, validateAsync, validateAsyncInline } from './utils'; | ||||
| export { | ||||
| 	UserRole, | ||||
| 	validateSync, | ||||
| 	validateAsync, | ||||
| 	validateAsyncInline | ||||
| } from './utils'; | ||||
|   | ||||
							
								
								
									
										17
									
								
								dto/src/requests/admin.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								dto/src/requests/admin.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| import { BaseRequest } from './base'; | ||||
| import { IsEnum, IsNumber } from 'class-validator'; | ||||
| import { UserRole } from '../utils'; | ||||
|  | ||||
| class AdminRequest extends BaseRequest { | ||||
| 	@IsNumber() | ||||
| 	user: number; | ||||
| } | ||||
|  | ||||
| export class SetUserRole extends AdminRequest { | ||||
| 	@IsEnum(UserRole) | ||||
| 	role: UserRole; | ||||
| } | ||||
|  | ||||
| export class LogoutAll extends AdminRequest {} | ||||
| export class DeleteUser extends AdminRequest {} | ||||
| export class DisableTfa extends AdminRequest {} | ||||
| @@ -1,3 +1,4 @@ | ||||
| export * from './base'; | ||||
| export * as Auth from './auth'; | ||||
| export * as FS from './fs'; | ||||
| export * as Admin from './admin'; | ||||
|   | ||||
							
								
								
									
										61
									
								
								dto/src/responses/admin.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								dto/src/responses/admin.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,61 @@ | ||||
| import { SuccessResponse } from './base'; | ||||
| import { | ||||
| 	IsArray, | ||||
| 	IsBoolean, | ||||
| 	IsEnum, | ||||
| 	IsNotEmpty, | ||||
| 	IsNumber, | ||||
| 	IsString, | ||||
| 	ValidateNested | ||||
| } from 'class-validator'; | ||||
| import { UserRole, ValidateConstructor } from '../utils'; | ||||
|  | ||||
| @ValidateConstructor | ||||
| export class GetUsersEntry { | ||||
| 	constructor( | ||||
| 		id: number, | ||||
| 		gitlab: boolean, | ||||
| 		name: string, | ||||
| 		role: UserRole, | ||||
| 		tfaEnabled: boolean | ||||
| 	) { | ||||
| 		this.id = id; | ||||
| 		this.gitlab = gitlab; | ||||
| 		this.name = name; | ||||
| 		this.role = role; | ||||
| 		this.tfaEnabled = tfaEnabled; | ||||
| 	} | ||||
|  | ||||
| 	@IsNumber() | ||||
| 	id: number; | ||||
|  | ||||
| 	@IsBoolean() | ||||
| 	gitlab: boolean; | ||||
|  | ||||
| 	@IsString() | ||||
| 	@IsNotEmpty() | ||||
| 	name: string; | ||||
|  | ||||
| 	@IsEnum(UserRole) | ||||
| 	role: UserRole; | ||||
|  | ||||
| 	@IsBoolean() | ||||
| 	tfaEnabled: boolean; | ||||
| } | ||||
|  | ||||
| @ValidateConstructor | ||||
| export class GetUsers extends SuccessResponse { | ||||
| 	constructor(users: GetUsersEntry[]) { | ||||
| 		super(); | ||||
| 		this.users = users; | ||||
| 	} | ||||
|  | ||||
| 	@IsArray() | ||||
| 	@ValidateNested({ each: true }) | ||||
| 	users: GetUsersEntry[]; | ||||
| } | ||||
|  | ||||
| export class LogoutAllUser extends SuccessResponse {} | ||||
| export class DeleteUser extends SuccessResponse {} | ||||
| export class SetUserRole extends SuccessResponse {} | ||||
| export class DisableTfa extends SuccessResponse {} | ||||
| @@ -2,3 +2,4 @@ export * from './base'; | ||||
| export * as Auth from './auth'; | ||||
| export * as FS from './fs'; | ||||
| export * as User from './user'; | ||||
| export * as Admin from './admin'; | ||||
|   | ||||
| @@ -1,5 +1,11 @@ | ||||
| import { validate, validateSync as _validateSync } from 'class-validator'; | ||||
|  | ||||
| export enum UserRole { | ||||
| 	ADMIN = 2, | ||||
| 	USER = 1, | ||||
| 	DISABLED = 0 | ||||
| } | ||||
|  | ||||
| export function validateSync<T extends object>(data: T): void { | ||||
| 	const errors = _validateSync(data); | ||||
| 	if (errors.length > 0) { | ||||
|   | ||||
| @@ -1,12 +1,13 @@ | ||||
| import { Controller, Get, Module } from '@nestjs/common'; | ||||
| import { TypeOrmModule } from '@nestjs/typeorm'; | ||||
| import { INode, JWTToken, User, UserRole } from './entities'; | ||||
| import { INode, JWTToken, User } from './entities'; | ||||
| import FileSystemModule from './modules/filesystem'; | ||||
| import { JWTAuthGuard, Role, RoleGuard } from './authguards'; | ||||
| import AuthModule from './modules/auth'; | ||||
| import { ServeStaticModule } from '@nestjs/serve-static'; | ||||
| import { join } from 'path'; | ||||
| import { cwd } from 'process'; | ||||
| import { UserRole } from 'dto'; | ||||
|  | ||||
| declare const PROD: boolean | undefined; | ||||
|  | ||||
|   | ||||
| @@ -6,7 +6,8 @@ import { | ||||
| } from '@nestjs/common'; | ||||
| import { AuthGuard } from '@nestjs/passport'; | ||||
| import { Reflector } from '@nestjs/core'; | ||||
| import { User, UserRole } from './entities'; | ||||
| import { User } from './entities'; | ||||
| import { UserRole } from 'dto'; | ||||
|  | ||||
| const IS_PUBLIC_KEY = 'isPublic'; | ||||
| export const Public = () => SetMetadata(IS_PUBLIC_KEY, true); | ||||
|   | ||||
| @@ -9,9 +9,8 @@ import { | ||||
| 	StreamableFile, | ||||
| 	ValidationPipe | ||||
| } from '@nestjs/common'; | ||||
| import { Responses, Requests, validateAsyncInline } from 'dto'; | ||||
| import { Responses, Requests, validateAsyncInline, UserRole } from 'dto'; | ||||
| import FileSystemService from 'services/filesystem'; | ||||
| import { UserRole } from 'entities'; | ||||
| import { Role } from 'authguards'; | ||||
|  | ||||
| @Controller('api/fs') | ||||
|   | ||||
| @@ -6,12 +6,7 @@ import { | ||||
| 	OneToMany, | ||||
| 	OneToOne | ||||
| } from 'typeorm'; | ||||
|  | ||||
| export enum UserRole { | ||||
| 	ADMIN = 2, | ||||
| 	USER = 1, | ||||
| 	DISABLED = 0 | ||||
| } | ||||
| import { UserRole } from 'dto'; | ||||
|  | ||||
| export enum tfaTypes { | ||||
| 	NONE = 0, | ||||
|   | ||||
| @@ -4,11 +4,12 @@ import { | ||||
| 	UnauthorizedException | ||||
| } from '@nestjs/common'; | ||||
| import { InjectRepository } from '@nestjs/typeorm'; | ||||
| import { JWTToken, User, UserRole } from 'entities'; | ||||
| import { JWTToken, User } from 'entities'; | ||||
| import { LessThanOrEqual, Repository } from 'typeorm'; | ||||
| import * as argon2 from 'argon2'; | ||||
| import FileSystemService from 'services/filesystem'; | ||||
| import * as jwt from 'jsonwebtoken'; | ||||
| import { UserRole } from 'dto'; | ||||
|  | ||||
| export const jwtSecret = 'CUM'; | ||||
|  | ||||
|   | ||||
| @@ -1,9 +1,10 @@ | ||||
| import { User, UserRole } from 'entities'; | ||||
| import { User } from 'entities'; | ||||
| import { FastifyRequest } from 'fastify'; | ||||
| import axios from 'axios'; | ||||
| import * as argon2 from 'argon2'; | ||||
| import { ForbiddenException, UnauthorizedException } from '@nestjs/common'; | ||||
| import TfaAuthService from './tfa'; | ||||
| import { UserRole } from 'dto'; | ||||
|  | ||||
| const GITLAB_ID = | ||||
| 	'98bcbad78cb1f880d1d1de62291d70a791251a7bea077bfe7df111ef3c115760'; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user