Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): doc level permission #9760

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading