mirror of
https://github.com/docmost/docmost.git
synced 2025-11-20 16:41:10 +10:00
frontend permissions
* rework backend workspace permissions
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import { IsOptional, IsString, MaxLength, MinLength } from 'class-validator';
|
||||
|
||||
export class CreateSpaceDto {
|
||||
@MinLength(4)
|
||||
@MinLength(2)
|
||||
@MaxLength(64)
|
||||
@IsString()
|
||||
name: string;
|
||||
@ -10,7 +10,7 @@ export class CreateSpaceDto {
|
||||
@IsString()
|
||||
description?: string;
|
||||
|
||||
@MinLength(4)
|
||||
@MinLength(2)
|
||||
@MaxLength(64)
|
||||
@IsString()
|
||||
slug: string;
|
||||
|
||||
@ -48,10 +48,6 @@ export class SpaceService {
|
||||
updateSpaceDto: UpdateSpaceDto,
|
||||
workspaceId: string,
|
||||
): Promise<Space> {
|
||||
if (!updateSpaceDto.name && !updateSpaceDto.description) {
|
||||
throw new BadRequestException('Please provide fields to update');
|
||||
}
|
||||
|
||||
return await this.spaceRepo.updateSpace(
|
||||
{
|
||||
name: updateSpaceDto.name,
|
||||
|
||||
@ -26,6 +26,8 @@ import {
|
||||
SpaceCaslSubject,
|
||||
} from '../casl/interfaces/space-ability.type';
|
||||
import { UpdateSpaceDto } from './dto/update-space.dto';
|
||||
import { findHighestUserSpaceRole } from '@docmost/db/repos/space/utils';
|
||||
import { SpaceMemberRepo } from '@docmost/db/repos/space/space-member.repo';
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('spaces')
|
||||
@ -33,6 +35,7 @@ export class SpaceController {
|
||||
constructor(
|
||||
private readonly spaceService: SpaceService,
|
||||
private readonly spaceMemberService: SpaceMemberService,
|
||||
private readonly spaceMemberRepo: SpaceMemberRepo,
|
||||
private readonly spaceAbility: SpaceAbilityFactory,
|
||||
) {}
|
||||
|
||||
@ -67,7 +70,20 @@ export class SpaceController {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
|
||||
return space;
|
||||
const userSpaceRoles = await this.spaceMemberRepo.getUserSpaceRoles(
|
||||
user.id,
|
||||
space.id,
|
||||
);
|
||||
|
||||
const userSpaceRole = findHighestUserSpaceRole(userSpaceRoles);
|
||||
|
||||
const membership = {
|
||||
userId: user.id,
|
||||
role: userSpaceRole,
|
||||
permissions: ability.rules,
|
||||
};
|
||||
|
||||
return { ...space, membership };
|
||||
}
|
||||
|
||||
@HttpCode(HttpStatus.OK)
|
||||
|
||||
Reference in New Issue
Block a user