Browse Source

Add INACTIVE as user role

pull/3024/head
Thomas Kaul 2 years ago
parent
commit
db38f9de34
  1. 13
      apps/api/src/app/user/user.controller.ts
  2. 10
      apps/client/src/app/core/http-response.interceptor.ts
  3. 2
      prisma/migrations/20240218173439_added_inactive_to_role/migration.sql
  4. 1
      prisma/schema.prisma

13
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 { HasPermissionGuard } from '@ghostfolio/api/guards/has-permission.guard';
import { PropertyService } from '@ghostfolio/api/services/property/property.service'; import { PropertyService } from '@ghostfolio/api/services/property/property.service';
import { User, UserSettings } from '@ghostfolio/common/interfaces'; 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 type { RequestWithUser } from '@ghostfolio/common/types';
import { import {
@ -59,6 +63,13 @@ export class UserController {
public async getUser( public async getUser(
@Headers('accept-language') acceptLanguage: string @Headers('accept-language') acceptLanguage: string
): Promise<User> { ): Promise<User> {
if (hasRole(this.request.user, 'INACTIVE')) {
throw new HttpException(
getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS),
StatusCodes.TOO_MANY_REQUESTS
);
}
return this.userService.getUser( return this.userService.getUser(
this.request.user, this.request.user,
acceptLanguage?.split(',')?.[0] acceptLanguage?.split(',')?.[0]

10
apps/client/src/app/core/http-response.interceptor.ts

@ -99,6 +99,16 @@ export class HttpResponseInterceptor implements HttpInterceptor {
window.location.reload(); 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) { } else if (error.status === StatusCodes.UNAUTHORIZED) {
if (this.webAuthnService.isEnabled()) { if (this.webAuthnService.isEnabled()) {
this.router.navigate(['/webauthn']); this.router.navigate(['/webauthn']);

2
prisma/migrations/20240218173439_added_inactive_to_role/migration.sql

@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "Role" ADD VALUE 'INACTIVE';

1
prisma/schema.prisma

@ -246,6 +246,7 @@ enum Provider {
enum Role { enum Role {
ADMIN ADMIN
DEMO DEMO
INACTIVE
USER USER
} }

Loading…
Cancel
Save