Skip to Content
ClassesFPermission

Class: FPermission

Description

Used to generate permission instances to control permissions for the entire workbook

Extends

  • FBase.IFPermissionSheetsUIMixin

Properties

PropertyTypeDescription

permissionPointsDefinition

{ RangeProtectionPermissionEditPoint: any; RangeProtectionPermissionViewPoint: any; WorkbookCommentPermission: any; WorkbookCopyPermission: any; WorkbookCreateProtectPermission: any; WorkbookCreateSheetPermission: any; WorkbookDeleteSheetPermission: any; WorkbookDuplicatePermission: any; WorkbookEditablePermission: any; WorkbookExportPermission: any; WorkbookHideSheetPermission: any; WorkbookHistoryPermission: any; WorkbookManageCollaboratorPermission: any; WorkbookMoveSheetPermission: any; WorkbookPrintPermission: any; WorkbookRecoverHistoryPermission: any; WorkbookRenameSheetPermission: any; WorkbookSharePermission: any; WorkbookViewHistoryPermission: any; WorkbookViewPermission: any; WorksheetCopyPermission: any; WorksheetDeleteColumnPermission: any; WorksheetDeleteProtectionPermission: any; WorksheetDeleteRowPermission: any; WorksheetEditExtraObjectPermission: any; WorksheetEditPermission: any; WorksheetFilterPermission: any; WorksheetInsertColumnPermission: any; WorksheetInsertHyperlinkPermission: any; WorksheetInsertRowPermission: any; WorksheetManageCollaboratorPermission: any; WorksheetPivotTablePermission: any; WorksheetSetCellStylePermission: any; WorksheetSetCellValuePermission: any; WorksheetSetColumnStylePermission: any; WorksheetSetRowStylePermission: any; WorksheetSortPermission: any; WorksheetViewPermission: any; }

Permission point definition, can read the point constructor want to modify from here

permissionPointsDefinition.RangeProtectionPermissionEditPoint

any

permissionPointsDefinition.RangeProtectionPermissionViewPoint

any

permissionPointsDefinition.WorkbookCommentPermission

any

permissionPointsDefinition.WorkbookCopyPermission

any

permissionPointsDefinition.WorkbookCreateProtectPermission

any

permissionPointsDefinition.WorkbookCreateSheetPermission

any

permissionPointsDefinition.WorkbookDeleteSheetPermission

any

permissionPointsDefinition.WorkbookDuplicatePermission

any

permissionPointsDefinition.WorkbookEditablePermission

any

permissionPointsDefinition.WorkbookExportPermission

any

permissionPointsDefinition.WorkbookHideSheetPermission

any

permissionPointsDefinition.WorkbookHistoryPermission

any

permissionPointsDefinition.WorkbookManageCollaboratorPermission

any

permissionPointsDefinition.WorkbookMoveSheetPermission

any

permissionPointsDefinition.WorkbookPrintPermission

any

permissionPointsDefinition.WorkbookRecoverHistoryPermission

any

permissionPointsDefinition.WorkbookRenameSheetPermission

any

permissionPointsDefinition.WorkbookSharePermission

any

permissionPointsDefinition.WorkbookViewHistoryPermission

any

permissionPointsDefinition.WorkbookViewPermission

any

permissionPointsDefinition.WorksheetCopyPermission

any

permissionPointsDefinition.WorksheetDeleteColumnPermission

any

permissionPointsDefinition.WorksheetDeleteProtectionPermission

any

permissionPointsDefinition.WorksheetDeleteRowPermission

any

permissionPointsDefinition.WorksheetEditExtraObjectPermission

any

permissionPointsDefinition.WorksheetEditPermission

any

permissionPointsDefinition.WorksheetFilterPermission

any

permissionPointsDefinition.WorksheetInsertColumnPermission

any

permissionPointsDefinition.WorksheetInsertHyperlinkPermission

any

permissionPointsDefinition.WorksheetInsertRowPermission

any

permissionPointsDefinition.WorksheetManageCollaboratorPermission

any

permissionPointsDefinition.WorksheetPivotTablePermission

any

permissionPointsDefinition.WorksheetSetCellStylePermission

any

permissionPointsDefinition.WorksheetSetCellValuePermission

any

permissionPointsDefinition.WorksheetSetColumnStylePermission

any

permissionPointsDefinition.WorksheetSetRowStylePermission

any

permissionPointsDefinition.WorksheetSortPermission

any

permissionPointsDefinition.WorksheetViewPermission

any

rangeRuleChangedAfterAuth$

Observable<string>

An observable object used to monitor permission change events within a range, thereby triggering corresponding subsequent processing.

sheetRuleChangedAfterAuth$

Observable<string>

An observable object used to monitor permission change events within a worksheet, thereby triggering corresponding subsequent processing.

Methods

addRangeBaseProtection()

