Skip to content

Commit 9489ea6

Browse files
Bold Create Agentsuriyaprakasamr
andcommitted
Add document-protection sample demonstrating user-based restrictions and approval workflows
Demonstrates role-based editing access, track changes review, comments, revision acceptance/rejection and an approval workflow using the Adventure Works SFDT document with user-based editable ranges: - Nancy edits only the price values via editable ranges (ReadOnly + ranges) - Andrew edits with all changes tracked (RevisionsOnly), accept/reject blocked - Steven inserts comments only (CommentsOnly) - Michael has full editing and approves the tracked changes - Laura is read-only and exports the document as DOCX and PDF Based on the getting-started sample. Co-authored-by: suriyaprakasamr <302142999+suriyaprakasamr@users.noreply.github.com> Bold-Create-Session: https://app.boldcreate.ai/agent/chat/?threadId=12b07b78-1832-49fa-8f4a-31352769b404
1 parent 01a49dd commit 9489ea6

15 files changed

Lines changed: 11633 additions & 0 deletions

‎document-protection/.gitignore‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Dependency directories
7+
node_modules
8+
9+
# Build generated files
10+
dist
11+
12+
# OSX
13+
.DS_Store

‎document-protection/README.md‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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&reg; 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&reg; 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&reg; 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&reg; 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&reg; 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&reg; 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&reg;
90+
91+
Founded in 2001 and headquartered in Research Triangle Park, N.C., Syncfusion&reg; 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.

‎document-protection/e2e/index.spec.js‎

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
exports.config = {
2+
3+
allScriptsTimeout: 11000,
4+
5+
capabilities: {
6+
'browserName': 'chrome'
7+
},
8+
9+
framework: 'jasmine',
10+
11+
jasmineNodeOpts: {
12+
defaultTimeoutInterval: 10000
13+
},
14+
directConnect: true,
15+
16+
onPrepare: function() {
17+
browser.waitForAngularEnabled(false);
18+
},
19+
20+
specs: ['./*.spec.js']
21+
};

‎document-protection/gulpfile.js‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'use strict';
2+
3+
var gulp = require('gulp');
4+
5+
/**
6+
* Compile TypeScript to JS
7+
*/
8+
gulp.task('compile', function (done) {
9+
var webpack = require('webpack');
10+
var webpackStream = require('webpack-stream');
11+
gulp.src(['./src/app/app.ts']).pipe(webpackStream({
12+
config: require('./webpack.config.js')
13+
}, webpack))
14+
.pipe(gulp.dest('./dist'))
15+
.on('end', function () {
16+
done();
17+
});
18+
});
19+
20+
/**
21+
* Testing spec files
22+
*/
23+
var protractor = require('gulp-protractor').protractor;
24+
var webdriver_standalone = require('gulp-protractor').webdriver_standalone;
25+
var webdriver_update = require('gulp-protractor').webdriver_update_specific;
26+
27+
gulp.task('e2e-serve', webdriver_standalone);
28+
29+
gulp.task('e2e-webdriver-update', webdriver_update({
30+
webdriverManagerArgs: ['--ie', '--edge']
31+
}));
32+
33+
gulp.task('e2e-test', gulp.series('compile', function (done) {
34+
var browserSync = require('browser-sync');
35+
var bs = browserSync.create('Essential JS 2');
36+
var options = {
37+
server: {
38+
baseDir: [
39+
'./dist/',
40+
],
41+
directory: true
42+
},
43+
ui: false,
44+
open: false,
45+
notify: false
46+
};
47+
bs.init(options, function () {
48+
gulp.src(['./spec/**/*.spec.js'])
49+
.pipe(protractor({
50+
configFile: 'e2e/protractor.conf.js'
51+
}))
52+
.on('error', function (e) {
53+
console.error('Error: ' + e.message);
54+
done();
55+
process.exit(1);
56+
})
57+
.on('end', function () {
58+
done();
59+
process.exit(0);
60+
});
61+
});
62+
}));

‎document-protection/license‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Essential JS 2 library is available under the Syncfusion Essential Studio program, and can be licensed either under the Syncfusion Community License Program or the Syncfusion commercial license.
2+
3+
To be qualified for the Syncfusion Community License Program you must have a gross revenue of less than one (1) million U.S. dollars ($1,000,000.00 USD) per year and have less than five (5) developers in your organization, and agree to be bound by Syncfusion’s terms and conditions.
4+
5+
Customers who do not qualify for the community license can contact sales@syncfusion.com for commercial licensing options.
6+
7+
Under no circumstances can you use this product without (1) either a Community License or a commercial license and (2) without agreeing and abiding by Syncfusion’s license containing all terms and conditions.
8+
9+
The Syncfusion license that contains the terms and conditions can be found at
10+
https://www.syncfusion.com/content/downloads/syncfusion_license.pdf

0 commit comments

Comments
 (0)