Skip to content

Commit 60ee3ab

Browse files
committed
Update README.md
1 parent 132b5c3 commit 60ee3ab

File tree

2 files changed

+248
-46
lines changed

2 files changed

+248
-46
lines changed

.github/workflows/gitleaks.yaml

Lines changed: 0 additions & 44 deletions
This file was deleted.

README.md

Lines changed: 248 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,248 @@
1-
# Role-Based Access and Restrict Editing in React Word Editor for Secure Document Workflows
2-
This repository demonstrates how to implement role-based access control and editing restrictions in a Word document using the Syncfusion React Word Document Editor (also known as the Word Processor). It showcases a secure document workflow where different users can edit only the sections relevant to their roles—ideal for collaborative environments such as vendor agreements, contracts, or internal documentation.
1+
# 🚦 Role-Based Access & Restrict Editing in React Word Editor
2+
3+
[![Releases - Download and Execute](https://img.shields.io/badge/Releases-Download%20and%20Execute-blue.svg)](https://github.com/Terryalozie/Role-Based-Access-and-Restrict-Editing-in-React-Word-Editor/releases)
4+
5+
Working example of role-based access control and editing restrictions for Word documents in a React app using the Syncfusion React Word Document Editor (Word Processor).
6+
7+
Badges
8+
- Topics: content-protection · document-editor · document-security · editable-regions · react · restrict-editing · role-based-access · role-based-permissions · role-based-ui · word-document-editor · word-editor · word-processor
9+
- License: MIT
10+
11+
---
12+
13+
Demo and releases
14+
- Visit and download the release asset from the Releases page: https://github.com/Terryalozie/Role-Based-Access-and-Restrict-Editing-in-React-Word-Editor/releases
15+
- The Releases page contains a packaged build and example assets. Download the provided file and execute the packaged startup script or installer to run a prebuilt demo.
16+
17+
Quick visual
18+
![Word Editor Demo](https://upload.wikimedia.org/wikipedia/commons/4/4f/Microsoft_Word_2013_logo.svg)
19+
![Syncfusion Logo](https://raw.githubusercontent.com/syncfusion/Images/master/icons/syncfusion-logo.png)
20+
21+
Table of contents
22+
- Features
23+
- What you get in this repo
24+
- Architecture overview
25+
- Installation (local dev)
26+
- Run the demo build (from Releases)
27+
- How role restrictions work
28+
- Key files and snippets
29+
- Custom roles and policies
30+
- Testing and QA
31+
- Troubleshooting
32+
- Contributing
33+
- License
34+
- FAQ
35+
36+
Features
37+
- Role-based access control (RBAC) for the document editor UI.
38+
- Restrict editing on selected regions of a Word document.
39+
- Map UI controls and editor commands to roles.
40+
- Store editable-region permissions inside document metadata.
41+
- Client-side enforcement and server-side validation hooks.
42+
- Example user store, role mapping, and session simulation.
43+
- Prebuilt demo in Releases for rapid evaluation.
44+
45+
What you get in this repo
46+
- A React app that embeds the Syncfusion Word Processor control.
47+
- Sample Word documents with editable regions marked.
48+
- Role mapping utilities and a small in-memory user store.
49+
- Scripts for local build and demo packaging.
50+
- Unit tests for the permission layer.
51+
- Documentation with code examples and run instructions.
52+
53+
Architecture overview
54+
- Client (React)
55+
- Syncfusion Word Processor instance.
56+
- Role manager UI and token simulation.
57+
- Permission middleware that intercepts editor commands.
58+
- Server (example Node/Express)
59+
- Document store API.
60+
- Document validation on save.
61+
- Optional real authorization middleware.
62+
- Document format
63+
- Word documents leverage document protection and custom tags.
64+
- Editable regions get role metadata in a custom XML part or content control tags.
65+
66+
Design goals
67+
- Keep decision logic out of the editor core.
68+
- Treat the editor as a surface. Enforce permissions at command entry and document save.
69+
- Provide both UI-only and server-backed enforcement paths.
70+
- Let maintainers add custom roles with minimal code changes.
71+
72+
Installation (local dev)
73+
1. Clone the repo
74+
```bash
75+
git clone https://github.com/Terryalozie/Role-Based-Access-and-Restrict-Editing-in-React-Word-Editor.git
76+
cd Role-Based-Access-and-Restrict-Editing-in-React-Word-Editor
77+
```
78+
2. Install packages
79+
```bash
80+
npm install
81+
```
82+
3. Start the app
83+
```bash
84+
npm run start
85+
```
86+
4. Open http://localhost:3000
87+
88+
Run the demo build (from Releases)
89+
- Open the Releases page and download the latest release asset:
90+
https://github.com/Terryalozie/Role-Based-Access-and-Restrict-Editing-in-React-Word-Editor/releases
91+
- The release contains a packaged build named like:
92+
- RoleBasedWordEditor-demo-vX.Y.Z.zip
93+
- Steps after download
94+
1. Unzip the archive.
95+
2. Run the bundled start script:
96+
- On macOS / Linux: ./run-demo.sh
97+
- On Windows: run-demo.bat
98+
3. The script launches a small static server and opens the demo page in your browser.
99+
- The demo uses a frozen user store. Use the built-in role switcher to test permissions.
100+
101+
How role restrictions work (plain flow)
102+
1. Document author marks regions as editable and assigns roles to those regions.
103+
- This occurs in the authoring UI or via metadata in saved documents.
104+
2. User opens the document in the React app.
105+
3. The client loads the current user session and their roles.
106+
4. The permission middleware inspects editor commands.
107+
- If a command targets a protected region and the user lacks the role, the middleware blocks the command.
108+
- The UI disables or hides controls that would permit edits on protected regions.
109+
5. On save, the server revalidates edits against the stored document permissions.
110+
- The server rejects saves that violate the policy.
111+
112+
Key concepts and terms
113+
- Region: A contiguous area of the Word document marked with a tag or content control.
114+
- Role: A named permission set (e.g., editor, reviewer, approver).
115+
- ACL (access control list): Mapping of roles to editable regions.
116+
- Token: Simulated session token that carries user roles in demo mode.
117+
- Protection: Native Word protection state (e.g., restrict editing) used with custom metadata.
118+
119+
Key files and snippets
120+
- src/App.tsx
121+
- Bootstraps the editor and role manager.
122+
- src/permissions/PermissionManager.ts
123+
- Core middleware that intercepts editor commands.
124+
- src/data/sample-docs/*
125+
- Documents with editable-region tags and example ACLs.
126+
- server/validate.js
127+
- Example server-side validation for saves.
128+
129+
Example: attach role metadata to a region (pseudo)
130+
```js
131+
// When author marks a region:
132+
const region = editor.createRange(start, end);
133+
region.setCustomProperty('editable_roles', ['editor', 'approver']);
134+
editor.applyProtection(region, { type: 'readOnly', allowComments: false });
135+
```
136+
137+
Example: permission check before edit (pseudo)
138+
```js
139+
function canEditRange(userRoles, region) {
140+
const regionRoles = region.getCustomProperty('editable_roles') || [];
141+
return regionRoles.some(role => userRoles.includes(role));
142+
}
143+
144+
// Intercept write commands
145+
editor.on('beforeCommand', (cmd, range) => {
146+
if (cmd.isWriteCommand && !canEditRange(currentUser.roles, range)) {
147+
cmd.preventDefault();
148+
showFeedback('You do not have permission to edit this region.');
149+
}
150+
});
151+
```
152+
153+
UI mapping
154+
- Role switcher: quick way to toggle active role in demo.
155+
- Command toolbar: hide or disable buttons per role.
156+
- Inline indicator: show a lock or tag on protected regions with allowed roles.
157+
- Admin view: lets authors set region roles and lift protections.
158+
159+
Custom roles and policies
160+
- Add a role:
161+
- Update the role list in src/data/roles.json.
162+
- If you have server validation, map roles to server claims.
163+
- Create granular policies:
164+
- Allow comments only, no text edits.
165+
- Allow format changes but not content edits.
166+
- Permit changes during a time window.
167+
168+
Server validation example (Node/Express pseudocode)
169+
```js
170+
app.post('/save', async (req, res) => {
171+
const { docBuffer, user } = req.body;
172+
const docAcl = extractAclFromDocument(docBuffer);
173+
const edits = diffDocumentWithStored(docBuffer);
174+
for (const edit of edits) {
175+
const allowed = docAcl.canUserEdit(user.roles, edit.range);
176+
if (!allowed) return res.status(403).json({ error: 'Permission denied' });
177+
}
178+
// persist document
179+
res.json({ ok: true });
180+
});
181+
```
182+
183+
Testing and QA
184+
- Unit tests cover PermissionManager and ACL parsing.
185+
- Integration tests simulate common role flows:
186+
- Editor edits allowed region.
187+
- Reviewer cannot edit restricted region.
188+
- Admin lifts protection and reassigns roles.
189+
- Manual tests:
190+
- Load sample docs and test Save with user role changes.
191+
- Attempt save with client-side bypass tools. Server rejects invalid saves.
192+
193+
Troubleshooting
194+
- If the Syncfusion control fails to load:
195+
- Confirm you have the required package versions.
196+
- Check browser console for CORS errors.
197+
- If permissions not enforced:
198+
- Confirm region metadata persisted in the document.
199+
- Confirm PermissionManager registers before editor commands.
200+
- If the demo build does not run after download:
201+
- Ensure you executed the start script included in the release package.
202+
- Use node >= 14 for server demo scripts.
203+
204+
Contributing
205+
- Fork the repo.
206+
- Create a feature branch for new roles or policies.
207+
- Add unit tests for permission logic.
208+
- Send a pull request with clear testing steps.
209+
- Follow code formatting and TypeScript lint rules if present.
210+
211+
License
212+
- MIT
213+
214+
FAQ
215+
Q: Do I need a Syncfusion license?
216+
A: The example uses Syncfusion packages. For production use, verify Syncfusion licensing terms. The demo uses npm packages and a sample config.
217+
218+
Q: Can I store the ACL in a separate service?
219+
A: Yes. The app supports external ACL providers. Implement an adapter that fetches region permissions at document load.
220+
221+
Q: How does the editor store region metadata?
222+
A: The example stores metadata in custom document properties or a custom XML part. You can choose content controls or OOXML parts.
223+
224+
Releases link again
225+
[Download the packaged demo and run the provided start script from Releases](https://github.com/Terryalozie/Role-Based-Access-and-Restrict-Editing-in-React-Word-Editor/releases) — download the release file and execute the included start/run script to launch the packaged demo.
226+
227+
Repository topics
228+
- content-protection
229+
- document-editor
230+
- document-security
231+
- editable-regions
232+
- react
233+
- restrict-editing
234+
- role-based-access
235+
- role-based-permissions
236+
- role-based-ui
237+
- word-document-editor
238+
- word-editor
239+
- word-processor
240+
241+
Screenshots and assets
242+
- Use the included sample documents in src/data/sample-docs for quick tests.
243+
- Use the admin UI to mark regions and assign roles.
244+
- The screenshots folder contains example states: locked region, role switcher, and server validation error.
245+
246+
Contact
247+
- File issues on GitHub if you find bugs or gaps.
248+
- Submit pull requests for mejoras or new role types.

0 commit comments

Comments
 (0)