|
| 1 | +# User-based restrict editing and approval workflow in JavaScript DOCX Editor (Document Editor) |
| 2 | + |
| 3 | +This sample demonstrates the user-based document restrictions and approval workflows of the [Syncfusion® JavaScript DOCX Editor](https://www.syncfusion.com/docx-editor-sdk/javascript-docx-editor?utm_source=github&utm_medium=github&utm_campaign=github-javascript-es6-docx-editor-examples) (Document Editor). The loaded Adventure Works Cycles document (`data-document-protection.json`) contains user-based editable ranges for Nancy's price values, and each user's restrictions are applied on the fly when a user is selected from the dropdown. |
| 4 | + |
| 5 | +## Demo |
| 6 | + |
| 7 | +* **Nancy** (nancy@example.com) – Price Editor: can edit only the price values that are marked as editable ranges for her in the loaded document. |
| 8 | +* **Andrew** (andrew@example.com) – Reviewer: all edits are tracked as revisions (`RevisionsOnly` protection), and he cannot accept or reject revisions. |
| 9 | +* **Steven** (steven@example.com) – Commenter: can insert comments only (`CommentsOnly` protection) and cannot edit the document content. |
| 10 | +* **Michael** (michael@example.com) – Editor: full editing access on the entire document (no protection applied) and reviews the tracked changes. |
| 11 | +* **Laura** (laura@example.com) – Viewer: read-only access and can export the document as DOCX and PDF only. |
| 12 | + |
| 13 | +Select a user in the dropdown on the right to switch the document restrictions between the roles, and use the table below the dropdown to see each user's permissions at a glance. |
| 14 | + |
| 15 | +## How it works |
| 16 | + |
| 17 | +1. The sample loads the Adventure Works Cycles SFDT document from `data-document-protection.json`. The attached SFDT already holds the user-based editable ranges (Nancy's price values) along with a ReadOnly protection (hash and salt), so it opens in the protected mode. |
| 18 | +2. When a user is selected, the previous document protection is stopped and the protection type of the new user is enforced through `documentEditor.editorModule.enforceProtection`: |
| 19 | + * `RevisionsOnly` – for Andrew, so all his edits are tracked. |
| 20 | + * `CommentsOnly` – for Steven, so he can only add comments. |
| 21 | + * `NoProtection` – for Michael, so he has full editing access. |
| 22 | + * `ReadOnly` – for Nancy (only her editable ranges can be edited) and Laura (no editable ranges, so the document is fully read-only). |
| 23 | +3. For Laura, the container is also set to read-only (`documentEditor.isReadOnly = true`), leaving only the custom **Export as DOCX** and **Export as PDF** buttons available for exporting the document. |
| 24 | +4. The approval workflow is demonstrated with the `beforeAcceptRejectChanges` event of the Document Editor: Andrew's accept/reject actions are cancelled, so the tracked changes can only be approved by a user with approval rights (Michael). |
| 25 | + |
| 26 | +## Project structure |
| 27 | + |
| 28 | +``` |
| 29 | +document-protection/ |
| 30 | +├── e2e/ # End-to-end test configuration |
| 31 | +├── license/ # License information |
| 32 | +├── src/ |
| 33 | +│ ├── app/ |
| 34 | +│ │ └── app.ts # Sample source code |
| 35 | +│ ├── resources/ |
| 36 | +│ │ └── data/ |
| 37 | +│ │ └── data-document-protection.json # Adventure Works Cycles SFDT with user-based editable ranges |
| 38 | +│ ├── styles/ |
| 39 | +│ │ └── styles.css # Sample styles |
| 40 | +│ └── index.html # Sample page |
| 41 | +├── gulpfile.js # Build and test tasks |
| 42 | +├── package.json # Project configuration |
| 43 | +├── tsconfig.json # TypeScript configuration |
| 44 | +└── webpack.config.js # Webpack configuration |
| 45 | +``` |
| 46 | + |
| 47 | +## How to run this sample |
| 48 | + |
| 49 | +1. Clone the [JavaScript (ES6) DOCX Editor examples](https://github.com/SyncfusionExamples/JavaScript-ES6-DOCX-Editor-Examples) repository. |
| 50 | +2. Navigate to the `document-protection` directory and install the dependencies: |
| 51 | + |
| 52 | + ``` |
| 53 | + npm install |
| 54 | + ``` |
| 55 | + |
| 56 | +3. Start the sample: |
| 57 | + |
| 58 | + ``` |
| 59 | + npm start |
| 60 | + ``` |
| 61 | + |
| 62 | +4. The sample will be available in the browser. Select a user in the dropdown to apply that user's document restrictions: |
| 63 | + * Nancy – try editing a price value (allowed) and any other text (blocked). |
| 64 | + * Andrew – type anywhere; the edits appear as tracked changes, and the accept/reject actions are cancelled. |
| 65 | + * Steven – insert comments from the Review tab; editing the content is blocked. |
| 66 | + * Michael – edit and format anywhere, and accept or reject Andrew's revisions. |
| 67 | + * Laura – the document is read-only; export it as DOCX or PDF using the custom buttons. |
| 68 | + |
| 69 | +> Note: The sample uses the Syncfusion demo web service (`https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/`) only for the PDF export server action. For production, set up your own web service as described in the [web services documentation](https://help.syncfusion.com/document-processing/word/word-processor/javascript-es6/web-services-overview?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples). |
| 70 | +
|
| 71 | +# Resources |
| 72 | + |
| 73 | +- **Product page:** [Syncfusion® JavaScript (ES6) DOCX Editor](https://www.syncfusion.com/docx-editor-sdk/javascript-docx-editor?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples) |
| 74 | + |
| 75 | +- **Documentation:** [Syncfusion® JavaScript (ES6) DOCX Editor - Documentation](https://help.syncfusion.com/document-processing/word/word-processor/javascript-es6/overview?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples) |
| 76 | + |
| 77 | +- **Online demo:** [Syncfusion® JavaScript (ES6) DOCX Editor - Online demo](https://document.syncfusion.com/demos/docx-editor/javascript/#/material3/document-editor/default.html?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples) |
| 78 | + |
| 79 | +# Support and feedback |
| 80 | + |
| 81 | +For any other queries, reach our [Syncfusion® support team](https://support.syncfusion.com/?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples) or post the queries through the [community forums](https://www.syncfusion.com/forums?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples). |
| 82 | + |
| 83 | +Request new feature through [Syncfusion® feedback portal](https://www.syncfusion.com/feedback?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples). |
| 84 | + |
| 85 | +# License |
| 86 | + |
| 87 | +This is a commercial product and requires a paid license for possession or use. Syncfusion's licensed software, including this component, is subject to the terms and conditions of [Syncfusion's EULA](https://www.syncfusion.com/license/studio/22.2.5/syncfusion_essential_studio_eula.pdf?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples). You can purchase a license [here](https://www.syncfusion.com/sales/products?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples) or start a free 30\-day trial [here](https://www.syncfusion.com/account/manage-trials/start-trials?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples). |
| 88 | + |
| 89 | +# About Syncfusion® |
| 90 | + |
| 91 | +Founded in 2001 and headquartered in Research Triangle Park, N.C., Syncfusion® has more than 29,000 customers and more than 1 million users, including large financial institutions, Fortune 500 companies, and global IT consultancies. |
| 92 | + |
| 93 | +Today, we provide 1700+ components and frameworks for web ([Blazor](https://www.syncfusion.com/blazor-components?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples), [ASP.NET Core](https://www.syncfusion.com/aspnet-core-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples), [ASP.NET MVC](https://www.syncfusion.com/aspnet-mvc-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples), [ASP.NET WebForms](https://www.syncfusion.com/aspnet-webforms-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples), [JavaScript](https://www.syncfusion.com/javascript-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples), [Angular](https://www.syncfusion.com/angular-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples), [React](https://www.syncfusion.com/react-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples), [Vue](https://www.syncfusion.com/vue-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples), and [Flutter](https://www.syncfusion.com/flutter-components?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples)), mobile ([Xamarin](https://www.syncfusion.com/xamarin-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples), [Flutter](https://www.syncfusion.com/flutter-components?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples), [UWP](https://www.syncfusion.com/uwp-components?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples), and [JavaScript](https://www.syncfusion.com/javascript-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples), [.NET MAUI](https://www.syncfusion.com/net-maui-components?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples)) and desktop development ([WinForms](https://www.syncfusion.com/winforms-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples), [WPF](https://www.syncfusion.com/wpf-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples), [WinUI](https://www.syncfusion.com/winui-components?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples), [Flutter](https://www.syncfusion.com/flutter-components?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples), [UWP](https://www.syncfusion.com/uwp-components?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples), and [.NET MAUI](https://www.syncfusion.com/net-maui-components?utm_source=github&utm_medium=listing&utm_campaign=github-javascript-es6-docx-editor-examples)). We provide ready-to-deploy enterprise software for dashboards, reports, data integration, and big data processing. Many customers have saved millions in licensing fees by deploying our software. |
0 commit comments