Browse Source

Restrict symbol data endpoint to authenticated users

pull/7372/head
Thomas Kaul 2 months ago
parent
commit
ca7e835b0d
  1. 28
      apps/api/src/app/info/info.service.ts
  2. 6
      apps/client/src/app/components/home-market/home-market.component.ts
  3. 2
      apps/client/src/app/components/home-market/home-market.html
  4. 4
      apps/client/src/app/components/home-market/home-market.scss
  5. 3
      libs/common/src/lib/interfaces/info-item.interface.ts

28
apps/api/src/app/info/info.service.ts

@ -1,7 +1,6 @@
import { RedisCacheService } from '@ghostfolio/api/app/redis-cache/redis-cache.service'; import { RedisCacheService } from '@ghostfolio/api/app/redis-cache/redis-cache.service';
import { SubscriptionService } from '@ghostfolio/api/app/subscription/subscription.service'; import { SubscriptionService } from '@ghostfolio/api/app/subscription/subscription.service';
import { UserService } from '@ghostfolio/api/app/user/user.service'; import { UserService } from '@ghostfolio/api/app/user/user.service';
import { encodeDataSource } from '@ghostfolio/api/helper/data-source.helper';
import { BenchmarkService } from '@ghostfolio/api/services/benchmark/benchmark.service'; import { BenchmarkService } from '@ghostfolio/api/services/benchmark/benchmark.service';
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service';
import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service'; import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service';
@ -25,6 +24,7 @@ import { permissions } from '@ghostfolio/common/permissions';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt'; import { JwtService } from '@nestjs/jwt';
import { MarketData } from '@prisma/client';
import { subDays } from 'date-fns'; import { subDays } from 'date-fns';
import { isNil } from 'lodash'; import { isNil } from 'lodash';
@ -48,6 +48,7 @@ export class InfoService {
public async get(): Promise<InfoItem> { public async get(): Promise<InfoItem> {
const info: Partial<InfoItem> = {}; const info: Partial<InfoItem> = {};
let isReadOnlyMode: boolean; let isReadOnlyMode: boolean;
let latestFearAndGreedStocksMarketDataPromise: Promise<MarketData>;
const globalPermissions: string[] = []; const globalPermissions: string[] = [];
@ -64,24 +65,13 @@ export class InfoService {
} }
if (this.configurationService.get('ENABLE_FEATURE_FEAR_AND_GREED_INDEX')) { if (this.configurationService.get('ENABLE_FEATURE_FEAR_AND_GREED_INDEX')) {
const fearAndGreedIndexDataSource = latestFearAndGreedStocksMarketDataPromise =
this.dataProviderService.getDataSourceForFearAndGreedIndexStocks(); this.marketDataService.getLatest({
dataSource:
if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) { this.dataProviderService.getDataSourceForFearAndGreedIndexStocks(),
info.fearAndGreedDataSource = encodeDataSource(
fearAndGreedIndexDataSource
);
} else {
info.fearAndGreedDataSource = fearAndGreedIndexDataSource;
}
const latestMarketData = await this.marketDataService.getLatest({
dataSource: fearAndGreedIndexDataSource,
symbol: ghostfolioFearAndGreedIndexSymbolStocks symbol: ghostfolioFearAndGreedIndexSymbolStocks
}); });
info.fearAndGreedMarketPrice = latestMarketData?.marketPrice;
globalPermissions.push(permissions.enableFearAndGreedIndex); globalPermissions.push(permissions.enableFearAndGreedIndex);
} }
@ -112,12 +102,14 @@ export class InfoService {
benchmarks, benchmarks,
demoAuthToken, demoAuthToken,
isUserSignupEnabled, isUserSignupEnabled,
latestFearAndGreedStocksMarketData,
statistics, statistics,
subscriptionOffer subscriptionOffer
] = await Promise.all([ ] = await Promise.all([
this.benchmarkService.getBenchmarkAssetProfiles(), this.benchmarkService.getBenchmarkAssetProfiles(),
this.getDemoAuthToken(), this.getDemoAuthToken(),
this.propertyService.isUserSignupEnabled(), this.propertyService.isUserSignupEnabled(),
latestFearAndGreedStocksMarketDataPromise,
this.getStatistics(), this.getStatistics(),
this.subscriptionService.getSubscriptionOffer({ key: 'default' }) this.subscriptionService.getSubscriptionOffer({ key: 'default' })
]); ]);
@ -135,7 +127,9 @@ export class InfoService {
statistics, statistics,
subscriptionOffer, subscriptionOffer,
baseCurrency: DEFAULT_CURRENCY, baseCurrency: DEFAULT_CURRENCY,
currencies: this.exchangeRateDataService.getCurrencies() currencies: this.exchangeRateDataService.getCurrencies(),
fearAndGreedStocksMarketPrice:
latestFearAndGreedStocksMarketData?.marketPrice
}; };
} }

6
apps/client/src/app/components/home-market/home-market.component.ts

@ -29,10 +29,12 @@ import { DeviceDetectorService } from 'ngx-device-detector';
}) })
export class GfHomeMarketComponent implements OnInit { export class GfHomeMarketComponent implements OnInit {
protected readonly benchmarks = signal<Benchmark[]>([]); protected readonly benchmarks = signal<Benchmark[]>([]);
protected readonly deviceType = computed( protected readonly deviceType = computed(
() => this.deviceDetectorService.deviceInfo().deviceType () => this.deviceDetectorService.deviceInfo().deviceType
); );
protected readonly fearAndGreedIndex = signal<number | undefined>(undefined);
protected fearAndGreedIndex: number | undefined;
protected hasPermissionToAccessFearAndGreedIndex: boolean; protected hasPermissionToAccessFearAndGreedIndex: boolean;
protected user: User; protected user: User;
@ -65,7 +67,7 @@ export class GfHomeMarketComponent implements OnInit {
); );
if (this.hasPermissionToAccessFearAndGreedIndex) { if (this.hasPermissionToAccessFearAndGreedIndex) {
this.fearAndGreedIndex.set(this.info.fearAndGreedMarketPrice); this.fearAndGreedIndex = this.info.fearAndGreedStocksMarketPrice;
} }
this.dataService this.dataService

2
apps/client/src/app/components/home-market/home-market.html

@ -5,7 +5,7 @@
<div class="col-xs-12 col-md-10 offset-md-1"> <div class="col-xs-12 col-md-10 offset-md-1">
<gf-fear-and-greed-index <gf-fear-and-greed-index
class="d-flex justify-content-center" class="d-flex justify-content-center"
[fearAndGreedIndex]="fearAndGreedIndex()" [fearAndGreedIndex]="fearAndGreedIndex"
/> />
</div> </div>
</div> </div>

4
apps/client/src/app/components/home-market/home-market.scss

@ -1,7 +1,3 @@
:host { :host {
display: block; display: block;
gf-line-chart {
aspect-ratio: 16 / 9;
}
} }

3
libs/common/src/lib/interfaces/info-item.interface.ts

@ -9,8 +9,7 @@ export interface InfoItem {
countriesOfSubscribers?: string[]; countriesOfSubscribers?: string[];
currencies: string[]; currencies: string[];
demoAuthToken: string; demoAuthToken: string;
fearAndGreedDataSource?: string; fearAndGreedStocksMarketPrice?: number;
fearAndGreedMarketPrice?: number;
globalPermissions: string[]; globalPermissions: string[];
isDataGatheringEnabled?: string; isDataGatheringEnabled?: string;
isReadOnlyMode?: boolean; isReadOnlyMode?: boolean;

Loading…
Cancel
Save