From 49e4516855abdf08c519306f2c3a5889b09ca403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Mart=C3=ADn?= Date: Sun, 9 Nov 2025 17:41:03 +0100 Subject: [PATCH] Refactor authentication permissions and update feature flags in environment configuration --- .env.example | 11 +------- apps/api/src/app/info/info.service.ts | 16 +++++------ .../interfaces/environment.interface.ts | 4 +-- .../admin-overview/admin-overview.html | 28 ++++++++----------- .../components/header/header.component.html | 6 +--- .../login-with-access-token-dialog.html | 8 ++---- .../pages/features/features-page.component.ts | 6 ++++ .../src/app/pages/features/features-page.html | 2 +- .../pages/landing/landing-page.component.ts | 3 +- .../src/app/pages/landing/landing-page.html | 6 ++-- .../pages/pricing/pricing-page.component.ts | 14 +++++++--- .../src/app/pages/pricing/pricing-page.html | 2 +- .../src/app/pages/register/register-page.html | 24 +++++++++------- libs/common/src/lib/permissions.ts | 4 +-- 14 files changed, 66 insertions(+), 68 deletions(-) diff --git a/.env.example b/.env.example index 494875c7b..f3d5e3634 100644 --- a/.env.example +++ b/.env.example @@ -13,13 +13,4 @@ POSTGRES_PASSWORD= # VARIOUS ACCESS_TOKEN_SALT= DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}?connect_timeout=300&sslmode=prefer -JWT_SECRET_KEY= - -# AUTHENTICATION -# Enable authentication with Google OAuth (default: false) -# ENABLE_FEATURE_AUTH_GOOGLE=true -# GOOGLE_CLIENT_ID= -# GOOGLE_SECRET= - -# Enable authentication with Security Token (default: true) -# ENABLE_FEATURE_AUTH_TOKEN=true +JWT_SECRET_KEY= \ No newline at end of file diff --git a/apps/api/src/app/info/info.service.ts b/apps/api/src/app/info/info.service.ts index 12fb13129..634fc959c 100644 --- a/apps/api/src/app/info/info.service.ts +++ b/apps/api/src/app/info/info.service.ts @@ -51,6 +51,14 @@ export class InfoService { const globalPermissions: string[] = []; + if (this.configurationService.get('ENABLE_FEATURE_AUTH_GOOGLE')) { + globalPermissions.push(permissions.enableAuthGoogle); + } + + if (this.configurationService.get('ENABLE_FEATURE_AUTH_TOKEN')) { + globalPermissions.push(permissions.enableAuthToken); + } + if (this.configurationService.get('ENABLE_FEATURE_FEAR_AND_GREED_INDEX')) { if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) { info.fearAndGreedDataSource = encodeDataSource( @@ -64,14 +72,6 @@ export class InfoService { globalPermissions.push(permissions.enableFearAndGreedIndex); } - if (this.configurationService.get('ENABLE_FEATURE_AUTH_GOOGLE')) { - globalPermissions.push(permissions.enableAuthGoogle); - } - - if (this.configurationService.get('ENABLE_FEATURE_AUTH_TOKEN')) { - globalPermissions.push(permissions.enableAuthToken); - } - if (this.configurationService.get('ENABLE_FEATURE_READ_ONLY_MODE')) { isReadOnlyMode = await this.propertyService.getByKey( PROPERTY_IS_READ_ONLY_MODE diff --git a/apps/api/src/services/interfaces/environment.interface.ts b/apps/api/src/services/interfaces/environment.interface.ts index 918b123ed..f2ee84926 100644 --- a/apps/api/src/services/interfaces/environment.interface.ts +++ b/apps/api/src/services/interfaces/environment.interface.ts @@ -16,10 +16,10 @@ export interface Environment extends CleanedEnvAccessors { DATA_SOURCE_IMPORT: string; DATA_SOURCES: string[]; DATA_SOURCES_GHOSTFOLIO_DATA_PROVIDER: string[]; - ENABLE_FEATURE_FEAR_AND_GREED_INDEX: boolean; - ENABLE_FEATURE_READ_ONLY_MODE: boolean; ENABLE_FEATURE_AUTH_GOOGLE: boolean; ENABLE_FEATURE_AUTH_TOKEN: boolean; + ENABLE_FEATURE_FEAR_AND_GREED_INDEX: boolean; + ENABLE_FEATURE_READ_ONLY_MODE: boolean; ENABLE_FEATURE_STATISTICS: boolean; ENABLE_FEATURE_SUBSCRIPTION: boolean; ENABLE_FEATURE_SYSTEM_MESSAGE: boolean; 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 0245b51b6..c47387f37 100644 --- a/apps/client/src/app/components/admin-overview/admin-overview.html +++ b/apps/client/src/app/components/admin-overview/admin-overview.html @@ -30,23 +30,19 @@ } - @if (hasPermissionForAuthToken) { -
-
User Signup
-
- -
+
+
User Signup
+
+
- } +
@if (hasPermissionToToggleReadOnlyMode) {
Read-only Mode
diff --git a/apps/client/src/app/components/header/header.component.html b/apps/client/src/app/components/header/header.component.html index c1917e843..501119b31 100644 --- a/apps/client/src/app/components/header/header.component.html +++ b/apps/client/src/app/components/header/header.component.html @@ -422,11 +422,7 @@ Sign in - @if ( - currentRoute !== 'register' && - hasPermissionToCreateUser && - hasPermissionForAuthToken - ) { + @if (currentRoute !== 'register' && hasPermissionToCreateUser) {
  • - @if (data.hasPermissionToUseAuthToken) { - Stay signed in - } + Stay signed in
    @if (data.hasPermissionToUseAuthToken) { diff --git a/apps/client/src/app/pages/features/features-page.component.ts b/apps/client/src/app/pages/features/features-page.component.ts index 89ec02bfe..d89156d69 100644 --- a/apps/client/src/app/pages/features/features-page.component.ts +++ b/apps/client/src/app/pages/features/features-page.component.ts @@ -26,6 +26,7 @@ import { Subject, takeUntil } from 'rxjs'; export class GfFeaturesPageComponent implements OnDestroy { public hasPermissionForAuthToken: boolean; public hasPermissionForSubscription: boolean; + public hasPermissionToCreateUser: boolean; public info: InfoItem; public routerLinkRegister = publicRoutes.register.routerLink; public routerLinkResources = publicRoutes.resources.routerLink; @@ -61,6 +62,11 @@ export class GfFeaturesPageComponent implements OnDestroy { this.info?.globalPermissions, permissions.enableSubscription ); + + this.hasPermissionToCreateUser = hasPermission( + this.info?.globalPermissions, + permissions.createUserAccount + ); } public ngOnDestroy() { diff --git a/apps/client/src/app/pages/features/features-page.html b/apps/client/src/app/pages/features/features-page.html index 75bfbfc59..314de8677 100644 --- a/apps/client/src/app/pages/features/features-page.html +++ b/apps/client/src/app/pages/features/features-page.html @@ -309,7 +309,7 @@
  • - @if (!user && hasPermissionForAuthToken) { + @if (!user && hasPermissionToCreateUser) {
    } - @if (hasPermissionToCreateUser && hasPermissionForAuthToken) { + @if (hasPermissionToCreateUser) {

    diff --git a/apps/client/src/app/pages/pricing/pricing-page.component.ts b/apps/client/src/app/pages/pricing/pricing-page.component.ts index c3cfd2ddc..4d4e8e1b6 100644 --- a/apps/client/src/app/pages/pricing/pricing-page.component.ts +++ b/apps/client/src/app/pages/pricing/pricing-page.component.ts @@ -53,6 +53,7 @@ export class GfPricingPageComponent implements OnDestroy, OnInit { public couponId: string; public durationExtension: StringValue; public hasPermissionForAuthToken: boolean; + public hasPermissionToCreateUser: boolean; public hasPermissionToUpdateUserSettings: boolean; public importAndExportTooltipBasic = translate( 'DATA_IMPORT_AND_EXPORT_TOOLTIP_BASIC' @@ -103,17 +104,22 @@ export class GfPricingPageComponent implements OnDestroy, OnInit { public ngOnInit() { const { baseCurrency, globalPermissions, subscriptionOffer } = this.dataService.fetchInfo(); + this.baseCurrency = baseCurrency; + this.coupon = subscriptionOffer?.coupon; + this.durationExtension = subscriptionOffer?.durationExtension; + this.label = subscriptionOffer?.label; + this.price = subscriptionOffer?.price; this.hasPermissionForAuthToken = hasPermission( globalPermissions, permissions.enableAuthToken ); - this.coupon = subscriptionOffer?.coupon; - this.durationExtension = subscriptionOffer?.durationExtension; - this.label = subscriptionOffer?.label; - this.price = subscriptionOffer?.price; + this.hasPermissionToCreateUser = hasPermission( + globalPermissions, + permissions.createUserAccount + ); this.userService.stateChanged .pipe(takeUntil(this.unsubscribeSubject)) diff --git a/apps/client/src/app/pages/pricing/pricing-page.html b/apps/client/src/app/pages/pricing/pricing-page.html index ca31895c5..83a3bdd97 100644 --- a/apps/client/src/app/pages/pricing/pricing-page.html +++ b/apps/client/src/app/pages/pricing/pricing-page.html @@ -367,7 +367,7 @@

    - } @else if (!user && hasPermissionForAuthToken) { + } @else if (!user && hasPermissionToCreateUser) {