Skip to Content
ClassesFRangePermission

Class: FRangePermission

Implementation class for RangePermission Manages range-level permissions

Properties

PropertyModifierTypeDescription

permission$

readonly

Observable<RangePermissionSnapshot>

Observable stream of permission snapshot changes

protectionChange$

readonly

Observable<… | …>

Observable stream of protection state changes

Methods

canDelete()

canDelete(): boolean

Check 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(): boolean

Check 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(): boolean

Check 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(): boolean

Check 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(): void

Clean up resources

Returns

void


getPoint()

getPoint(point): boolean

Get the value of a specific permission point.

Parameters

ParameterTypeDescription
pointRangePermissionPointThe 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(): RangePermissionSnapshot

Get the current permission snapshot.

Returns

RangePermissionSnapshot

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(): boolean

Check 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

ParameterTypeDescription
options?IRangeProtectionOptionsProtection 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

ParameterTypeDescription
pointRangePermissionPointThe permission point to set.
valuebooleanThe 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 enabled

subscribe()

subscribe(listener): () => void

Subscribe to permission changes (simplified interface).

Parameters

ParameterTypeDescription
listener(snapshot) => voidCallback 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();