frontend permissions

* rework backend workspace permissions
This commit is contained in:
Philipinho
2024-06-03 02:54:12 +01:00
parent b88e0b605f
commit 886d9591fa
54 changed files with 715 additions and 385 deletions

View File

@ -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;

View File

@ -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,

View File

@ -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)