refactor: rename all page query to doc (#10019)

This commit is contained in:
forehalo
2025-02-07 11:40:59 +00:00
parent 4e00ddd5f1
commit 0b9d30b55a
34 changed files with 658 additions and 643 deletions
@@ -49,7 +49,7 @@ test.after(async t => {
test('should create page with default mode and public false', async t => {
const page = await t.context.page.upsert(workspace.id, 'page1');
t.is(page.workspaceId, workspace.id);
t.is(page.pageId, 'page1');
t.is(page.docId, 'page1');
t.is(page.mode, PublicPageMode.Page);
t.is(page.public, false);
});
@@ -110,7 +110,7 @@ test('should get public pages of a workspace', async t => {
await t.context.page.upsert(workspace.id, 'page3');
const pages = await t.context.page.findPublics(workspace.id);
t.is(pages.length, 2);
t.deepEqual(pages.map(p => p.pageId).sort(), ['page1', 'page2']);
t.deepEqual(pages.map(p => p.docId).sort(), ['page1', 'page2']);
});
test('should grant a member to access a page', async t => {
@@ -23,6 +23,7 @@ import {
createInviteLink,
createTestingApp,
createWorkspace,
docGrantedUsersList,
getInviteInfo,
getInviteLink,
getWorkspace,
@@ -31,7 +32,6 @@ import {
inviteUser,
inviteUsers,
leaveWorkspace,
pageGrantedUsersList,
revokeDocUserRoles,
revokeInviteLink,
revokeMember,
@@ -39,7 +39,7 @@ import {
signUp,
sleep,
TestingApp,
updatePageDefaultRole,
updateDocDefaultRole,
UserAuthedType,
} from './utils';
@@ -817,13 +817,13 @@ test('should be able to grant and revoke users role in page', async t => {
read,
external,
} = await init(app, 5);
const pageId = nanoid();
const docId = nanoid();
const res = await grantDocUserRoles(
app,
admin.token.token,
ws.id,
pageId,
docId,
[read.id, write.id],
DocRole.Manager
);
@@ -840,7 +840,7 @@ test('should be able to grant and revoke users role in page', async t => {
app,
admin.token.token,
ws.id,
pageId,
docId,
[read.id],
DocRole.Reader
);
@@ -849,7 +849,7 @@ test('should be able to grant and revoke users role in page', async t => {
app,
read.token.token,
ws.id,
pageId,
docId,
[external.id],
DocRole.Editor
);
@@ -859,15 +859,15 @@ test('should be able to grant and revoke users role in page', async t => {
},
});
const pageUsersList = await pageGrantedUsersList(
const docUsersList = await docGrantedUsersList(
app,
admin.token.token,
ws.id,
pageId
docId
);
t.is(pageUsersList.data.workspace.pageGrantedUsersList.totalCount, 3);
t.is(docUsersList.data.workspace.doc.grantedUsersList.totalCount, 3);
const externalRole =
pageUsersList.data.workspace.pageGrantedUsersList.edges.find(
docUsersList.data.workspace.doc.grantedUsersList.edges.find(
(edge: any) => edge.node.user.id === external.id
)?.node.role;
t.is(externalRole, DocRole[DocRole.Editor]);
@@ -877,18 +877,18 @@ test('should be able to grant and revoke users role in page', async t => {
test('should be able to change the default role in page', async t => {
const { app } = t.context;
const { teamWorkspace: ws, admin } = await init(app, 5);
const pageId = nanoid();
const res = await updatePageDefaultRole(
const docId = nanoid();
const res = await updateDocDefaultRole(
app,
admin.token.token,
ws.id,
pageId,
docId,
DocRole.Reader
);
t.deepEqual(res.body, {
data: {
updatePageDefaultRole: true,
updateDocDefaultRole: true,
},
});
});
@@ -902,53 +902,53 @@ test('default page role should be able to override the workspace role', async t
external,
} = await init(app, 5);
const pageId = nanoid();
const docId = nanoid();
const res = await updatePageDefaultRole(
const res = await updateDocDefaultRole(
app,
admin.token.token,
workspace.id,
pageId,
docId,
DocRole.Manager
);
t.deepEqual(res.body, {
data: {
updatePageDefaultRole: true,
updateDocDefaultRole: true,
},
});
// reader can manage the page if the page default role is Manager
{
const readerRes = await updatePageDefaultRole(
const readerRes = await updateDocDefaultRole(
app,
read.token.token,
workspace.id,
pageId,
docId,
DocRole.Manager
);
t.deepEqual(readerRes.body, {
data: {
updatePageDefaultRole: true,
updateDocDefaultRole: true,
},
});
}
// external can't manage the page even if the page default role is Manager
{
const externalRes = await updatePageDefaultRole(
const externalRes = await updateDocDefaultRole(
app,
external.token.token,
workspace.id,
pageId,
docId,
DocRole.Manager
);
t.like(externalRes.body, {
errors: [
{
message: `You do not have permission to access doc ${pageId} under Space ${workspace.id}.`,
message: `You do not have permission to access doc ${docId} under Space ${workspace.id}.`,
},
],
});
@@ -958,13 +958,13 @@ test('default page role should be able to override the workspace role', async t
test('should be able to grant and revoke doc user role', async t => {
const { app } = t.context;
const { teamWorkspace: ws, admin, read, external } = await init(app, 5);
const pageId = nanoid();
const docId = nanoid();
const res = await grantDocUserRoles(
app,
admin.token.token,
ws.id,
pageId,
docId,
[external.id],
DocRole.Manager
);
@@ -981,7 +981,7 @@ test('should be able to grant and revoke doc user role', async t => {
app,
external.token.token,
ws.id,
pageId,
docId,
[read.id],
DocRole.Manager
);
@@ -999,7 +999,7 @@ test('should be able to grant and revoke doc user role', async t => {
app,
admin.token.token,
ws.id,
pageId,
docId,
external.id
);
@@ -1014,14 +1014,14 @@ test('should be able to grant and revoke doc user role', async t => {
app,
external.token.token,
ws.id,
pageId,
docId,
read.id
);
t.like(externalRes.body, {
errors: [
{
message: `You do not have permission to access doc ${pageId} under Space ${ws.id}.`,
message: `You do not have permission to access doc ${docId} under Space ${ws.id}.`,
},
],
});
@@ -1031,7 +1031,7 @@ test('should be able to grant and revoke doc user role', async t => {
test('update page default role should throw error if the space does not exist', async t => {
const { app } = t.context;
const { admin } = await init(app, 5);
const pageId = nanoid();
const docId = nanoid();
const nonExistWorkspaceId = 'non-exist-workspace';
const res = await request(app.getHttpServer())
.post('/graphql')
@@ -1040,9 +1040,9 @@ test('update page default role should throw error if the space does not exist',
.send({
query: `
mutation {
updatePageDefaultRole(input: {
updateDocDefaultRole(input: {
workspaceId: "${nonExistWorkspaceId}",
docId: "${pageId}",
docId: "${docId}",
role: Manager,
})
}
@@ -1052,7 +1052,7 @@ test('update page default role should throw error if the space does not exist',
t.like(res.body, {
errors: [
{
message: `You do not have permission to access doc ${pageId} under Space ${nonExistWorkspaceId}.`,
message: `You do not have permission to access doc ${docId} under Space ${nonExistWorkspaceId}.`,
},
],
});
@@ -54,7 +54,7 @@ export function revokeDocUserRoles(
});
}
export function updatePageDefaultRole(
export function updateDocDefaultRole(
app: INestApplication,
token: string,
workspaceId: string,
@@ -68,7 +68,7 @@ export function updatePageDefaultRole(
.send({
query: `
mutation {
updatePageDefaultRole(input: {
updateDocDefaultRole(input: {
workspaceId: "${workspaceId}",
docId: "${docId}",
role: ${DocRole[role]}
@@ -78,7 +78,7 @@ export function updatePageDefaultRole(
});
}
export async function pageGrantedUsersList(
export async function docGrantedUsersList(
app: INestApplication,
token: string,
workspaceId: string,
@@ -94,14 +94,16 @@ export async function pageGrantedUsersList(
query: `
query {
workspace(id: "${workspaceId}") {
pageGrantedUsersList(pageId: "${docId}", pagination: { first: ${first}, offset: ${offset} }) {
totalCount
edges {
doc(docId: "${docId}") {
grantedUsersList(pagination: { first: ${first}, offset: ${offset} }) {
totalCount
edges {
cursor
node {
role
user {
id
node {
role
user {
id
}
}
}
}
@@ -103,11 +103,11 @@ export async function updateWorkspace(
return res.body.data.updateWorkspace.public;
}
export async function publishPage(
export async function publishDoc(
app: INestApplication,
token: string,
workspaceId: string,
pageId: string
docId: string
) {
const res = await request(app.getHttpServer())
.post(gql)
@@ -116,7 +116,7 @@ export async function publishPage(
.send({
query: `
mutation {
publishPage(workspaceId: "${workspaceId}", pageId: "${pageId}") {
publishDoc(workspaceId: "${workspaceId}", docId: "${docId}") {
id
mode
}
@@ -124,14 +124,14 @@ export async function publishPage(
`,
})
.expect(200);
return res.body.errors?.[0]?.message || res.body.data?.publishPage;
return res.body.errors?.[0]?.message || res.body.data?.publishDoc;
}
export async function revokePublicPage(
export async function revokePublicDoc(
app: INestApplication,
token: string,
workspaceId: string,
pageId: string
docId: string
) {
const res = await request(app.getHttpServer())
.post(gql)
@@ -140,7 +140,7 @@ export async function revokePublicPage(
.send({
query: `
mutation {
revokePublicPage(workspaceId: "${workspaceId}", pageId: "${pageId}") {
revokePublicDoc(workspaceId: "${workspaceId}", docId: "${docId}") {
id
mode
public
@@ -149,7 +149,7 @@ export async function revokePublicPage(
`,
})
.expect(200);
return res.body.errors?.[0]?.message || res.body.data?.revokePublicPage;
return res.body.errors?.[0]?.message || res.body.data?.revokePublicDoc;
}
export async function grantMember(
@@ -10,8 +10,8 @@ import {
createWorkspace,
getWorkspacePublicPages,
inviteUser,
publishPage,
revokePublicPage,
publishDoc,
revokePublicDoc,
signUp,
TestingApp,
updateWorkspace,
@@ -83,8 +83,8 @@ test('should share a page', async t => {
const workspace = await createWorkspace(app, u1.token.token);
const share = await publishPage(app, u1.token.token, workspace.id, 'page1');
t.is(share.id, 'page1', 'failed to share page');
const share = await publishDoc(app, u1.token.token, workspace.id, 'doc1');
t.is(share.id, 'doc1', 'failed to share doc');
const pages = await getWorkspacePublicPages(
app,
u1.token.token,
@@ -93,8 +93,8 @@ test('should share a page', async t => {
t.is(pages.length, 1, 'failed to get shared pages');
t.deepEqual(
pages[0],
{ id: 'page1', mode: 'Page' },
'failed to get shared page: page1'
{ id: 'doc1', mode: 'Page' },
'failed to get shared doc: doc1'
);
const resp1 = await request(app.getHttpServer())
@@ -107,53 +107,48 @@ test('should share a page', async t => {
t.is(resp2.statusCode, 200, 'failed to get root doc with public pages');
const resp3 = await request(app.getHttpServer())
.get(`/api/workspaces/${workspace.id}/docs/page1`)
.get(`/api/workspaces/${workspace.id}/docs/doc1`)
.auth(u1.token.token, { type: 'bearer' });
// 404 because we don't put the page doc to server
t.is(resp3.statusCode, 404, 'failed to get shared doc with u1 token');
const resp4 = await request(app.getHttpServer()).get(
`/api/workspaces/${workspace.id}/docs/page1`
`/api/workspaces/${workspace.id}/docs/doc1`
);
// 404 because we don't put the page doc to server
t.is(resp4.statusCode, 404, 'should not get shared doc without token');
const msg1 = await publishPage(app, u2.token.token, 'not_exists_ws', 'page2');
const msg1 = await publishDoc(app, u2.token.token, 'not_exists_ws', 'doc2');
t.is(
msg1,
'You do not have permission to access doc page2 under Space not_exists_ws.',
'unauthorized user can share page'
'You do not have permission to access doc doc2 under Space not_exists_ws.',
'unauthorized user can share doc'
);
const msg2 = await revokePublicPage(
const msg2 = await revokePublicDoc(
app,
u2.token.token,
'not_exists_ws',
'page2'
'doc2'
);
t.is(
msg2,
'You do not have permission to access doc page2 under Space not_exists_ws.',
'unauthorized user can share page'
'You do not have permission to access doc doc2 under Space not_exists_ws.',
'unauthorized user can share doc'
);
const revoke = await revokePublicPage(
const revoke = await revokePublicDoc(
app,
u1.token.token,
workspace.id,
'page1'
'doc1'
);
t.false(revoke.public, 'failed to revoke page');
t.false(revoke.public, 'failed to revoke doc');
const pages2 = await getWorkspacePublicPages(
app,
u1.token.token,
workspace.id
);
t.is(pages2.length, 0, 'failed to get shared pages');
const msg4 = await revokePublicPage(
app,
u1.token.token,
workspace.id,
'page3'
);
t.is(msg4, 'Page is not public');
const msg4 = await revokePublicDoc(app, u1.token.token, workspace.id, 'doc3');
t.is(msg4, 'Doc is not public');
const pages3 = await getWorkspacePublicPages(
app,
@@ -41,7 +41,7 @@ test.before(async t => {
t.context.storage = app.get(WorkspaceBlobStorage);
t.context.workspace = app.get(PgWorkspaceDocStorageAdapter);
await db.workspacePage.create({
await db.workspaceDoc.create({
data: {
workspace: {
create: {
@@ -49,12 +49,12 @@ test.before(async t => {
public: true,
},
},
pageId: 'private',
docId: 'private',
public: false,
},
});
await db.workspacePage.create({
await db.workspaceDoc.create({
data: {
workspace: {
create: {
@@ -62,12 +62,12 @@ test.before(async t => {
public: false,
},
},
pageId: 'public',
docId: 'public',
public: true,
},
});
await db.workspacePage.create({
await db.workspaceDoc.create({
data: {
workspace: {
create: {
@@ -75,7 +75,7 @@ test.before(async t => {
public: false,
},
},
pageId: 'private',
docId: 'private',
public: false,
},
});
@@ -261,8 +261,8 @@ test('should be able to change page publish mode', async t => {
t.is(res.status, HttpStatus.OK);
t.is(res.get('publish-mode'), 'page');
await db.workspacePage.update({
where: { workspaceId_pageId: { workspaceId: 'private', pageId: 'public' } },
await db.workspaceDoc.update({
where: { workspaceId_docId: { workspaceId: 'private', docId: 'public' } },
data: { mode: 1 },
});