Skip to content

Commit

Permalink
feat(server): doc level permission
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Jan 26, 2025
1 parent 6c8edb1 commit 8d89c5c
Show file tree
Hide file tree
Showing 33 changed files with 2,086 additions and 290 deletions.
4 changes: 2 additions & 2 deletions packages/backend/server/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ model WorkspaceUserPermission {
id String @id @default(uuid()) @db.VarChar
workspaceId String @map("workspace_id") @db.VarChar
userId String @map("user_id") @db.VarChar
// Read/Write
// Workspace Role, Owner/Admin/Collaborator/External
type Int @db.SmallInt
/// @deprecated Whether the permission invitation is accepted by the user
accepted Boolean @default(false)
Expand All @@ -165,7 +165,7 @@ model WorkspacePageUserPermission {
workspaceId String @map("workspace_id") @db.VarChar
pageId String @map("page_id") @db.VarChar
userId String @map("user_id") @db.VarChar
// Read/Write
// External/Reader/Editor/Manager/Owner
type Int @db.SmallInt
/// Whether the permission invitation is accepted by the user
accepted Boolean @default(false)
Expand Down
23 changes: 12 additions & 11 deletions packages/backend/server/src/__tests__/models/page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { PrismaClient } from '@prisma/client';
import ava, { TestFn } from 'ava';

import { Config } from '../../base/config';
import { Permission, PublicPageMode } from '../../models/common';
import { WorkspaceRole } from '../../core/permission';
import { PublicPageMode } from '../../models/common';
import { PageModel } from '../../models/page';
import { type User, UserModel } from '../../models/user';
import { type Workspace, WorkspaceModel } from '../../models/workspace';
Expand Down Expand Up @@ -131,28 +132,28 @@ test('should grant a member to access a page', async t => {
workspace.id,
'page1',
user.id,
Permission.Write
WorkspaceRole.Collaborator
);
t.false(hasAccess);
// grant write permission
await t.context.page.grantMember(
workspace.id,
'page1',
user.id,
Permission.Write
WorkspaceRole.Collaborator
);
hasAccess = await t.context.page.isMember(
workspace.id,
'page1',
user.id,
Permission.Write
WorkspaceRole.Collaborator
);
t.true(hasAccess);
hasAccess = await t.context.page.isMember(
workspace.id,
'page1',
user.id,
Permission.Read
WorkspaceRole.Collaborator
);
t.true(hasAccess);
// delete member
Expand All @@ -174,14 +175,14 @@ test('should change the page owner', async t => {
workspace.id,
'page1',
user.id,
Permission.Owner
WorkspaceRole.Owner
);
t.true(
await t.context.page.isMember(
workspace.id,
'page1',
user.id,
Permission.Owner
WorkspaceRole.Owner
)
);

Expand All @@ -193,22 +194,22 @@ test('should change the page owner', async t => {
workspace.id,
'page1',
otherUser.id,
Permission.Owner
WorkspaceRole.Owner
);
t.true(
await t.context.page.isMember(
workspace.id,
'page1',
otherUser.id,
Permission.Owner
WorkspaceRole.Owner
)
);
t.false(
await t.context.page.isMember(
workspace.id,
'page1',
user.id,
Permission.Owner
WorkspaceRole.Owner
)
);
});
Expand All @@ -221,7 +222,7 @@ test('should not delete owner from page', async t => {
workspace.id,
'page1',
user.id,
Permission.Owner
WorkspaceRole.Owner
);
const count = await t.context.page.deleteMember(
workspace.id,
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/server/src/__tests__/models/user.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ava, { TestFn } from 'ava';
import Sinon from 'sinon';

import { EmailAlreadyUsed, EventBus } from '../../base';
import { Permission } from '../../models/common';
import { WorkspaceRole } from '../../core/permission';
import { UserModel } from '../../models/user';
import { WorkspaceMemberStatus } from '../../models/workspace';
import { createTestingModule, initTestingDB } from '../utils';
Expand Down Expand Up @@ -263,7 +263,7 @@ test('should trigger user.deleted event', async t => {
public: false,
},
},
type: Permission.Owner,
type: WorkspaceRole.Owner,
status: WorkspaceMemberStatus.Accepted,
},
},
Expand Down
Loading

0 comments on commit 8d89c5c

Please sign in to comment.