Feature/improve inactive user role (#3360)
* Improve inactive role * Update changelog
This commit is contained in:
parent
4416ba0c88
commit
0a53df4293
@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
- Set the performance column of the holdings table to stick at the end
|
- Set the performance column of the holdings table to stick at the end
|
||||||
- Skipped the caching in the portfolio calculator if there are active filters (experimental)
|
- Skipped the caching in the portfolio calculator if there are active filters (experimental)
|
||||||
|
- Improved the `INACTIVE` user role
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
@ -2,10 +2,12 @@ import { UserService } from '@ghostfolio/api/app/user/user.service';
|
|||||||
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service';
|
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service';
|
||||||
import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service';
|
import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service';
|
||||||
import { HEADER_KEY_TIMEZONE } from '@ghostfolio/common/config';
|
import { HEADER_KEY_TIMEZONE } from '@ghostfolio/common/config';
|
||||||
|
import { hasRole } from '@ghostfolio/common/permissions';
|
||||||
|
|
||||||
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
import { HttpException, Injectable } from '@nestjs/common';
|
||||||
import { PassportStrategy } from '@nestjs/passport';
|
import { PassportStrategy } from '@nestjs/passport';
|
||||||
import * as countriesAndTimezones from 'countries-and-timezones';
|
import * as countriesAndTimezones from 'countries-and-timezones';
|
||||||
|
import { StatusCodes, getReasonPhrase } from 'http-status-codes';
|
||||||
import { ExtractJwt, Strategy } from 'passport-jwt';
|
import { ExtractJwt, Strategy } from 'passport-jwt';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -29,6 +31,13 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
|
|||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) {
|
if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) {
|
||||||
|
if (hasRole(user, 'INACTIVE')) {
|
||||||
|
throw new HttpException(
|
||||||
|
getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS),
|
||||||
|
StatusCodes.TOO_MANY_REQUESTS
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const country =
|
const country =
|
||||||
countriesAndTimezones.getCountryForTimezone(timezone)?.id;
|
countriesAndTimezones.getCountryForTimezone(timezone)?.id;
|
||||||
|
|
||||||
@ -45,10 +54,20 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
|
|||||||
|
|
||||||
return user;
|
return user;
|
||||||
} else {
|
} else {
|
||||||
throw '';
|
throw new HttpException(
|
||||||
|
getReasonPhrase(StatusCodes.NOT_FOUND),
|
||||||
|
StatusCodes.NOT_FOUND
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (error?.getStatus() === StatusCodes.TOO_MANY_REQUESTS) {
|
||||||
|
throw error;
|
||||||
|
} else {
|
||||||
|
throw new HttpException(
|
||||||
|
getReasonPhrase(StatusCodes.UNAUTHORIZED),
|
||||||
|
StatusCodes.UNAUTHORIZED
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
|
||||||
throw new UnauthorizedException('unauthorized', err.message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,7 @@ 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 {
|
import { hasPermission, permissions } from '@ghostfolio/common/permissions';
|
||||||
hasPermission,
|
|
||||||
hasRole,
|
|
||||||
permissions
|
|
||||||
} from '@ghostfolio/common/permissions';
|
|
||||||
import type { RequestWithUser } from '@ghostfolio/common/types';
|
import type { RequestWithUser } from '@ghostfolio/common/types';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -63,13 +59,6 @@ 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]
|
||||||
|
@ -54,9 +54,10 @@ export class AuthGuard {
|
|||||||
this.router.navigate(['/' + $localize`register`]);
|
this.router.navigate(['/' + $localize`register`]);
|
||||||
resolve(false);
|
resolve(false);
|
||||||
} else if (
|
} else if (
|
||||||
AuthGuard.PUBLIC_PAGE_ROUTES.filter((publicPageRoute) =>
|
AuthGuard.PUBLIC_PAGE_ROUTES.filter((publicPageRoute) => {
|
||||||
state.url.startsWith(publicPageRoute)
|
const [, url] = state.url.split('/');
|
||||||
)?.length > 0
|
return `/${url}` === publicPageRoute;
|
||||||
|
})?.length > 0
|
||||||
) {
|
) {
|
||||||
resolve(true);
|
resolve(true);
|
||||||
return EMPTY;
|
return EMPTY;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user