Browse Source

Task/refactor asset profile deletion permissions (#6940)

Refactor permissions
main
Thomas Kaul 1 day ago
committed by GitHub
parent
commit
5689326b12
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 7
      apps/client/src/app/components/admin-market-data/admin-market-data.component.ts
  2. 4
      apps/client/src/app/components/admin-market-data/admin-market-data.html
  3. 30
      apps/client/src/app/components/admin-market-data/admin-market-data.service.ts
  4. 2
      apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts
  5. 2
      apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html
  6. 30
      libs/common/src/lib/helper.ts

7
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[] = [];

4
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 @@
<button
mat-menu-item
[disabled]="
!adminMarketDataService.hasPermissionToDeleteAssetProfile({
!canDeleteAssetProfile({
activitiesCount: element.activitiesCount,
isBenchmark: element.isBenchmark,
symbol: element.symbol

30
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
);
}
}

2
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: {

2
apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html

@ -70,7 +70,7 @@
mat-menu-item
type="button"
[disabled]="
!adminMarketDataService.hasPermissionToDeleteAssetProfile({
!canDeleteAssetProfile({
activitiesCount: assetProfile?.activitiesCount,
isBenchmark: isBenchmark,
symbol: data.symbol,

30
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();
}

Loading…
Cancel
Save