addRangeBaseProtection( unitId, subUnitId, ranges): Promise<{ permissionId: ...; ruleId: ...; }>

Adds a range protection to the worksheet. Note that after adding, only the background mask of the permission module will be rendered. If you want to modify the function permissions, you need to modify the permission points with the permissionId returned by this function.

Parameters

ParameterTypeDescription
unitIdstringThe unique identifier of the workbook.
subUnitIdstringThe unique identifier of the worksheet.
rangesFRange[]The ranges to be protected.

Returns

Promise<{ permissionId: …; ruleId: …; }>

  • Returns an object containing the permissionId and ruleId if the range protection is successfully added. If the operation fails or no result is returned, it resolves to undefined. permissionId is used to stitch permission point ID,ruleId is used to store permission rules

Example

const workbook = univerAPI.getActiveWorkbook(); const permission = workbook.getPermission(); const unitId = workbook.getId(); const worksheet = workbook.getActiveSheet(); const subUnitId = worksheet.getSheetId(); const range = worksheet.getRange(0,0,2,2); const ranges = []; ranges.push(range); // Note that there will be no permission changes after this step is completed. It only returns an ID for subsequent permission changes. // For details, please see the example of the **`setRangeProtectionPermissionPoint`** API. const res = await permission.addRangeBaseProtection(unitId, subUnitId, ranges); const {permissionId, ruleId} = res; console.log('debugger', permissionId, ruleId);

addWorksheetBasePermission()

addWorksheetBasePermission(unitId, subUnitId): Promise<string>

This function is used to add a base permission for a worksheet. Note that after adding, only the background mask of the permission module will be rendered. If you want to modify the function permissions, you need to modify the permission points with the permissionId returned by this function.

Parameters

ParameterTypeDescription
unitIdstringThe unique identifier of the workbook for which the permission is being set.
subUnitIdstringThe unique identifier of the worksheet for which the permission is being set.

Returns

Promise<string>

  • Returns the permissionId if the permission is successfully added. If the operation fails or no result is returned, it resolves to undefined.

Example

const workbook = univerAPI.getActiveWorkbook(); const permission = workbook.getPermission(); const unitId = workbook.getId(); const worksheet = workbook.getActiveSheet(); const subUnitId = worksheet.getSheetId(); // Note that there will be no permission changes after this step is completed. It only returns an ID for subsequent permission changes. // For details, please see the example of the **`setWorksheetPermissionPoint`** API. const permissionId = await permission.addWorksheetBasePermission(unitId, subUnitId) // Can still edit and read it. console.log('debugger', permissionId)

removeRangeProtection()

removeRangeProtection( unitId, subUnitId, ruleIds): void

Removes the range protection from the worksheet.

Parameters

ParameterTypeDescription
unitIdstringThe unique identifier of the workbook.
subUnitIdstringThe unique identifier of the worksheet.
ruleIdsstring[]The rule IDs of the range protection to be removed.

Returns

void

Example

const workbook = univerAPI.getActiveWorkbook(); const permission = workbook.getPermission(); const unitId = workbook.getId(); const worksheet = workbook.getActiveSheet(); const subUnitId = worksheet.getSheetId(); const range = worksheet.getRange(0,0,2,2); const ranges = []; ranges.push(range); const res = await permission.addRangeBaseProtection(unitId, subUnitId, ranges); const ruleId = res.ruleId; permission.removeRangeProtection(unitId, subUnitId, [ruleId]);

removeWorksheetPermission()

removeWorksheetPermission(unitId, subUnitId): void

Delete the entire table protection set for the worksheet and reset the point permissions of the worksheet to true

Parameters

ParameterTypeDescription
unitIdstringThe unique identifier of the workbook for which the permission is being set.
subUnitIdstringThe unique identifier of the worksheet for which the permission is being set.

Returns

void

Example

const workbook = univerAPI.getActiveWorkbook(); const permission = workbook.getPermission(); const unitId = workbook.getId(); const worksheet = workbook.getActiveSheet(); const subUnitId = worksheet.getSheetId(); permission.removeWorksheetPermission(unitId, subUnitId);

setPermissionDialogVisible()

setPermissionDialogVisible(visible): void

Set visibility of unauthorized pop-up window

Parameters

ParameterTypeDescription
visibleboolean

Returns

void

Example

univerAPI.getPermission().setPermissionDialogVisible(false);

setRangeProtectionPermissionPoint()

setRangeProtectionPermissionPoint( unitId, subUnitId, permissionId, FPointClass, value): void

Modify the permission points of a custom area

Parameters

ParameterTypeDescription
unitIdstringThe unique identifier of the workbook.
subUnitIdstringThe unique identifier of the worksheet within the workbook.
permissionIdstringThe unique identifier of the permission that controls access to the range.
FPointClassRangePermissionPointConstructorThe constructor for the range permission point class. See the permission-point documentation for more details.
valuebooleanThe new permission value to be set for the range (e.g., true for allowing access, false for restricting access).

