Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Feature/add signup permission (#1512)

gobdevel616d168a7ce8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e8304dfd33..0c45d8ecae 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 8ed589cb5e..e3702fbbdb 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 2b1f063bf7..4c8b0d7489 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<UserItem> {
- 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 033f78c698..f629b620dd 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 c9414201b6..44d851a8c9 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 @@
</table>
</div>
</div>
+ <div class="d-flex my-3">
+ <div class="w-50" i18n>User Signup</div>
+ <div class="w-50">
+ <mat-slide-toggle
+ color="primary"
+ [checked]="info.globalPermissions.includes(permissions.createUserAccount)"
+ (change)="onEnableUserSignupModeChange($event)"
+ ></mat-slide-toggle>
+ </div>
+ </div>
+ <div *ngIf="hasPermissionToToggleReadOnlyMode" class="d-flex my-3">
+ <div class="w-50" i18n>Read-only Mode</div>
+ <div class="w-50">
+ <mat-slide-toggle
+ color="primary"
+ [checked]="info?.isReadOnlyMode"
+ (change)="onReadOnlyModeChange($event)"
+ ></mat-slide-toggle>
+ </div>
+ </div>
<div *ngIf="hasPermissionForSystemMessage" class="d-flex my-3">
<div class="w-50" i18n>System Message</div>
<div class="w-50">
@@ -109,16 +129,6 @@
</button>
</div>
</div>
- <div *ngIf="hasPermissionToToggleReadOnlyMode" class="d-flex my-3">
- <div class="w-50" i18n>Read-only Mode</div>
- <div class="w-50">
- <mat-slide-toggle
- color="primary"
- [checked]="info?.isReadOnlyMode"
- (change)="onReadOnlyModeChange($event)"
- ></mat-slide-toggle>
- </div>
- </div>
<div
*ngIf="hasPermissionForSubscription"
class="d-flex my-3 subscription"
diff --git a/apps/client/src/app/components/header/header.component.html b/apps/client/src/app/components/header/header.component.html
index 336bc6d24b..ce3b98dffc 100644
--- a/apps/client/src/app/components/header/header.component.html
+++ b/apps/client/src/app/components/header/header.component.html
@@ -1,9 +1,9 @@
<mat-toolbar class="px-2">
<ng-container *ngIf="user">
<a
- [routerLink]="['/']"
class="align-items-center d-flex h-100 no-min-width px-2 rounded-0"
mat-button
+ [routerLink]="['/']"
>
<gf-logo></gf-logo>
</a>
@@ -289,7 +289,7 @@
<ng-container i18n>Sign in</ng-container>
</button>
<a
- *ngIf="currentRoute !== 'register' && !info?.isReadOnlyMode"
+ *ngIf="currentRoute !== 'register' && hasPermissionToCreateUser"
class="d-none d-sm-block"
color="primary"
mat-flat-button
diff --git a/apps/client/src/app/components/header/header.component.ts b/apps/client/src/app/components/header/header.component.ts
index 9e17b59adb..03ec46dd86 100644
--- a/apps/client/src/app/components/header/header.component.ts
+++ b/apps/client/src/app/components/header/header.component.ts
@@ -38,6 +38,7 @@ export class HeaderComponent implements OnChanges {
public hasPermissionForSubscription: boolean;
public hasPermissionToAccessAdminControl: boolean;
public hasPermissionToAccessFearAndGreedIndex: boolean;
+ public hasPermissionToCreateUser: boolean;
public impersonationId: string;
public isMenuOpen: boolean;
@@ -79,6 +80,11 @@ export class HeaderComponent implements OnChanges {
this.info?.globalPermissions,
permissions.enableFearAndGreedIndex
);
+
+ this.hasPermissionToCreateUser = hasPermission(
+ this.info?.globalPermissions,
+ permissions.createUserAccount
+ );
}
public impersonateAccount(aId: string) {
diff --git a/apps/client/src/app/pages/landing/landing-page.component.ts b/apps/client/src/app/pages/landing/landing-page.component.ts
index 34757b2ca8..f8c2c6a234 100644
--- a/apps/client/src/app/pages/landing/landing-page.component.ts
+++ b/apps/client/src/app/pages/landing/landing-page.component.ts
@@ -17,6 +17,7 @@ export class LandingPageComponent implements OnDestroy, OnInit {
public demoAuthToken: string;
public deviceType: string;
public hasPermissionForStatistics: boolean;
+ public hasPermissionToCreateUser: boolean;
public statistics: Statistics;
public testimonials = [
{
@@ -54,6 +55,11 @@ export class LandingPageComponent implements OnDestroy, OnInit {
permissions.enableStatistics
);
+ this.hasPermissionToCreateUser = hasPermission(
+ globalPermissions,
+ permissions.createUserAccount
+ );
+
this.statistics = statistics;
}
diff --git a/apps/client/src/app/pages/landing/landing-page.html b/apps/client/src/app/pages/landing/landing-page.html
index 9b1a5202f3..48b448dcad 100644
--- a/apps/client/src/app/pages/landing/landing-page.html
+++ b/apps/client/src/app/pages/landing/landing-page.html
@@ -31,15 +31,18 @@
<div class="button-container mb-5 row">
<div class="align-items-center col d-flex justify-content-center">
<div class="text-center">
- <a
- class="d-inline-block"
- color="primary"
- mat-flat-button
- [routerLink]="['/register']"
+ <ng-container *ngIf="hasPermissionToCreateUser">
+ <a
+ class="d-inline-block"
+ color="primary"
+ mat-flat-button
+ [routerLink]="['/register']"
+ >
+ Get Started
+ </a>
+ <div class="d-inline-block mx-3 text-muted">or</div></ng-container
>
- Get Started
- </a>
- <div class="d-inline-block mx-3 text-muted">or</div>
+
<a class="d-inline-block" mat-stroked-button [routerLink]="['/demo']">
Live Demo
</a>
@@ -306,7 +309,7 @@
</div>
</div>
- <div class="row my-5">
+ <div *ngIf="hasPermissionToCreateUser" class="row my-5">
<div class="col">
<h2 class="h4 mb-1 text-center">Are <strong>you</strong> ready?</h2>
<p class="lead mb-3 text-center">
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 ee18a024cc..29a428fe18 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 0542af79c7..130346ef5e 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 @@
</div>
</div>
- <div class="button-container row">
+ <div *ngIf="hasPermissionToCreateUser" class="button-container row">
<div class="align-items-center col d-flex justify-content-center">
<div class="py-5 text-center">
<button
class="d-inline-block"
color="primary"
mat-flat-button
- [disabled]="!demoAuthToken || info?.isReadOnlyMode"
+ [disabled]="!demoAuthToken"
(click)="createAccount()"
>
<ng-container i18n>Create Account</ng-container>
diff --git a/libs/common/src/lib/config.ts b/libs/common/src/lib/config.ts
index 1389200a60..7b34aaf336 100644
--- a/libs/common/src/lib/config.ts
+++ b/libs/common/src/lib/config.ts
@@ -74,6 +74,7 @@ export const PROPERTY_BENCHMARKS = 'BENCHMARKS';
export const PROPERTY_COUPONS = 'COUPONS';
export const PROPERTY_CURRENCIES = 'CURRENCIES';
export const PROPERTY_IS_READ_ONLY_MODE = 'IS_READ_ONLY_MODE';
+export const PROPERTY_IS_USER_SIGNUP_ENABLED = 'IS_USER_SIGNUP_ENABLED';
export const PROPERTY_SLACK_COMMUNITY_USERS = 'SLACK_COMMUNITY_USERS';
export const PROPERTY_STRIPE_CONFIG = 'STRIPE_CONFIG';
export const PROPERTY_SYSTEM_MESSAGE = 'SYSTEM_MESSAGE';