Browse Source

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>
pull/1515/head
gobdevel 2 years ago
committed by GitHub
parent
commit
616d168a7c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 10
      apps/api/src/app/info/info.service.ts
  3. 21
      apps/api/src/app/user/user.controller.ts
  4. 11
      apps/client/src/app/components/admin-overview/admin-overview.component.ts
  5. 30
      apps/client/src/app/components/admin-overview/admin-overview.html
  6. 4
      apps/client/src/app/components/header/header.component.html
  7. 6
      apps/client/src/app/components/header/header.component.ts
  8. 6
      apps/client/src/app/pages/landing/landing-page.component.ts
  9. 21
      apps/client/src/app/pages/landing/landing-page.html
  10. 5
      apps/client/src/app/pages/register/register-page.component.ts
  11. 4
      apps/client/src/app/pages/register/register-page.html
  12. 1
      libs/common/src/lib/config.ts

1
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

10
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,

21
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();

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

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

4
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

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

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

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

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

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

1
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';

Loading…
Cancel
Save