Skip to content

Commit cde4e1d

Browse files
committed
docs(docs): make permission examples executable
1 parent e904ce8 commit cde4e1d

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

packages/docs/src/controllers/__tests__/doc-permission.controller.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ describe('DocPermissionController', () => {
124124

125125
it('uses section and paragraph ids as hierarchical edit boundaries', async () => {
126126
const firstSection = document.getSection(0)!;
127-
const firstParagraph = document.getParagraph('paragraph-one')!;
127+
const firstParagraph = document.getParagraphs()[0];
128128
const secondParagraph = document.getParagraph('paragraph-two')!;
129+
if (!firstParagraph) throw new Error('Paragraph not found.');
129130

130131
await firstSection.getPermission().setReadOnly();
131132

@@ -206,9 +207,11 @@ describe('DocPermissionController', () => {
206207
univer = testBed.univer;
207208
get = testBed.get;
208209
document = testBed.univerAPI.getActiveDocument()!;
209-
await document.getEntityPermission('', 'drawing', 'drawing-one').setEditable(false);
210+
const drawingId = document.getDocumentDataModel().getSnapshot().drawingsOrder?.[0];
211+
if (!drawingId) throw new Error('Drawing not found.');
212+
await document.getEntityPermission('', 'drawing', drawingId).setReadOnly();
210213
const actions = JSONX.getInstance().replaceOp(
211-
['drawings', 'drawing-one', 'docTransform', 'angle'],
214+
['drawings', drawingId, 'docTransform', 'angle'],
212215
0,
213216
15
214217
);
@@ -219,7 +222,7 @@ describe('DocPermissionController', () => {
219222
actions,
220223
textRanges: [],
221224
})).toBe(false);
222-
expect(document.getDocumentDataModel().getSnapshot().drawings?.['drawing-one'].docTransform?.angle).toBe(0);
225+
expect(document.getDocumentDataModel().getSnapshot().drawings?.[drawingId].docTransform?.angle).toBe(0);
223226
});
224227

225228
it('enforces paragraph permission on direct RichText mutations used by paste and undo/redo', async () => {

packages/docs/src/facade/f-document-permission.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class FDocumentObjectPermission {
150150
* @example Restore editing for a paragraph
151151
* ```ts
152152
* const document = univerAPI.getActiveDocument();
153-
* const paragraph = document?.getParagraph('paragraph-1');
153+
* const paragraph = document?.getParagraphs()[0];
154154
* if (!paragraph) throw new Error('Paragraph not found.');
155155
* await paragraph.getPermission().setEditable();
156156
* ```

packages/docs/src/facade/f-document.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,14 @@ export class FDocument extends FBaseInitialable {
207207
* @param {string} entityType Stable entity type used by the owning Doc feature.
208208
* @param {string} entityId Stable entity id.
209209
* @returns {FDocumentObjectPermission} Effective permission facade for the entity.
210-
* @example Make one table read-only
210+
* @example Make one drawing read-only
211211
* ```ts
212212
* const document = univerAPI.getActiveDocument();
213213
* if (!document) throw new Error('No active Document.');
214-
* await document.getEntityPermission('', 'table', 'table-1').setReadOnly();
214+
* const snapshot = document.getDocumentDataModel().getSnapshot();
215+
* const drawingId = snapshot.drawingsOrder?.[0];
216+
* if (!drawingId) throw new Error('Drawing not found.');
217+
* await document.getEntityPermission('', 'drawing', drawingId).setReadOnly();
215218
* ```
216219
*/
217220
getEntityPermission(segmentId: string, entityType: string, entityId: string): FDocumentObjectPermission {

0 commit comments

Comments
 (0)