diff --git a/CHANGELOG.md b/CHANGELOG.md index e8304dfd3..0c45d8eca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Added support to disable user sign up in the admin control panel - Extended the glossary of the resources page by _Deflation_, _Inflation_ and _Stagflation_ ## 1.218.0 - 2022-12-12 diff --git a/apps/api/src/app/info/info.service.ts b/apps/api/src/app/info/info.service.ts index 8ed589cb5..e3702fbbd 100644 --- a/apps/api/src/app/info/info.service.ts +++ b/apps/api/src/app/info/info.service.ts @@ -8,6 +8,7 @@ import { TagService } from '@ghostfolio/api/services/tag/tag.service'; import { DEMO_USER_ID, PROPERTY_IS_READ_ONLY_MODE, + PROPERTY_IS_USER_SIGNUP_ENABLED, PROPERTY_SLACK_COMMUNITY_USERS, PROPERTY_STRIPE_CONFIG, PROPERTY_SYSTEM_MESSAGE, @@ -103,6 +104,15 @@ export class InfoService { )) as string; } + const isUserSignupEnabled = + ((await this.propertyService.getByKey( + PROPERTY_IS_USER_SIGNUP_ENABLED + )) as boolean) ?? true; + + if (isUserSignupEnabled) { + globalPermissions.push(permissions.createUserAccount); + } + return { ...info, globalPermissions, diff --git a/apps/api/src/app/user/user.controller.ts b/apps/api/src/app/user/user.controller.ts index 2b1f063bf..4c8b0d748 100644 --- a/apps/api/src/app/user/user.controller.ts +++ b/apps/api/src/app/user/user.controller.ts @@ -1,6 +1,6 @@ import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; import { PropertyService } from '@ghostfolio/api/services/property/property.service'; -import { PROPERTY_IS_READ_ONLY_MODE } from '@ghostfolio/common/config'; +import { PROPERTY_IS_USER_SIGNUP_ENABLED } from '@ghostfolio/common/config'; import { User, UserSettings } from '@ghostfolio/common/interfaces'; import { hasPermission, permissions } from '@ghostfolio/common/permissions'; import type { RequestWithUser } from '@ghostfolio/common/types'; @@ -69,17 +69,16 @@ export class UserController { @Post() public async signupUser(): Promise { - if (this.configurationService.get('ENABLE_FEATURE_READ_ONLY_MODE')) { - const isReadOnlyMode = (await this.propertyService.getByKey( - PROPERTY_IS_READ_ONLY_MODE - )) as boolean; + const isUserSignupEnabled = + ((await this.propertyService.getByKey( + PROPERTY_IS_USER_SIGNUP_ENABLED + )) as boolean) ?? true; - if (isReadOnlyMode) { - throw new HttpException( - getReasonPhrase(StatusCodes.FORBIDDEN), - StatusCodes.FORBIDDEN - ); - } + if (!isUserSignupEnabled) { + throw new HttpException( + getReasonPhrase(StatusCodes.FORBIDDEN), + StatusCodes.FORBIDDEN + ); } const hasAdmin = await this.userService.hasAdmin(); 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 033f78c69..f629b620d 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 @@ -7,6 +7,7 @@ import { PROPERTY_COUPONS, PROPERTY_CURRENCIES, PROPERTY_IS_READ_ONLY_MODE, + PROPERTY_IS_USER_SIGNUP_ENABLED, PROPERTY_SYSTEM_MESSAGE } from '@ghostfolio/common/config'; import { Coupon, InfoItem, User } from '@ghostfolio/common/interfaces'; @@ -35,6 +36,7 @@ export class AdminOverviewComponent implements OnDestroy, OnInit { public hasPermissionForSystemMessage: boolean; public hasPermissionToToggleReadOnlyMode: boolean; public info: InfoItem; + public permissions = permissions; public transactionCount: number; public userCount: number; public user: User; @@ -167,6 +169,13 @@ export class AdminOverviewComponent implements OnDestroy, OnInit { }); } + public onEnableUserSignupModeChange(aEvent: MatSlideToggleChange) { + this.putAdminSetting({ + key: PROPERTY_IS_USER_SIGNUP_ENABLED, + value: aEvent.checked ? undefined : false + }); + } + public onSetSystemMessage() { const systemMessage = prompt($localize`Please set your system message:`); @@ -214,7 +223,7 @@ export class AdminOverviewComponent implements OnDestroy, OnInit { private putAdminSetting({ key, value }: { key: string; value: any }) { this.dataService .putAdminSetting(key, { - value: value ? JSON.stringify(value) : undefined + value: value || value === false ? JSON.stringify(value) : undefined }) .pipe(takeUntil(this.unsubscribeSubject)) .subscribe(() => { 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 c9414201b..44d851a8c 100644 --- a/apps/client/src/app/components/admin-overview/admin-overview.html +++ b/apps/client/src/app/components/admin-overview/admin-overview.html @@ -82,6 +82,26 @@ +
+
User Signup
+
+ +
+
+
+
Read-only Mode
+
+ +
+
System Message
@@ -109,16 +129,6 @@
-
-
Read-only Mode
-
- -
-
@@ -289,7 +289,7 @@ Sign in
- + + Get Started + +
or
- Get Started - -
or
+ Live Demo @@ -306,7 +309,7 @@
-
+

Are you ready?

diff --git a/apps/client/src/app/pages/register/register-page.component.ts b/apps/client/src/app/pages/register/register-page.component.ts index ee18a024c..29a428fe1 100644 --- a/apps/client/src/app/pages/register/register-page.component.ts +++ b/apps/client/src/app/pages/register/register-page.component.ts @@ -25,6 +25,7 @@ export class RegisterPageComponent implements OnDestroy, OnInit { public demoAuthToken: string; public deviceType: string; public hasPermissionForSocialLogin: boolean; + public hasPermissionToCreateUser: boolean; public historicalDataItems: LineChartItem[]; public info: InfoItem; @@ -52,6 +53,10 @@ export class RegisterPageComponent implements OnDestroy, OnInit { globalPermissions, permissions.enableSocialLogin ); + this.hasPermissionToCreateUser = hasPermission( + globalPermissions, + permissions.createUserAccount + ); } public async createAccount() { diff --git a/apps/client/src/app/pages/register/register-page.html b/apps/client/src/app/pages/register/register-page.html index 0542af79c..130346ef5 100644 --- a/apps/client/src/app/pages/register/register-page.html +++ b/apps/client/src/app/pages/register/register-page.html @@ -14,14 +14,14 @@

-
+