fix(server): should check doc public attribute when snapshot not exists (#12913)
close CLOUD-232 #### PR Dependency Tree * **PR #12913** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - The visibility status of documents now accurately reflects their public status instead of always showing as private. - **Tests** - Added an end-to-end test to verify correct handling of the public attribute for documents without snapshots. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -1,4 +1,10 @@
|
|||||||
import { getRecentlyUpdatedDocsQuery } from '@affine/graphql';
|
import { randomUUID } from 'node:crypto';
|
||||||
|
|
||||||
|
import {
|
||||||
|
getRecentlyUpdatedDocsQuery,
|
||||||
|
getWorkspacePageByIdQuery,
|
||||||
|
publishPageMutation,
|
||||||
|
} from '@affine/graphql';
|
||||||
|
|
||||||
import { Mockers } from '../../mocks';
|
import { Mockers } from '../../mocks';
|
||||||
import { app, e2e } from '../test';
|
import { app, e2e } from '../test';
|
||||||
@@ -60,3 +66,36 @@ e2e('should get recently updated docs', async t => {
|
|||||||
t.is(recentlyUpdatedDocs.edges[2].node.id, doc1.docId);
|
t.is(recentlyUpdatedDocs.edges[2].node.id, doc1.docId);
|
||||||
t.is(recentlyUpdatedDocs.edges[2].node.title, doc1.title);
|
t.is(recentlyUpdatedDocs.edges[2].node.title, doc1.title);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
e2e(
|
||||||
|
'should get doc with public attribute when doc snapshot not exists',
|
||||||
|
async t => {
|
||||||
|
const owner = await app.signup();
|
||||||
|
|
||||||
|
const workspace = await app.create(Mockers.Workspace, {
|
||||||
|
owner: { id: owner.id },
|
||||||
|
});
|
||||||
|
|
||||||
|
const docId = randomUUID();
|
||||||
|
|
||||||
|
// default public is false
|
||||||
|
const result1 = await app.gql({
|
||||||
|
query: getWorkspacePageByIdQuery,
|
||||||
|
variables: { workspaceId: workspace.id, pageId: docId },
|
||||||
|
});
|
||||||
|
|
||||||
|
t.is(result1.workspace.doc.public, false);
|
||||||
|
|
||||||
|
await app.gql({
|
||||||
|
query: publishPageMutation,
|
||||||
|
variables: { workspaceId: workspace.id, pageId: docId },
|
||||||
|
});
|
||||||
|
|
||||||
|
const result2 = await app.gql({
|
||||||
|
query: getWorkspacePageByIdQuery,
|
||||||
|
variables: { workspaceId: workspace.id, pageId: docId },
|
||||||
|
});
|
||||||
|
|
||||||
|
t.is(result2.workspace.doc.public, true);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|||||||
@@ -304,11 +304,13 @@ export class WorkspaceDocResolver {
|
|||||||
|
|
||||||
await this.tryFixDocOwner(workspace.id, docId);
|
await this.tryFixDocOwner(workspace.id, docId);
|
||||||
|
|
||||||
|
const isPublic = await this.models.doc.isPublic(workspace.id, docId);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
docId,
|
docId,
|
||||||
workspaceId: workspace.id,
|
workspaceId: workspace.id,
|
||||||
mode: PublicDocMode.Page,
|
mode: PublicDocMode.Page,
|
||||||
public: false,
|
public: isPublic,
|
||||||
defaultRole: DocRole.Manager,
|
defaultRole: DocRole.Manager,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user