Browse Source

Restrict symbol data endpoint to authenticated users

pull/7372/head
Thomas Kaul 1 month ago
parent
commit
ca7e835b0d
  1. 32
      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

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

@ -1,7 +1,6 @@
import { RedisCacheService } from '@ghostfolio/api/app/redis-cache/redis-cache.service';
import { SubscriptionService } from '@ghostfolio/api/app/subscription/subscription.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 { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.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 { JwtService } from '@nestjs/jwt';
import { MarketData } from '@prisma/client';
import { subDays } from 'date-fns';
import { isNil } from 'lodash';
@ -48,6 +48,7 @@ export class InfoService {
public async get(): Promise<InfoItem> {
const info: Partial<InfoItem> = {};
let isReadOnlyMode: boolean;
let latestFearAndGreedStocksMarketDataPromise: Promise<MarketData>;
const globalPermissions: string[] = [];
@ -64,23 +65,12 @@ export class InfoService {
}
if (this.configurationService.get('ENABLE_FEATURE_FEAR_AND_GREED_INDEX')) {
const fearAndGreedIndexDataSource =
this.dataProviderService.getDataSourceForFearAndGreedIndexStocks();
if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) {
info.fearAndGreedDataSource = encodeDataSource(
fearAndGreedIndexDataSource
);
} else {
info.fearAndGreedDataSource = fearAndGreedIndexDataSource;
}
const latestMarketData = await this.marketDataService.getLatest({
dataSource: fearAndGreedIndexDataSource,
symbol: ghostfolioFearAndGreedIndexSymbolStocks
});
info.fearAndGreedMarketPrice = latestMarketData?.marketPrice;
latestFearAndGreedStocksMarketDataPromise =
this.marketDataService.getLatest({
dataSource:
this.dataProviderService.getDataSourceForFearAndGreedIndexStocks(),
symbol: ghostfolioFearAndGreedIndexSymbolStocks
});
globalPermissions.push(permissions.enableFearAndGreedIndex);
}
@ -112,12 +102,14 @@ export class InfoService {
benchmarks,
demoAuthToken,
isUserSignupEnabled,
latestFearAndGreedStocksMarketData,
statistics,
subscriptionOffer
] = await Promise.all([
this.benchmarkService.getBenchmarkAssetProfiles(),
this.getDemoAuthToken(),
this.propertyService.isUserSignupEnabled(),
latestFearAndGreedStocksMarketDataPromise,
this.getStatistics(),
this.subscriptionService.getSubscriptionOffer({ key: 'default' })
]);
@ -135,7 +127,9 @@ export class InfoService {
statistics,
subscriptionOffer,
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 {
protected readonly benchmarks = signal<Benchmark[]>([]);
protected readonly deviceType = computed(
() => this.deviceDetectorService.deviceInfo().deviceType
);
protected readonly fearAndGreedIndex = signal<number | undefined>(undefined);
protected fearAndGreedIndex: number | undefined;
protected hasPermissionToAccessFearAndGreedIndex: boolean;
protected user: User;
@ -65,7 +67,7 @@ export class GfHomeMarketComponent implements OnInit {
);
if (this.hasPermissionToAccessFearAndGreedIndex) {
this.fearAndGreedIndex.set(this.info.fearAndGreedMarketPrice);
this.fearAndGreedIndex = this.info.fearAndGreedStocksMarketPrice;
}
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">
<gf-fear-and-greed-index
class="d-flex justify-content-center"
[fearAndGreedIndex]="fearAndGreedIndex()"
[fearAndGreedIndex]="fearAndGreedIndex"
/>
</div>
</div>

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

@ -1,7 +1,3 @@
:host {
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[];
currencies: string[];
demoAuthToken: string;
fearAndGreedDataSource?: string;
fearAndGreedMarketPrice?: number;
fearAndGreedStocksMarketPrice?: number;
globalPermissions: string[];
isDataGatheringEnabled?: string;
isReadOnlyMode?: boolean;

Loading…
Cancel
Save