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:
fengmk2 2025-06-24 19:40:21 +08:00 committed by GitHub
parent 3186fb8306
commit f0671cf2dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 43 additions and 2 deletions

View File

@ -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 { 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.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);
}
);

View File

@ -304,11 +304,13 @@ export class WorkspaceDocResolver {
await this.tryFixDocOwner(workspace.id, docId);
const isPublic = await this.models.doc.isPublic(workspace.id, docId);
return {
docId,
workspaceId: workspace.id,
mode: PublicDocMode.Page,
public: false,
public: isPublic,
defaultRole: DocRole.Manager,
};
}