Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Task/refactor asset profile deletion permissions (#6940)
Thomas Kaul5689326b1296
diff --git a/apps/client/src/app/components/admin-market-data/admin-market-data.component.ts b/apps/client/src/app/components/admin-market-data/admin-market-data.component.tsindex 72a3c337ac..28b7297d20 100644--- a/apps/client/src/app/components/admin-market-data/admin-market-data.component.ts+++ b/apps/client/src/app/components/admin-market-data/admin-market-data.component.ts@@ -4,7 +4,10 @@ import {DEFAULT_PAGE_SIZE,locale} from '@ghostfolio/common/config';-import { getDateFormatString } from '@ghostfolio/common/helper';+import {+ canDeleteAssetProfile,+ getDateFormatString+} from '@ghostfolio/common/helper';import {AssetProfileIdentifier,Filter,@@ -101,6 +104,7 @@ import { CreateAssetProfileDialogParams } from './create-asset-profile-dialog/in})export class GfAdminMarketDataComponent implements AfterViewInit, OnInit {protected readonly adminMarketDataService = inject(AdminMarketDataService);+protected readonly allFilters: Filter[] = [...Object.keys(AssetSubClass).filter((assetSubClass) => {@@ -146,6 +150,7 @@ export class GfAdminMarketDataComponent implements AfterViewInit, OnInit {type: 'PRESET_ID' as Filter['type']}];+ protected readonly canDeleteAssetProfile = canDeleteAssetProfile;protected dataSource = new MatTableDataSource<AdminMarketDataItem>();protected defaultDateFormat: string;protected readonly displayedColumns: string[] = [];diff --git a/apps/client/src/app/components/admin-market-data/admin-market-data.html b/apps/client/src/app/components/admin-market-data/admin-market-data.htmlindex e2c6d1a87c..14d12627d1 100644--- a/apps/client/src/app/components/admin-market-data/admin-market-data.html+++ b/apps/client/src/app/components/admin-market-data/admin-market-data.html@@ -52,7 +52,7 @@<th *matHeaderCellDef class="px-1" mat-header-cell></th><td *matCellDef="let element" class="px-1" mat-cell>@if (- adminMarketDataService.hasPermissionToDeleteAssetProfile({+ canDeleteAssetProfile({activitiesCount: element.activitiesCount,isBenchmark: element.isBenchmark,symbol: element.symbol,@@ -271,7 +271,7 @@<buttonmat-menu-item[disabled]="- !adminMarketDataService.hasPermissionToDeleteAssetProfile({+ !canDeleteAssetProfile({activitiesCount: element.activitiesCount,isBenchmark: element.isBenchmark,symbol: element.symboldiff --git a/apps/client/src/app/components/admin-market-data/admin-market-data.service.ts b/apps/client/src/app/components/admin-market-data/admin-market-data.service.tsindex 9528687a83..77e2151efb 100644--- a/apps/client/src/app/components/admin-market-data/admin-market-data.service.ts+++ b/apps/client/src/app/components/admin-market-data/admin-market-data.service.ts@@ -1,14 +1,5 @@-import { ghostfolioScraperApiSymbolPrefix } from '@ghostfolio/common/config';import { ConfirmationDialogType } from '@ghostfolio/common/enums';-import {- getCurrencyFromSymbol,- isDerivedCurrency,- isRootCurrency-} from '@ghostfolio/common/helper';-import {- AssetProfileIdentifier,- AdminMarketDataItem-} from '@ghostfolio/common/interfaces';+import { AssetProfileIdentifier } from '@ghostfolio/common/interfaces';import { NotificationService } from '@ghostfolio/ui/notifications';import { AdminService } from '@ghostfolio/ui/services';@@ -68,23 +59,4 @@ export class AdminMarketDataService {title: $localize`Do you really want to delete these profiles?`});}-- public hasPermissionToDeleteAssetProfile({- activitiesCount,- isBenchmark,- symbol,- watchedByCount- }: Pick<- AdminMarketDataItem,- 'activitiesCount' | 'isBenchmark' | 'symbol' | 'watchedByCount'- >) {- return (- activitiesCount === 0 &&- !isBenchmark &&- !isDerivedCurrency(getCurrencyFromSymbol(symbol)) &&- !isRootCurrency(getCurrencyFromSymbol(symbol)) &&- !symbol.startsWith(ghostfolioScraperApiSymbolPrefix) &&- watchedByCount === 0- );- }}diff --git a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.tsindex f0721c87fc..560a00164b 100644--- a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts+++ b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts@@ -6,6 +6,7 @@ import {} from '@ghostfolio/common/config';import { UpdateAssetProfileDto } from '@ghostfolio/common/dtos';import {+ canDeleteAssetProfile,DATE_FORMAT,getCurrencyFromSymbol,isCurrency@@ -188,6 +189,7 @@ export class GfAssetProfileDialogComponent implements OnInit {});+ protected readonly canDeleteAssetProfile = canDeleteAssetProfile;protected canEditAssetProfile = true;protected countries: {diff --git a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.htmlindex a145469736..b2a7e0a05d 100644--- a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html+++ b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html@@ -70,7 +70,7 @@mat-menu-itemtype="button"[disabled]="- !adminMarketDataService.hasPermissionToDeleteAssetProfile({+ !canDeleteAssetProfile({activitiesCount: assetProfile?.activitiesCount,isBenchmark: isBenchmark,symbol: data.symbol,diff --git a/libs/common/src/lib/helper.ts b/libs/common/src/lib/helper.tsindex cbaf657dd4..c5f6cbbb99 100644--- a/libs/common/src/lib/helper.ts+++ b/libs/common/src/lib/helper.ts@@ -30,10 +30,17 @@ import { get, isNil, isString } from 'lodash';import {DEFAULT_CURRENCY,DERIVED_CURRENCIES,+ ghostfolioFearAndGreedIndexSymbol,+ ghostfolioFearAndGreedIndexSymbolCryptocurrencies,+ ghostfolioFearAndGreedIndexSymbolStocks,ghostfolioScraperApiSymbolPrefix,locale} from './config';-import { AssetProfileIdentifier, Benchmark } from './interfaces';+import {+ AdminMarketDataItem,+ AssetProfileIdentifier,+ Benchmark+} from './interfaces';import { BenchmarkTrend, ColorScheme } from './types';export const DATE_FORMAT = 'yyyy-MM-dd';@@ -93,6 +100,27 @@ export function calculateMovingAverage({.toNumber();}+export function canDeleteAssetProfile({+ activitiesCount,+ isBenchmark,+ symbol,+ watchedByCount+}: Pick<+ AdminMarketDataItem,+ 'activitiesCount' | 'isBenchmark' | 'symbol' | 'watchedByCount'+>): boolean {+ return (+ activitiesCount === 0 &&+ !isBenchmark &&+ !isDerivedCurrency(getCurrencyFromSymbol(symbol)) &&+ !isRootCurrency(getCurrencyFromSymbol(symbol)) &&+ symbol !== ghostfolioFearAndGreedIndexSymbol &&+ symbol !== ghostfolioFearAndGreedIndexSymbolCryptocurrencies &&+ symbol !== ghostfolioFearAndGreedIndexSymbolStocks &&+ watchedByCount === 0+ );+}+export function capitalize(aString: string) {return aString.charAt(0).toUpperCase() + aString.slice(1).toLowerCase();}