fix: sửa lỗi các nút bị che dưới thanh địa chỉ của chrome, hỗ trợ iphone upload ảnh heic
This commit is contained in:
+39
-4
@@ -1640,14 +1640,16 @@ class PhotoController {
|
||||
}
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('users')
|
||||
@Roles(ParticipantRole.OWNER, ParticipantRole.MANAGER) // Default roles for User management (Admin/Manager)
|
||||
class UserController {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
@Get()
|
||||
@UseGuards(AdminGuard)
|
||||
async getAllUsers(@Req() req: any, @Query('q') q?: string) {
|
||||
const currentUserId = req.user?.sub;
|
||||
const currentUserId = req.user?.id;
|
||||
const users = await this.prisma.user.findMany({
|
||||
where: q
|
||||
? {
|
||||
@@ -1677,11 +1679,36 @@ class UserController {
|
||||
|
||||
@Roles(ParticipantRole.OWNER, ParticipantRole.MANAGER) // Default roles for updating user (Admin/Manager)
|
||||
@Patch(':id')
|
||||
async updateUser(@Param('id', ParseUUIDPipe) id: string, @Body() data: any) {
|
||||
async updateUser(@Param('id', ParseUUIDPipe) id: string, @Body() data: any, @Req() req: any) {
|
||||
const requestingUser = req.user;
|
||||
|
||||
// Fetch target user from DB
|
||||
const targetUser = await this.prisma.user.findUnique({ where: { id } });
|
||||
if (!targetUser) {
|
||||
throw new NotFoundException('Không tìm thấy người dùng');
|
||||
}
|
||||
|
||||
// 1. If target user is an Admin, only an Admin can update them.
|
||||
// (A manager/normal user cannot reset/change password of an Admin)
|
||||
if (targetUser.isAdmin && !requestingUser.isAdmin) {
|
||||
throw new ForbiddenException('Không có quyền thay đổi thông tin hoặc reset password của Quản trị viên');
|
||||
}
|
||||
|
||||
// 2. A non-admin can only update their own profile.
|
||||
if (!requestingUser.isAdmin && requestingUser.id !== id) {
|
||||
throw new ForbiddenException('Bạn không có quyền thực hiện hành động này');
|
||||
}
|
||||
|
||||
if (data.password) {
|
||||
data.passwordHash = await bcrypt.hash(data.password, 10);
|
||||
delete data.password;
|
||||
}
|
||||
|
||||
// Safety: prevent non-admins from promoting anyone to admin
|
||||
if (!requestingUser.isAdmin && data.isAdmin !== undefined) {
|
||||
delete data.isAdmin;
|
||||
}
|
||||
|
||||
return this.prisma.user.update({
|
||||
where: { id },
|
||||
data,
|
||||
@@ -1691,7 +1718,8 @@ class UserController {
|
||||
|
||||
@Roles(ParticipantRole.OWNER) // Only owner can delete user
|
||||
@Delete(':id')
|
||||
async deleteUser(@Param('id', ParseUUIDPipe) id: string) {
|
||||
@UseGuards(AdminGuard)
|
||||
async deleteUser(@Param('id', ParseUUIDPipe) id: string, @Req() req: any) {
|
||||
const user = await this.prisma.user.findUnique({ where: { id } });
|
||||
if (!user) throw new NotFoundException('Không tìm thấy người dùng');
|
||||
if (user.isAdmin) {
|
||||
@@ -1729,9 +1757,16 @@ class UserController {
|
||||
|
||||
@Roles(ParticipantRole.OWNER, ParticipantRole.MANAGER) // Default roles for blocking user (Admin/Manager)
|
||||
@Post('block/:id')
|
||||
async toggleBlock(@Param('id', ParseUUIDPipe) id: string) {
|
||||
@UseGuards(AdminGuard)
|
||||
async toggleBlock(@Param('id', ParseUUIDPipe) id: string, @Req() req: any) {
|
||||
const user = await this.prisma.user.findUnique({ where: { id } });
|
||||
if (!user) throw new NotFoundException('Người dùng không tồn tại');
|
||||
|
||||
// Safety check: Cannot block an Admin
|
||||
if (user.isAdmin) {
|
||||
throw new BadRequestException('Không thể khóa tài khoản Quản trị viên');
|
||||
}
|
||||
|
||||
const updated = await this.prisma.user.update({
|
||||
where: { id },
|
||||
data: { isBlocked: !user.isBlocked },
|
||||
|
||||
Reference in New Issue
Block a user