Feature/add signup permission (#1512)

* Added support to disable user sign up in the admin control panel

* Update changelog

Co-authored-by: Thomas <4159106+dtslvr@users.noreply.github.com>
This commit is contained in:
gobdevel
2022-12-17 17:09:21 +05:30
committed by GitHub
parent b13e4425d3
commit 616d168a7c
12 changed files with 85 additions and 35 deletions

View File

@@ -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(() => {

View File

@@ -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"

View File

@@ -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

View File

@@ -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) {

View File

@@ -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;
}

View File

@@ -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">

View File

@@ -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() {

View File

@@ -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>