Feature/improve value redaction interceptor (#1495)

* Improve value redaction interceptor

* Update changelog
pull/1500/head
Thomas Kaul 2 years ago committed by GitHub
parent f521fe99c5
commit 2efb331370
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Improved the value redaction interceptor (including `comment`)
- Improved the language localization for Español (`es`) - Improved the language localization for Español (`es`)
- Upgraded `prisma` from version `4.6.1` to `4.7.1` - Upgraded `prisma` from version `4.6.1` to `4.7.1`

@ -6,5 +6,6 @@ export interface Activities {
export interface Activity extends OrderWithAccount { export interface Activity extends OrderWithAccount {
feeInBaseCurrency: number; feeInBaseCurrency: number;
value: number;
valueInBaseCurrency: number; valueInBaseCurrency: number;
} }

@ -1,5 +1,3 @@
import { UserService } from '@ghostfolio/api/app/user/user.service';
import { nullifyValuesInObjects } from '@ghostfolio/api/helper/object.helper';
import { RedactValuesInResponseInterceptor } from '@ghostfolio/api/interceptors/redact-values-in-response.interceptor'; import { RedactValuesInResponseInterceptor } from '@ghostfolio/api/interceptors/redact-values-in-response.interceptor';
import { TransformDataSourceInRequestInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-request.interceptor'; import { TransformDataSourceInRequestInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-request.interceptor';
import { TransformDataSourceInResponseInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-response.interceptor'; import { TransformDataSourceInResponseInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-response.interceptor';
@ -39,8 +37,7 @@ export class OrderController {
private readonly apiService: ApiService, private readonly apiService: ApiService,
private readonly impersonationService: ImpersonationService, private readonly impersonationService: ImpersonationService,
private readonly orderService: OrderService, private readonly orderService: OrderService,
@Inject(REQUEST) private readonly request: RequestWithUser, @Inject(REQUEST) private readonly request: RequestWithUser
private readonly userService: UserService
) {} ) {}
@Delete(':id') @Delete(':id')
@ -87,7 +84,7 @@ export class OrderController {
); );
const userCurrency = this.request.user.Settings.settings.baseCurrency; const userCurrency = this.request.user.Settings.settings.baseCurrency;
let activities = await this.orderService.getOrders({ const activities = await this.orderService.getOrders({
filters, filters,
userCurrency, userCurrency,
includeDrafts: true, includeDrafts: true,
@ -95,20 +92,6 @@ export class OrderController {
withExcludedAccounts: true withExcludedAccounts: true
}); });
if (
impersonationUserId ||
this.userService.isRestrictedView(this.request.user)
) {
activities = nullifyValuesInObjects(activities, [
'fee',
'feeInBaseCurrency',
'quantity',
'unitPrice',
'value',
'valueInBaseCurrency'
]);
}
return { activities }; return { activities };
} }

@ -1,4 +1,5 @@
import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface';
import { UserService } from '@ghostfolio/api/app/user/user.service';
import { import {
CallHandler, CallHandler,
ExecutionContext, ExecutionContext,
@ -12,7 +13,7 @@ import { map } from 'rxjs/operators';
export class RedactValuesInResponseInterceptor<T> export class RedactValuesInResponseInterceptor<T>
implements NestInterceptor<T, any> implements NestInterceptor<T, any>
{ {
public constructor() {} public constructor(private userService: UserService) {}
public intercept( public intercept(
context: ExecutionContext, context: ExecutionContext,
@ -23,7 +24,10 @@ export class RedactValuesInResponseInterceptor<T>
const request = context.switchToHttp().getRequest(); const request = context.switchToHttp().getRequest();
const hasImpersonationId = !!request.headers?.['impersonation-id']; const hasImpersonationId = !!request.headers?.['impersonation-id'];
if (hasImpersonationId) { if (
hasImpersonationId ||
this.userService.isRestrictedView(request.user)
) {
if (data.accounts) { if (data.accounts) {
for (const accountId of Object.keys(data.accounts)) { for (const accountId of Object.keys(data.accounts)) {
if (data.accounts[accountId]?.balance !== undefined) { if (data.accounts[accountId]?.balance !== undefined) {
@ -38,6 +42,34 @@ export class RedactValuesInResponseInterceptor<T>
activity.Account.balance = null; activity.Account.balance = null;
} }
if (activity.comment !== undefined) {
activity.comment = null;
}
if (activity.fee !== undefined) {
activity.fee = null;
}
if (activity.feeInBaseCurrency !== undefined) {
activity.feeInBaseCurrency = null;
}
if (activity.quantity !== undefined) {
activity.quantity = null;
}
if (activity.unitPrice !== undefined) {
activity.unitPrice = null;
}
if (activity.value !== undefined) {
activity.value = null;
}
if (activity.valueInBaseCurrency !== undefined) {
activity.valueInBaseCurrency = null;
}
return activity; return activity;
}); });
} }

Loading…
Cancel
Save