mirror of https://github.com/ghostfolio/ghostfolio
Browse Source
* Deprecate admin user endpoints in favor of users endpoints * Update changelogpull/8366/head
committed by
GitHub
10 changed files with 162 additions and 32 deletions
@ -0,0 +1,83 @@ |
|||||
|
import { AdminService } from '@ghostfolio/api/app/admin/admin.service'; |
||||
|
import { AllowDuringImpersonation } from '@ghostfolio/api/decorators/allow-during-impersonation.decorator'; |
||||
|
import { HasPermission } from '@ghostfolio/api/decorators/has-permission.decorator'; |
||||
|
import { HasPermissionGuard } from '@ghostfolio/api/guards/has-permission.guard'; |
||||
|
import { UserService } from '@ghostfolio/api/services/user/user.service'; |
||||
|
import { |
||||
|
AccessTokenResponse, |
||||
|
AdminUserResponse, |
||||
|
AdminUsersResponse |
||||
|
} from '@ghostfolio/common/interfaces'; |
||||
|
import { permissions } from '@ghostfolio/common/permissions'; |
||||
|
import type { RequestWithUser } from '@ghostfolio/common/types'; |
||||
|
|
||||
|
import { |
||||
|
Controller, |
||||
|
Delete, |
||||
|
Get, |
||||
|
HttpException, |
||||
|
Inject, |
||||
|
Param, |
||||
|
ParseIntPipe, |
||||
|
Post, |
||||
|
Query, |
||||
|
UseGuards |
||||
|
} from '@nestjs/common'; |
||||
|
import { REQUEST } from '@nestjs/core'; |
||||
|
import { AuthGuard } from '@nestjs/passport'; |
||||
|
import { StatusCodes, getReasonPhrase } from 'http-status-codes'; |
||||
|
|
||||
|
@AllowDuringImpersonation() |
||||
|
@Controller('users') |
||||
|
export class UsersController { |
||||
|
public constructor( |
||||
|
private readonly adminService: AdminService, |
||||
|
@Inject(REQUEST) private readonly request: RequestWithUser, |
||||
|
private readonly userService: UserService |
||||
|
) {} |
||||
|
|
||||
|
@Delete(':id') |
||||
|
@HasPermission(permissions.deleteUser) |
||||
|
@UseGuards(AuthGuard('jwt'), HasPermissionGuard) |
||||
|
public async deleteUser(@Param('id') id: string): Promise<void> { |
||||
|
if (id === this.request.user.id) { |
||||
|
throw new HttpException( |
||||
|
getReasonPhrase(StatusCodes.FORBIDDEN), |
||||
|
StatusCodes.FORBIDDEN |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
await this.userService.deleteUser({ |
||||
|
id |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
@Get(':id') |
||||
|
@HasPermission(permissions.accessAdminControl) |
||||
|
@UseGuards(AuthGuard('jwt'), HasPermissionGuard) |
||||
|
public async getUser(@Param('id') id: string): Promise<AdminUserResponse> { |
||||
|
return this.adminService.getUser(id); |
||||
|
} |
||||
|
|
||||
|
@Get() |
||||
|
@HasPermission(permissions.accessAdminControl) |
||||
|
@UseGuards(AuthGuard('jwt'), HasPermissionGuard) |
||||
|
public async getUsers( |
||||
|
@Query('skip', new ParseIntPipe({ optional: true })) skip?: number, |
||||
|
@Query('take', new ParseIntPipe({ optional: true })) take?: number |
||||
|
): Promise<AdminUsersResponse> { |
||||
|
return this.adminService.getUsers({ |
||||
|
skip, |
||||
|
take |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
@HasPermission(permissions.accessAdminControl) |
||||
|
@Post(':id/access-token') |
||||
|
@UseGuards(AuthGuard('jwt'), HasPermissionGuard) |
||||
|
public async updateUserAccessToken( |
||||
|
@Param('id') id: string |
||||
|
): Promise<AccessTokenResponse> { |
||||
|
return this.userService.rotateAccessToken({ userId: id }); |
||||
|
} |
||||
|
} |
||||
@ -1,30 +1,31 @@ |
|||||
|
import { AdminModule } from '@ghostfolio/api/app/admin/admin.module'; |
||||
import { RedactValuesInResponseModule } from '@ghostfolio/api/interceptors/redact-values-in-response/redact-values-in-response.module'; |
import { RedactValuesInResponseModule } from '@ghostfolio/api/interceptors/redact-values-in-response/redact-values-in-response.module'; |
||||
import { TransformDataSourceInResponseModule } from '@ghostfolio/api/interceptors/transform-data-source-in-response/transform-data-source-in-response.module'; |
import { TransformDataSourceInResponseModule } from '@ghostfolio/api/interceptors/transform-data-source-in-response/transform-data-source-in-response.module'; |
||||
import { ConfigurationModule } from '@ghostfolio/api/services/configuration/configuration.module'; |
import { ConfigurationModule } from '@ghostfolio/api/services/configuration/configuration.module'; |
||||
import { ImpersonationModule } from '@ghostfolio/api/services/impersonation/impersonation.module'; |
import { ImpersonationModule } from '@ghostfolio/api/services/impersonation/impersonation.module'; |
||||
import { PrismaModule } from '@ghostfolio/api/services/prisma/prisma.module'; |
|
||||
import { PropertyModule } from '@ghostfolio/api/services/property/property.module'; |
import { PropertyModule } from '@ghostfolio/api/services/property/property.module'; |
||||
import { UserModule as UserServiceModule } from '@ghostfolio/api/services/user/user.module'; |
import { UserModule } from '@ghostfolio/api/services/user/user.module'; |
||||
|
|
||||
import { Module } from '@nestjs/common'; |
import { Module } from '@nestjs/common'; |
||||
import { JwtModule } from '@nestjs/jwt'; |
import { JwtModule } from '@nestjs/jwt'; |
||||
|
|
||||
import { UserController } from './user.controller'; |
import { UserController } from './user.controller'; |
||||
|
import { UsersController } from './users.controller'; |
||||
|
|
||||
@Module({ |
@Module({ |
||||
controllers: [UserController], |
controllers: [UserController, UsersController], |
||||
imports: [ |
imports: [ |
||||
|
AdminModule, |
||||
ConfigurationModule, |
ConfigurationModule, |
||||
ImpersonationModule, |
ImpersonationModule, |
||||
JwtModule.register({ |
JwtModule.register({ |
||||
secret: process.env.JWT_SECRET_KEY, |
secret: process.env.JWT_SECRET_KEY, |
||||
signOptions: { expiresIn: '30 days' } |
signOptions: { expiresIn: '30 days' } |
||||
}), |
}), |
||||
PrismaModule, |
|
||||
PropertyModule, |
PropertyModule, |
||||
RedactValuesInResponseModule, |
RedactValuesInResponseModule, |
||||
TransformDataSourceInResponseModule, |
TransformDataSourceInResponseModule, |
||||
UserServiceModule |
UserModule |
||||
] |
] |
||||
}) |
}) |
||||
export class UserModule {} |
export class UsersModule {} |
||||
Loading…
Reference in new issue