Class: FRangePermission
Implementation class for RangePermission Manages range-level permissions
Properties
| Property | Modifier | Type | Description |
|---|---|---|---|
|
|
|
Observable stream of permission snapshot changes | |
|
|
|
Observable stream of protection state changes |
Methods
canDelete()
canDelete(): booleanCheck if the current user can delete this protection rule.
Returns
boolean
true if can delete rule, false otherwise.
Example
const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
const permission = range?.getRangePermission();
if (permission?.canDelete()) {
console.log('You can delete this protection rule');
}canEdit()
canEdit(): booleanCheck if the current user can edit this range.
Returns
boolean
true if editable, false otherwise.
Example
const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
const permission = range?.getRangePermission();
if (permission?.canEdit()) {
console.log('You can edit this range');
}canManageCollaborator()
canManageCollaborator(): booleanCheck if the current user can manage collaborators for this range.
Returns
boolean
true if can manage collaborators, false otherwise.
Example
const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
const permission = range?.getRangePermission();
if (permission?.canManageCollaborator()) {
console.log('You can manage collaborators for this range');
}canView()
canView(): booleanCheck if the current user can view this range.
Returns
boolean
true if viewable, false otherwise.
Example
const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
const permission = range?.getRangePermission();
if (permission?.canView()) {
console.log('You can view this range');
}dispose()
dispose(): voidClean up resources
Returns
void
getPoint()
getPoint(point): booleanGet the value of a specific permission point.
Parameters
| Parameter | Type | Description |
|---|---|---|
point | RangePermissionPoint | The permission point to query. |
Returns
boolean
true if allowed, false if denied.
Example
const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
const permission = range?.getRangePermission();
const canEdit = permission?.getPoint(univerAPI.Enum.RangePermissionPoint.Edit);
console.log(canEdit);getSnapshot()
getSnapshot(): RangePermissionSnapshotGet the current permission snapshot.
Returns
Snapshot of all permission points.
Example
const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
const permission = range?.getRangePermission();
const snapshot = permission?.getSnapshot();
console.log(snapshot);isProtected()
isProtected(): booleanCheck if the current range is protected.
Returns
boolean
true if protected, false otherwise.
Example
const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
const permission = range?.getRangePermission();
const isProtected = permission?.isProtected();
console.log(isProtected);listRules()
listRules(): Promise<...[]>List all protection rules.
Returns
Promise<…[]>
Array of protection rules.
Example
const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
const permission = range?.getRangePermission();
const rules = await permission?.listRules();
console.log(rules);protect()
protect(options?): Promise<FRangeProtectionRule>Protect the current range.
Parameters
| Parameter | Type | Description |
|---|---|---|
options? | IRangeProtectionOptions | Protection options. |
Returns
Promise<FRangeProtectionRule>
The created protection rule.
Example
const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
const permission = range?.getRangePermission();
const rule = await permission?.protect({
name: 'My protected range',
allowEdit: true,
allowedUsers: ['user1', 'user2'],
allowViewByOthers: false,
});
console.log(rule);setPoint()
setPoint(point, value): Promise<void>Set a specific permission point for the range (low-level API).
Important: This method only updates the permission point value for an existing protection rule.
It does NOT create permission checks that will block actual editing operations.
You must call protect() first to create a protection rule before using this method.
This method is useful for:
- Fine-tuning permissions after creating a protection rule with
protect() - Dynamically adjusting permissions based on runtime conditions
- Advanced permission management scenarios
Parameters
| Parameter | Type | Description |
|---|---|---|
point | RangePermissionPoint | The permission point to set. |
value | boolean | The value to set (true = allowed, false = denied). |
Returns
Promise<void>
A promise that resolves when the point is set.
Throws
If no protection rule exists for this range.
Example
const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
const permission = range?.getRangePermission();
// First, create a protection rule
await permission?.protect({ name: 'My Range', allowEdit: true });
// Then you can dynamically update permission points
await permission?.setPoint(univerAPI.Enum.RangePermissionPoint.Edit, false); // Now disable edit
await permission?.setPoint(univerAPI.Enum.RangePermissionPoint.View, true); // Ensure view is enabledsubscribe()
subscribe(listener): () => voidSubscribe to permission changes (simplified interface).
Parameters
| Parameter | Type | Description |
|---|---|---|
listener | (snapshot) => void | Callback function to be called when permissions change. |
Returns
Function
Unsubscribe function.
Returns
void
Example
const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
const permission = range?.getRangePermission();
const unsubscribe = permission?.subscribe((snapshot) => {
console.log('Permission changed:', snapshot);
});
// Later, to stop listening:
unsubscribe?.();unprotect()
unprotect(): Promise<void>Unprotect the current range.
Returns
Promise<void>
A promise that resolves when the range is unprotected.
Example
const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
const permission = range?.getRangePermission();
await permission?.unprotect();