fix and update
This commit is contained in:
@@ -3,7 +3,7 @@ import { ApiBearerAuth, ApiBody, ApiOperation, ApiParam, ApiTags } from '@nestjs
|
||||
import { map } from 'rxjs';
|
||||
import { CoreGrpcService } from '../core-grpc.service';
|
||||
import { CurrentAdmin } from '../decorators/current-admin.decorator';
|
||||
import { ListUsersQueryDto, ResetPasswordDto, SetSuperAdminDto, UpdateUserDto } from '../dto/admin.dto';
|
||||
import { ListUsersQueryDto, ResetPasswordDto, SetSuperAdminDto, SetUserVerificationDto, UpdateUserDto } from '../dto/admin.dto';
|
||||
import { AdminGuard, AdminRequestUser, assertAdminPermission, SuperAdminGuard } from '../guards/admin.guard';
|
||||
|
||||
@ApiTags('Администрирование')
|
||||
@@ -32,6 +32,15 @@ export class AdminController {
|
||||
);
|
||||
}
|
||||
|
||||
@Get('verification-icons')
|
||||
@ApiOperation({ summary: 'Список значков верификации', description: 'Доступные значки для выбора при верификации пользователя.' })
|
||||
listVerificationIcons(@CurrentAdmin() admin: AdminRequestUser) {
|
||||
if (!admin.canVerifyUsers) {
|
||||
throw new ForbiddenException('Недостаточно прав для верификации пользователей');
|
||||
}
|
||||
return this.core.admin.ListVerificationIcons({});
|
||||
}
|
||||
|
||||
@Patch(':userId')
|
||||
@ApiOperation({ summary: 'Обновить профиль пользователя', description: 'Обновляет основные и резервные контакты пользователя.' })
|
||||
@ApiParam({ name: 'userId', description: 'ID пользователя' })
|
||||
@@ -66,4 +75,20 @@ export class AdminController {
|
||||
setSuperAdmin(@Param('userId') userId: string, @Body() dto: SetSuperAdminDto, @CurrentAdmin() admin: AdminRequestUser) {
|
||||
return this.core.admin.SetSuperAdmin({ actorUserId: admin.id, userId, isSuperAdmin: dto.isSuperAdmin });
|
||||
}
|
||||
|
||||
@Patch(':userId/verification')
|
||||
@ApiOperation({ summary: 'Верифицировать или снять верификацию', description: 'Требуется право users.verify.' })
|
||||
@ApiParam({ name: 'userId', description: 'ID пользователя' })
|
||||
@ApiBody({ type: SetUserVerificationDto })
|
||||
setUserVerification(@Param('userId') userId: string, @Body() dto: SetUserVerificationDto, @CurrentAdmin() admin: AdminRequestUser) {
|
||||
if (!admin.canVerifyUsers) {
|
||||
throw new ForbiddenException('Недостаточно прав для верификации пользователей');
|
||||
}
|
||||
return this.core.admin.SetUserVerification({
|
||||
actorUserId: admin.id,
|
||||
userId,
|
||||
isVerified: dto.isVerified,
|
||||
verificationIcon: dto.verificationIcon
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,3 +58,14 @@ export class SetSuperAdminDto {
|
||||
@IsBoolean({ message: 'isSuperAdmin должно быть boolean' })
|
||||
isSuperAdmin!: boolean;
|
||||
}
|
||||
|
||||
export class SetUserVerificationDto {
|
||||
@ApiProperty({ description: 'Верифицировать или снять верификацию' })
|
||||
@IsBoolean({ message: 'isVerified должно быть boolean' })
|
||||
isVerified!: boolean;
|
||||
|
||||
@ApiPropertyOptional({ description: 'Slug значка из списка (badge-check, star, moon и т.д.)' })
|
||||
@IsOptional()
|
||||
@IsString({ message: 'Значок должен быть строкой' })
|
||||
verificationIcon?: string;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ export interface AdminRequestUser {
|
||||
canManageAllUsers: boolean;
|
||||
canViewUsers: boolean;
|
||||
canManageSettings: boolean;
|
||||
canVerifyUsers: boolean;
|
||||
roles: string[];
|
||||
permissions: string[];
|
||||
}
|
||||
@@ -58,6 +59,7 @@ export class AdminGuard implements CanActivate {
|
||||
canManageAllUsers: Boolean(profile.canManageAllUsers),
|
||||
canManageSettings: Boolean(profile.canManageSettings),
|
||||
canViewUsers: Boolean(profile.canViewUsers),
|
||||
canVerifyUsers: Boolean(profile.canVerifyUsers),
|
||||
roles: profile.roles ?? [],
|
||||
permissions: profile.permissions ?? []
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user