mirror of https://github.com/ghostfolio/ghostfolio
underwater
1 year ago
committed by
GitHub
22 changed files with 172 additions and 545 deletions
@ -1,87 +1,48 @@ |
|||
import { HasPermission } from '@ghostfolio/api/decorators/has-permission.decorator'; |
|||
import { HasPermissionGuard } from '@ghostfolio/api/guards/has-permission.guard'; |
|||
import { AdminJobs } from '@ghostfolio/common/interfaces'; |
|||
import { hasPermission, permissions } from '@ghostfolio/common/permissions'; |
|||
import type { RequestWithUser } from '@ghostfolio/common/types'; |
|||
import { permissions } from '@ghostfolio/common/permissions'; |
|||
import { |
|||
Controller, |
|||
Delete, |
|||
Get, |
|||
HttpException, |
|||
Inject, |
|||
Param, |
|||
Query, |
|||
UseGuards |
|||
} from '@nestjs/common'; |
|||
import { REQUEST } from '@nestjs/core'; |
|||
import { AuthGuard } from '@nestjs/passport'; |
|||
import { JobStatus } from 'bull'; |
|||
import { StatusCodes, getReasonPhrase } from 'http-status-codes'; |
|||
|
|||
import { QueueService } from './queue.service'; |
|||
|
|||
@Controller('admin/queue') |
|||
export class QueueController { |
|||
public constructor( |
|||
private readonly queueService: QueueService, |
|||
@Inject(REQUEST) private readonly request: RequestWithUser |
|||
) {} |
|||
public constructor(private readonly queueService: QueueService) {} |
|||
|
|||
@Delete('job') |
|||
@UseGuards(AuthGuard('jwt')) |
|||
@HasPermission(permissions.accessAdminControl) |
|||
@UseGuards(AuthGuard('jwt'), HasPermissionGuard) |
|||
public async deleteJobs( |
|||
@Query('status') filterByStatus?: string |
|||
): Promise<void> { |
|||
if ( |
|||
!hasPermission( |
|||
this.request.user.permissions, |
|||
permissions.accessAdminControl |
|||
) |
|||
) { |
|||
throw new HttpException( |
|||
getReasonPhrase(StatusCodes.FORBIDDEN), |
|||
StatusCodes.FORBIDDEN |
|||
); |
|||
} |
|||
|
|||
const status = <JobStatus[]>filterByStatus?.split(',') ?? undefined; |
|||
return this.queueService.deleteJobs({ status }); |
|||
} |
|||
|
|||
@Get('job') |
|||
@UseGuards(AuthGuard('jwt')) |
|||
@HasPermission(permissions.accessAdminControl) |
|||
@UseGuards(AuthGuard('jwt'), HasPermissionGuard) |
|||
public async getJobs( |
|||
@Query('status') filterByStatus?: string |
|||
): Promise<AdminJobs> { |
|||
if ( |
|||
!hasPermission( |
|||
this.request.user.permissions, |
|||
permissions.accessAdminControl |
|||
) |
|||
) { |
|||
throw new HttpException( |
|||
getReasonPhrase(StatusCodes.FORBIDDEN), |
|||
StatusCodes.FORBIDDEN |
|||
); |
|||
} |
|||
|
|||
const status = <JobStatus[]>filterByStatus?.split(',') ?? undefined; |
|||
return this.queueService.getJobs({ status }); |
|||
} |
|||
|
|||
@Delete('job/:id') |
|||
@UseGuards(AuthGuard('jwt')) |
|||
@HasPermission(permissions.accessAdminControl) |
|||
@UseGuards(AuthGuard('jwt'), HasPermissionGuard) |
|||
public async deleteJob(@Param('id') id: string): Promise<void> { |
|||
if ( |
|||
!hasPermission( |
|||
this.request.user.permissions, |
|||
permissions.accessAdminControl |
|||
) |
|||
) { |
|||
throw new HttpException( |
|||
getReasonPhrase(StatusCodes.FORBIDDEN), |
|||
StatusCodes.FORBIDDEN |
|||
); |
|||
} |
|||
|
|||
return this.queueService.deleteJob(id); |
|||
} |
|||
} |
|||
|
@ -1,40 +1,18 @@ |
|||
import { AuthDeviceService } from '@ghostfolio/api/app/auth-device/auth-device.service'; |
|||
import { hasPermission, permissions } from '@ghostfolio/common/permissions'; |
|||
import type { RequestWithUser } from '@ghostfolio/common/types'; |
|||
import { |
|||
Controller, |
|||
Delete, |
|||
HttpException, |
|||
Inject, |
|||
Param, |
|||
UseGuards |
|||
} from '@nestjs/common'; |
|||
import { REQUEST } from '@nestjs/core'; |
|||
import { HasPermission } from '@ghostfolio/api/decorators/has-permission.decorator'; |
|||
import { HasPermissionGuard } from '@ghostfolio/api/guards/has-permission.guard'; |
|||
import { permissions } from '@ghostfolio/common/permissions'; |
|||
import { Controller, Delete, Param, UseGuards } from '@nestjs/common'; |
|||
import { AuthGuard } from '@nestjs/passport'; |
|||
import { StatusCodes, getReasonPhrase } from 'http-status-codes'; |
|||
|
|||
@Controller('auth-device') |
|||
export class AuthDeviceController { |
|||
public constructor( |
|||
private readonly authDeviceService: AuthDeviceService, |
|||
@Inject(REQUEST) private readonly request: RequestWithUser |
|||
) {} |
|||
public constructor(private readonly authDeviceService: AuthDeviceService) {} |
|||
|
|||
@Delete(':id') |
|||
@UseGuards(AuthGuard('jwt')) |
|||
@HasPermission(permissions.deleteAuthDevice) |
|||
@UseGuards(AuthGuard('jwt'), HasPermissionGuard) |
|||
public async deleteAuthDevice(@Param('id') id: string): Promise<void> { |
|||
if ( |
|||
!hasPermission( |
|||
this.request.user.permissions, |
|||
permissions.deleteAuthDevice |
|||
) |
|||
) { |
|||
throw new HttpException( |
|||
getReasonPhrase(StatusCodes.FORBIDDEN), |
|||
StatusCodes.FORBIDDEN |
|||
); |
|||
} |
|||
|
|||
await this.authDeviceService.deleteAuthDevice({ id }); |
|||
} |
|||
} |
|||
|
@ -1,39 +1,18 @@ |
|||
import { RedisCacheService } from '@ghostfolio/api/app/redis-cache/redis-cache.service'; |
|||
import { hasPermission, permissions } from '@ghostfolio/common/permissions'; |
|||
import type { RequestWithUser } from '@ghostfolio/common/types'; |
|||
import { |
|||
Controller, |
|||
HttpException, |
|||
Inject, |
|||
Post, |
|||
UseGuards |
|||
} from '@nestjs/common'; |
|||
import { REQUEST } from '@nestjs/core'; |
|||
import { HasPermission } from '@ghostfolio/api/decorators/has-permission.decorator'; |
|||
import { HasPermissionGuard } from '@ghostfolio/api/guards/has-permission.guard'; |
|||
import { permissions } from '@ghostfolio/common/permissions'; |
|||
import { Controller, Post, UseGuards } from '@nestjs/common'; |
|||
import { AuthGuard } from '@nestjs/passport'; |
|||
import { StatusCodes, getReasonPhrase } from 'http-status-codes'; |
|||
|
|||
@Controller('cache') |
|||
export class CacheController { |
|||
public constructor( |
|||
private readonly redisCacheService: RedisCacheService, |
|||
@Inject(REQUEST) private readonly request: RequestWithUser |
|||
) {} |
|||
public constructor(private readonly redisCacheService: RedisCacheService) {} |
|||
|
|||
@HasPermission(permissions.accessAdminControl) |
|||
@Post('flush') |
|||
@UseGuards(AuthGuard('jwt')) |
|||
@UseGuards(AuthGuard('jwt'), HasPermissionGuard) |
|||
public async flushCache(): Promise<void> { |
|||
if ( |
|||
!hasPermission( |
|||
this.request.user.permissions, |
|||
permissions.accessAdminControl |
|||
) |
|||
) { |
|||
throw new HttpException( |
|||
getReasonPhrase(StatusCodes.FORBIDDEN), |
|||
StatusCodes.FORBIDDEN |
|||
); |
|||
} |
|||
|
|||
return this.redisCacheService.reset(); |
|||
} |
|||
} |
|||
|
Loading…
Reference in new issue