Returns

void

Example

const workbook = univerAPI.getActiveWorkbook(); const permission = workbook.getPermission(); const unitId = workbook.getId(); const worksheet = workbook.getActiveSheet(); const subUnitId = worksheet.getSheetId(); const range = worksheet.getRange(0, 0, 2, 2); const ranges = []; ranges.push(range); // Note that there will be no permission changes after this step is completed. It only returns an ID for subsequent permission changes. // For details, please see the example of the **`setRangeProtectionPermissionPoint`** API. const res = await permission.addRangeBaseProtection(unitId, subUnitId, ranges); const {permissionId, ruleId} = res; // After passing the following line of code, the range set above will become uneditable permission.setRangeProtectionPermissionPoint(unitId,subUnitId,permissionId, permission.permissionPointsDefinition.RangeProtectionPermissionEditPoint, false);

setRangeProtectionRanges()

setRangeProtectionRanges( unitId, subUnitId, ruleId, ranges): void

Sets the ranges for range protection in a worksheet.

This method finds the rule by unitId, subUnitId, and ruleId, and updates the rule with the provided ranges. It checks for overlaps with existing ranges in the same subunit and shows an error message if any overlap is detected. If no overlap is found, it executes the command to update the range protection with the new ranges.

Parameters

ParameterTypeDescription
unitIdstringThe unique identifier of the workbook.
subUnitIdstringThe unique identifier of the worksheet within the workbook.
ruleIdstringThe ruleId of the range protection rule that is being updated.
rangesFRange[]The array of new ranges to be set for the range protection rule.

Returns

void

Example

const workbook = univerAPI.getActiveWorkbook(); const permission = workbook.getPermission(); const unitId = workbook.getId(); const worksheet = workbook.getActiveSheet(); const subUnitId = worksheet.getSheetId(); const range = worksheet.getRange(0, 0, 2, 2); const ranges = []; ranges.push(range); const res = await permission.addRangeBaseProtection(unitId, subUnitId, ranges); const {permissionId, ruleId} = res; const newRange = worksheet.getRange(3, 3, 2, 2); permission.setRangeProtectionRanges(unitId, subUnitId, ruleId, [newRange]);

setWorkbookEditPermission()

setWorkbookEditPermission(unitId, value): void

This function is used to set whether the workbook can be edited

Parameters

ParameterTypeDescription
unitIdstringThe unique identifier of the workbook for which the permission is being set.
valuebooleanA value that controls whether the workbook can be edited

Returns

void

Example

const workbook = univerAPI.getActiveWorkbook(); const permission = workbook.getPermission(); const unitId = workbook.getId(); permission.setWorkbookEditPermission(unitId, false);

setWorkbookPermissionPoint()

setWorkbookPermissionPoint( unitId, FPointClass, value): void

Configures a specific permission point for a workbook. This function sets or updates a permission point for a workbook identified by unitId. It creates a new permission point if it does not already exist, and updates the point with the provided value.

Parameters

ParameterTypeDescription
unitIdstringThe unique identifier of the workbook for which the permission is being set.
FPointClassWorkbookPermissionPointConstructorThe constructor function for creating a permission point instance. Other point constructors can See the permission-point documentation for more details.
valuebooleanThe boolean value to determine whether the permission point is enabled or disabled.

Returns

void

Example

const workbook = univerAPI.getActiveWorkbook(); const permission = workbook.getPermission(); const unitId = workbook.getId(); permission.setWorkbookPermissionPoint(unitId, permission.permissionPointsDefinition.WorkbookEditablePermission, false)

setWorksheetPermissionPoint()

setWorksheetPermissionPoint( unitId, subUnitId, FPointClass, value): Promise<string>

Sets the worksheet permission point by updating or adding the permission point for the worksheet. If the worksheet doesn’t have a base permission, it creates one to used render

Parameters

ParameterTypeDescription
unitIdstringThe unique identifier of the workbook.
subUnitIdstringThe unique identifier of the worksheet.
FPointClassWorkSheetPermissionPointConstructorThe constructor for the permission point class. See the permission-point documentation for more details.
valuebooleanThe new permission value to be set for the worksheet.

Returns

Promise<string>

  • Returns the permissionId if the permission point is successfully set or created. If no permission is set, it resolves to undefined.

Example

const workbook = univerAPI.getActiveWorkbook(); const permission = workbook.getPermission(); const unitId = workbook.getId(); const worksheet = workbook.getActiveSheet(); const subUnitId = worksheet.getSheetId(); const permissionId = await permission.addWorksheetBasePermission(unitId, subUnitId) // After this line of code , the worksheet will no longer be editable permission.setWorksheetPermissionPoint(unitId, subUnitId, permission.permissionPointsDefinition.WorksheetEditPermission, false);