diff --git a/CHANGELOG.md b/CHANGELOG.md index b389d0d135..b9a533700f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Extended the coupon system to support the duration extension of the current subscription offer +- Upgraded `@ionic/angular` from version `8.8.12` to `8.8.19` - Upgraded `bootstrap` from version `5.3.8` to `5.3.9` +- Upgraded `ionicons` from version `8.0.13` to `8.1.0` ## 3.101.0 - 2026-11-28 diff --git a/apps/api/src/app/endpoints/accounts/accounts.controller.ts b/apps/api/src/app/endpoints/accounts/accounts.controller.ts index d47dcd3a25..b28e303935 100644 --- a/apps/api/src/app/endpoints/accounts/accounts.controller.ts +++ b/apps/api/src/app/endpoints/accounts/accounts.controller.ts @@ -7,6 +7,7 @@ import { TransformDataSourceInRequestInterceptor } from '@ghostfolio/api/interce import { AccountBalanceService } from '@ghostfolio/api/services/account-balance/account-balance.service'; import { AccountService } from '@ghostfolio/api/services/account/account.service'; import { ApiService } from '@ghostfolio/api/services/api/api.service'; +import { DEFAULT_CURRENCY } from '@ghostfolio/common/config'; import { CreateAccountBalanceDto, CreateAccountDto, @@ -72,7 +73,7 @@ export class AccountsController { { activities: true } ); - if (!account || account?.activities.length > 0) { + if (!account?.activities || account.activities.length > 0) { throw new HttpException( getReasonPhrase(StatusCodes.FORBIDDEN), StatusCodes.FORBIDDEN @@ -173,7 +174,7 @@ export class AccountsController { return this.accountBalanceService.getAccountBalances({ userId, filters: [{ id, type: 'ACCOUNT' }], - userCurrency: userSettings.baseCurrency + userCurrency: userSettings.baseCurrency ?? DEFAULT_CURRENCY }); } @@ -185,12 +186,9 @@ export class AccountsController { @Body() data: CreateAccountDto, @Impersonation() { userId }: ImpersonationContext ): Promise { - const { balance, tags: tagIds, ...accountData } = data; - - if (accountData.platformId) { - const platformId = accountData.platformId; - delete accountData.platformId; + const { balance, platformId, tags: tagIds, ...accountData } = data; + if (platformId) { return this.accountService.createAccount({ balance, tagIds, @@ -202,8 +200,6 @@ export class AccountsController { } }); } else { - delete accountData.platformId; - return this.accountService.createAccount({ balance, tagIds, @@ -262,7 +258,7 @@ export class AccountsController { @RequiresScope(scopes.accountUpdate) public async transferAccountBalance( @Body() { accountIdFrom, accountIdTo, balance }: TransferBalanceDto, - @Impersonation() { userId }: ImpersonationContext + @Impersonation() { userId, userSettings }: ImpersonationContext ) { const accountsOfUser = await this.accountService.getAccounts(userId); @@ -295,18 +291,21 @@ export class AccountsController { ); } + const currency = + accountFrom.currency ?? userSettings.baseCurrency ?? DEFAULT_CURRENCY; + await this.accountService.updateAccountBalance({ + currency, userId, accountId: accountFrom.id, - amount: -balance, - currency: accountFrom.currency + amount: -balance }); await this.accountService.updateAccountBalance({ + currency, userId, accountId: accountTo.id, - amount: balance, - currency: accountFrom.currency + amount: balance }); } @@ -333,12 +332,9 @@ export class AccountsController { ); } - const { balance, tags: tagIds, ...accountData } = data; - - if (accountData.platformId) { - const platformId = accountData.platformId; - delete accountData.platformId; + const { balance, platformId, tags: tagIds, ...accountData } = data; + if (platformId) { return this.accountService.updateAccount({ balance, tagIds, @@ -356,9 +352,6 @@ export class AccountsController { } }); } else { - // platformId is null, remove it - delete accountData.platformId; - return this.accountService.updateAccount({ balance, tagIds, diff --git a/apps/api/src/app/endpoints/auth/auth.module.ts b/apps/api/src/app/endpoints/auth/auth.module.ts index 353b063d4e..4925908fdd 100644 --- a/apps/api/src/app/endpoints/auth/auth.module.ts +++ b/apps/api/src/app/endpoints/auth/auth.module.ts @@ -65,9 +65,19 @@ import { WebAuthService } from './web-auth.service'; return null; } + const clientID = configurationService.get('OIDC_CLIENT_ID'); + const clientSecret = configurationService.get('OIDC_CLIENT_SECRET'); const issuer = configurationService.get('OIDC_ISSUER'); const scope = configurationService.get('OIDC_SCOPE'); + if (!clientID || !clientSecret || !issuer) { + logger.error( + 'OIDC configuration incomplete: issuer, clientID, or clientSecret missing' + ); + + throw new Error('OIDC configuration incomplete'); + } + const callbackURL = configurationService.get('OIDC_CALLBACK_URL') || `${configurationService.get('ROOT_URL')}/api/auth/oidc/callback`; @@ -119,17 +129,6 @@ import { WebAuthService } from './web-auth.service'; } } - const clientID = configurationService.get('OIDC_CLIENT_ID'); - const clientSecret = configurationService.get('OIDC_CLIENT_SECRET'); - - if (!clientID || !clientSecret || !issuer) { - logger.error( - 'OIDC configuration incomplete: issuer, clientID, or clientSecret missing' - ); - - throw new Error('OIDC configuration incomplete'); - } - const options: StrategyOptions = { authorizationURL, callbackURL, diff --git a/apps/api/src/app/endpoints/auth/web-auth.service.ts b/apps/api/src/app/endpoints/auth/web-auth.service.ts index 4265ce8843..8e756394ff 100644 --- a/apps/api/src/app/endpoints/auth/web-auth.service.ts +++ b/apps/api/src/app/endpoints/auth/web-auth.service.ts @@ -6,6 +6,7 @@ import { PortfolioSnapshotService } from '@ghostfolio/api/services/queues/portfo import { RedisCacheService } from '@ghostfolio/api/services/redis-cache/redis-cache.service'; import { UserService } from '@ghostfolio/api/services/user/user.service'; import { + DEFAULT_CURRENCY, PORTFOLIO_SNAPSHOT_COMPUTATION_QUEUE_PRIORITY_LOW, PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME, PORTFOLIO_SNAPSHOT_PROCESS_JOB_OPTIONS @@ -16,6 +17,7 @@ import { AttestationCredentialJSON } from '@ghostfolio/common/interfaces'; import type { RequestWithUser } from '@ghostfolio/common/types'; +import { PerformanceCalculationType } from '@ghostfolio/common/types/performance-calculation-type.type'; import { Inject, @@ -258,9 +260,13 @@ export class WebAuthService { private async isPortfolioSnapshotExpired(portfolioSnapshotKey: string) { try { - const { expiration }: PortfolioSnapshotValue = JSON.parse( - await this.redisCacheService.get(portfolioSnapshotKey) - ); + const value = await this.redisCacheService.get(portfolioSnapshotKey); + + if (!value) { + return true; + } + + const { expiration }: PortfolioSnapshotValue = JSON.parse(value); return isPast(new Date(expiration)); } catch { @@ -277,6 +283,10 @@ export class WebAuthService { } const userSettings = user.settings.settings; + const calculationType = + userSettings.performanceCalculationType ?? + PerformanceCalculationType.ROAI; + const userCurrency = userSettings.baseCurrency ?? DEFAULT_CURRENCY; const filters = this.apiService.buildFiltersFromUserSettings({ userSettings @@ -284,18 +294,18 @@ export class WebAuthService { const portfolioSnapshotKey = this.redisCacheService.getPortfolioSnapshotKey({ + calculationType, filters, - userId, - calculationType: userSettings.performanceCalculationType + userId }); if (await this.isPortfolioSnapshotExpired(portfolioSnapshotKey)) { await this.portfolioSnapshotService.addJobToQueue({ data: { + calculationType, filters, - userId, - calculationType: userSettings.performanceCalculationType, - userCurrency: userSettings.baseCurrency + userCurrency, + userId }, name: PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME, opts: { diff --git a/apps/client/src/app/adapter/custom-paginator-intl.ts b/apps/client/src/app/adapter/custom-paginator-intl.ts index 8bfd139420..ca4a4b3bb9 100644 --- a/apps/client/src/app/adapter/custom-paginator-intl.ts +++ b/apps/client/src/app/adapter/custom-paginator-intl.ts @@ -30,7 +30,7 @@ export class CustomPaginatorIntl extends MatPaginatorIntl { const total = this.formatNumber(Math.max(length, 0)); - return `${range} ${$localize`of`} ${total}`; + return $localize`${range}:range: of ${total}:total:`; }; public setLocale(aLocale: string) { diff --git a/apps/client/src/app/components/admin-overview/admin-overview.component.ts b/apps/client/src/app/components/admin-overview/admin-overview.component.ts index 5824bda366..02c8ca156e 100644 --- a/apps/client/src/app/components/admin-overview/admin-overview.component.ts +++ b/apps/client/src/app/components/admin-overview/admin-overview.component.ts @@ -49,7 +49,11 @@ import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar'; import { MatTableDataSource, MatTableModule } from '@angular/material/table'; import { RouterModule } from '@angular/router'; import { IonIcon } from '@ionic/angular/standalone'; -import { addMilliseconds, formatDistanceToNowStrict } from 'date-fns'; +import { + addMilliseconds, + FormatDistanceStrictUnit, + formatDistanceToNowStrict +} from 'date-fns'; import { addIcons } from 'ionicons'; import { closeCircleOutline, @@ -88,6 +92,7 @@ import { catchError, finalize, of, switchMap } from 'rxjs'; export class GfAdminOverviewComponent implements OnInit { protected activitiesCount: number; protected couponDuration: StringValue = '14 days'; + protected readonly couponDurationWithExtension: StringValue | undefined; protected readonly couponsDataSource = new MatTableDataSource(); protected readonly couponsDisplayedColumns = [ 'code', @@ -95,6 +100,7 @@ export class GfAdminOverviewComponent implements OnInit { 'createdAt', 'actions' ]; + protected readonly durationExtension: StringValue | undefined; protected hasPermissionForSubscription: boolean; protected hasPermissionForSystemMessage: boolean; protected hasPermissionToSyncDemoUserAccount: boolean; @@ -124,6 +130,15 @@ export class GfAdminOverviewComponent implements OnInit { public constructor() { this.info = this.dataService.fetchInfo(); + this.durationExtension = this.info.subscriptionOffer?.durationExtension; + + if (this.durationExtension) { + this.couponDurationWithExtension = ms( + ms('1 year') + ms(this.durationExtension), + { long: true } + ) as StringValue; + } + this.userService.stateChanged .pipe(takeUntilDestroyed(this.destroyRef)) .subscribe((state) => { @@ -185,13 +200,17 @@ export class GfAdminOverviewComponent implements OnInit { this.fetchAdminData(); } - protected formatStringValue(aStringValue: StringValue) { - return formatDistanceToNowStrict( - addMilliseconds(new Date(), ms(aStringValue)), - { - locale: getDateFnsLocale(this.user?.settings?.language) - } - ); + protected formatStringValue({ + unit, + value + }: { + unit?: FormatDistanceStrictUnit; + value: StringValue; + }) { + return formatDistanceToNowStrict(addMilliseconds(new Date(), ms(value)), { + unit, + locale: getDateFnsLocale(this.user?.settings?.language) + }); } protected onAddCoupon() { diff --git a/apps/client/src/app/components/admin-overview/admin-overview.html b/apps/client/src/app/components/admin-overview/admin-overview.html index 269fe291ac..592d135301 100644 --- a/apps/client/src/app/components/admin-overview/admin-overview.html +++ b/apps/client/src/app/components/admin-overview/admin-overview.html @@ -178,7 +178,7 @@ Duration - {{ formatStringValue(element.duration) }} + {{ formatStringValue({ value: element.duration }) }} @@ -263,23 +263,34 @@ (selectionChange)="onChangeCouponDuration($event.value)" > {{ - formatStringValue('7 days') + formatStringValue({ value: '7 days' }) }} {{ - formatStringValue('14 days') + formatStringValue({ value: '14 days' }) }} {{ - formatStringValue('30 days') + formatStringValue({ value: '30 days' }) }} {{ - formatStringValue('90 days') + formatStringValue({ value: '90 days' }) }} {{ - formatStringValue('180 days') + formatStringValue({ value: '180 days' }) }} {{ - formatStringValue('1 year') + formatStringValue({ value: '1 year' }) }} + @if (durationExtension) { + {{ formatStringValue({ value: '1 year' }) }} + + {{ + formatStringValue({ + unit: 'day', + value: durationExtension + }) + }} + }