From be7f6bb6576e4788d5a9a31674923afd1c360573 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 18 Feb 2024 18:54:49 +0100 Subject: [PATCH] Feature/add inactive as user role (#3024) * Add INACTIVE as user role * Update changelog --- CHANGELOG.md | 6 ++++++ apps/api/src/app/user/user.controller.ts | 13 ++++++++++++- .../src/app/core/http-response.interceptor.ts | 10 ++++++++++ .../migration.sql | 2 ++ prisma/schema.prisma | 1 + 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 prisma/migrations/20240218173439_added_inactive_to_role/migration.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d8c18d50..d1c9a4dde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Added + +- Added `INACTIVE` as a new user role + ## 2.53.0 - 2024-02-18 ### Added diff --git a/apps/api/src/app/user/user.controller.ts b/apps/api/src/app/user/user.controller.ts index cf332b2e8..541c7b178 100644 --- a/apps/api/src/app/user/user.controller.ts +++ b/apps/api/src/app/user/user.controller.ts @@ -2,7 +2,11 @@ import { HasPermission } from '@ghostfolio/api/decorators/has-permission.decorat import { HasPermissionGuard } from '@ghostfolio/api/guards/has-permission.guard'; import { PropertyService } from '@ghostfolio/api/services/property/property.service'; import { User, UserSettings } from '@ghostfolio/common/interfaces'; -import { hasPermission, permissions } from '@ghostfolio/common/permissions'; +import { + hasPermission, + hasRole, + permissions +} from '@ghostfolio/common/permissions'; import type { RequestWithUser } from '@ghostfolio/common/types'; import { @@ -59,6 +63,13 @@ export class UserController { public async getUser( @Headers('accept-language') acceptLanguage: string ): Promise { + if (hasRole(this.request.user, 'INACTIVE')) { + throw new HttpException( + getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS), + StatusCodes.TOO_MANY_REQUESTS + ); + } + return this.userService.getUser( this.request.user, acceptLanguage?.split(',')?.[0] diff --git a/apps/client/src/app/core/http-response.interceptor.ts b/apps/client/src/app/core/http-response.interceptor.ts index 193359848..15a0d2e9f 100644 --- a/apps/client/src/app/core/http-response.interceptor.ts +++ b/apps/client/src/app/core/http-response.interceptor.ts @@ -99,6 +99,16 @@ export class HttpResponseInterceptor implements HttpInterceptor { window.location.reload(); }); } + } else if (error.status === StatusCodes.TOO_MANY_REQUESTS) { + if (!this.snackBarRef) { + this.snackBarRef = this.snackBar.open( + $localize`Oops! It looks like you’re making too many requests. Please slow down a bit.` + ); + + this.snackBarRef.afterDismissed().subscribe(() => { + this.snackBarRef = undefined; + }); + } } else if (error.status === StatusCodes.UNAUTHORIZED) { if (this.webAuthnService.isEnabled()) { this.router.navigate(['/webauthn']); diff --git a/prisma/migrations/20240218173439_added_inactive_to_role/migration.sql b/prisma/migrations/20240218173439_added_inactive_to_role/migration.sql new file mode 100644 index 000000000..0070382b6 --- /dev/null +++ b/prisma/migrations/20240218173439_added_inactive_to_role/migration.sql @@ -0,0 +1,2 @@ +-- AlterEnum +ALTER TYPE "Role" ADD VALUE 'INACTIVE'; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index a5a57d8c0..615610fa3 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -246,6 +246,7 @@ enum Provider { enum Role { ADMIN DEMO + INACTIVE USER }