From 9cd4321bd02c2f3cb6eaf7010c020882937a0d84 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 8 Sep 2024 09:56:08 +0200 Subject: [PATCH] Feature/extract users from admin control panel endpoint to dedicated endpoint (#3740) * Introduce GET api/v1/admin/user endpoint * Update changelog --- CHANGELOG.md | 6 ++++++ apps/api/src/app/admin/admin.controller.ts | 8 ++++++++ apps/api/src/app/admin/admin.service.ts | 10 +++++++--- .../admin-users/admin-users.component.ts | 12 ++++++------ apps/client/src/app/services/admin.service.ts | 5 +++++ .../src/lib/interfaces/admin-data.interface.ts | 12 ------------ .../src/lib/interfaces/admin-users.interface.ts | 14 ++++++++++++++ libs/common/src/lib/interfaces/index.ts | 2 ++ 8 files changed, 48 insertions(+), 21 deletions(-) create mode 100644 libs/common/src/lib/interfaces/admin-users.interface.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index f91b3b62e..eae074550 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Changed + +- Extracted the users from the admin control panel endpoint to a dedicated endpoint + ## 2.106.0 - 2024-09-07 ### Added diff --git a/apps/api/src/app/admin/admin.controller.ts b/apps/api/src/app/admin/admin.controller.ts index 6d201be23..da4b5dd7e 100644 --- a/apps/api/src/app/admin/admin.controller.ts +++ b/apps/api/src/app/admin/admin.controller.ts @@ -17,6 +17,7 @@ import { AdminData, AdminMarketData, AdminMarketDataDetails, + AdminUsers, EnhancedSymbolProfile } from '@ghostfolio/common/interfaces'; import { permissions } from '@ghostfolio/common/permissions'; @@ -347,4 +348,11 @@ export class AdminController { ) { return this.adminService.putSetting(key, data.value); } + + @Get('user') + @HasPermission(permissions.accessAdminControl) + @UseGuards(AuthGuard('jwt'), HasPermissionGuard) + public async getUsers(): Promise { + return this.adminService.getUsers(); + } } diff --git a/apps/api/src/app/admin/admin.service.ts b/apps/api/src/app/admin/admin.service.ts index 50b781f54..3f5274285 100644 --- a/apps/api/src/app/admin/admin.service.ts +++ b/apps/api/src/app/admin/admin.service.ts @@ -21,6 +21,7 @@ import { AdminMarketData, AdminMarketDataDetails, AdminMarketDataItem, + AdminUsers, AssetProfileIdentifier, EnhancedSymbolProfile, Filter @@ -135,7 +136,6 @@ export class AdminService { settings: await this.propertyService.get(), transactionCount: await this.prismaService.order.count(), userCount: await this.prismaService.user.count(), - users: await this.getUsersWithAnalytics(), version: environment.version }; } @@ -377,6 +377,10 @@ export class AdminService { }; } + public async getUsers(): Promise { + return { users: await this.getUsersWithAnalytics() }; + } + public async patchAssetProfileData({ assetClass, assetSubClass, @@ -546,11 +550,11 @@ export class AdminService { return { marketData, count: marketData.length }; } - private async getUsersWithAnalytics(): Promise { + private async getUsersWithAnalytics(): Promise { let orderBy: any = { createdAt: 'desc' }; - let where; + let where: Prisma.UserWhereInput; if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) { orderBy = { diff --git a/apps/client/src/app/components/admin-users/admin-users.component.ts b/apps/client/src/app/components/admin-users/admin-users.component.ts index 4a419dd6c..c5264c3b3 100644 --- a/apps/client/src/app/components/admin-users/admin-users.component.ts +++ b/apps/client/src/app/components/admin-users/admin-users.component.ts @@ -5,7 +5,7 @@ import { DataService } from '@ghostfolio/client/services/data.service'; import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service'; import { UserService } from '@ghostfolio/client/services/user/user.service'; import { getDateFormatString, getEmojiFlag } from '@ghostfolio/common/helper'; -import { AdminData, InfoItem, User } from '@ghostfolio/common/interfaces'; +import { AdminUsers, InfoItem, User } from '@ghostfolio/common/interfaces'; import { hasPermission, permissions } from '@ghostfolio/common/permissions'; import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'; @@ -24,7 +24,7 @@ import { takeUntil } from 'rxjs/operators'; templateUrl: './admin-users.html' }) export class AdminUsersComponent implements OnDestroy, OnInit { - public dataSource: MatTableDataSource = + public dataSource: MatTableDataSource = new MatTableDataSource(); public defaultDateFormat: string; public displayedColumns: string[] = []; @@ -94,7 +94,7 @@ export class AdminUsersComponent implements OnDestroy, OnInit { } public ngOnInit() { - this.fetchAdminData(); + this.fetchUsers(); } public formatDistanceToNow(aDateString: string) { @@ -119,7 +119,7 @@ export class AdminUsersComponent implements OnDestroy, OnInit { .deleteUser(aId) .pipe(takeUntil(this.unsubscribeSubject)) .subscribe(() => { - this.fetchAdminData(); + this.fetchUsers(); }); }, confirmType: ConfirmationDialogType.Warn, @@ -142,11 +142,11 @@ export class AdminUsersComponent implements OnDestroy, OnInit { this.unsubscribeSubject.complete(); } - private fetchAdminData() { + private fetchUsers() { this.isLoading = true; this.adminService - .fetchAdminData() + .fetchUsers() .pipe(takeUntil(this.unsubscribeSubject)) .subscribe(({ users }) => { this.dataSource = new MatTableDataSource(users); diff --git a/apps/client/src/app/services/admin.service.ts b/apps/client/src/app/services/admin.service.ts index e5ea176d1..4c011e8c1 100644 --- a/apps/client/src/app/services/admin.service.ts +++ b/apps/client/src/app/services/admin.service.ts @@ -12,6 +12,7 @@ import { AdminJobs, AdminMarketData, AdminMarketDataDetails, + AdminUsers, EnhancedSymbolProfile, Filter } from '@ghostfolio/common/interfaces'; @@ -155,6 +156,10 @@ export class AdminService { return this.http.get('/api/v1/tag'); } + public fetchUsers() { + return this.http.get('/api/v1/admin/user'); + } + public gather7Days() { return this.http.post('/api/v1/admin/gather', {}); } diff --git a/libs/common/src/lib/interfaces/admin-data.interface.ts b/libs/common/src/lib/interfaces/admin-data.interface.ts index 6b139026b..3dc476df8 100644 --- a/libs/common/src/lib/interfaces/admin-data.interface.ts +++ b/libs/common/src/lib/interfaces/admin-data.interface.ts @@ -1,7 +1,5 @@ import { AssetProfileIdentifier } from '@ghostfolio/common/interfaces'; -import { Role } from '@prisma/client'; - export interface AdminData { exchangeRates: ({ label1: string; @@ -11,15 +9,5 @@ export interface AdminData { settings: { [key: string]: boolean | object | string | string[] }; transactionCount: number; userCount: number; - users: { - accountCount: number; - country: string; - createdAt: Date; - engagement: number; - id: string; - lastActivity: Date; - role: Role; - transactionCount: number; - }[]; version: string; } diff --git a/libs/common/src/lib/interfaces/admin-users.interface.ts b/libs/common/src/lib/interfaces/admin-users.interface.ts new file mode 100644 index 000000000..24eb45c85 --- /dev/null +++ b/libs/common/src/lib/interfaces/admin-users.interface.ts @@ -0,0 +1,14 @@ +import { Role } from '@prisma/client'; + +export interface AdminUsers { + users: { + accountCount: number; + country: string; + createdAt: Date; + engagement: number; + id: string; + lastActivity: Date; + role: Role; + transactionCount: number; + }[]; +} diff --git a/libs/common/src/lib/interfaces/index.ts b/libs/common/src/lib/interfaces/index.ts index f7224407b..efab780fd 100644 --- a/libs/common/src/lib/interfaces/index.ts +++ b/libs/common/src/lib/interfaces/index.ts @@ -7,6 +7,7 @@ import type { AdminMarketData, AdminMarketDataItem } from './admin-market-data.interface'; +import type { AdminUsers } from './admin-users.interface'; import type { AssetProfileIdentifier } from './asset-profile-identifier.interface'; import type { BenchmarkMarketDataDetails } from './benchmark-market-data-details.interface'; import type { BenchmarkProperty } from './benchmark-property.interface'; @@ -61,6 +62,7 @@ export { AdminMarketData, AdminMarketDataDetails, AdminMarketDataItem, + AdminUsers, AssetProfileIdentifier, Benchmark, BenchmarkMarketDataDetails,