FWorkbookPermission
| Packages | @univerjs/sheets |
|---|
Implementation class for WorkbookPermission Provides workbook-level permission control
This class should not be instantiated directly. Use factory methods on
univerAPIinstead.
Overview
@univerjs/sheets
| Method | Description |
|---|---|
addCollaborator | Add a single collaborator |
canEdit | Check if the workbook is editable |
getPoint | Get the value of a specific permission point |
getSnapshot | Get a snapshot of all permission points |
listCollaborators | List all collaborators of the workbook |
removeCollaborator | Remove a collaborator from the workbook |
removeCollaborators | Remove multiple collaborators at once |
setCollaborators | Set multiple collaborators at once (replaces existing collaborators) |
setEditable | Set the workbook to editable mode (editor mode) |
setMode | Set permission mode for the workbook |
setPoint | Set a specific permission point |
setReadOnly | Set the workbook to read-only mode (viewer mode) |
updateCollaborator | Update an existing collaborator's role and information |
APIs
Lifecycle & Creation
addCollaborator
Add a single collaborator.
Signature
async addCollaborator(user: ICollaboratorUser, role: UnitRole): Promise<void>Parameters
userICollaboratorUser— No descriptionroleUnitRole— No description
Returns
Promise<void>— A promise that resolves when the collaborator is added.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const permission = fWorkbook.getWorkbookPermission();
await permission.addCollaborator(
{ userID: 'user1', name: 'John Doe', avatar: 'https://...' },
univerAPI.Enum.UnitRole.Editor
);@univerjs/sheets
Getters & Queries
canEdit
Check if the workbook is editable.
Signature
canEdit(): booleanReturns
boolean— true if the workbook can be edited, false otherwise.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
if (fWorkbook.getWorkbookPermission().canEdit()) {
console.log('Workbook is editable');
}@univerjs/sheets
getPoint
Get the value of a specific permission point.
Signature
getPoint(point: WorkbookPermissionPoint): booleanParameters
pointWorkbookPermissionPoint— No description
Returns
boolean— true if allowed, false if denied.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const permission = fWorkbook.getWorkbookPermission();
const canPrint = permission.getPoint(univerAPI.Enum.WorkbookPermissionPoint.Print);
console.log(canPrint);@univerjs/sheets
getSnapshot
Get a snapshot of all permission points.
Signature
getSnapshot(): WorkbookPermissionSnapshotReturns
WorkbookPermissionSnapshot— An object containing all permission point values.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const snapshot = fWorkbook.getWorkbookPermission().getSnapshot();
console.log(snapshot);@univerjs/sheets
listCollaborators
List all collaborators of the workbook.
Signature
async listCollaborators(): Promise<ICollaborator[]>Returns
Promise<ICollaborator[]>— Array of collaborators with their roles.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const permission = fWorkbook.getWorkbookPermission();
const collaborators = await permission.listCollaborators();
console.log(collaborators);@univerjs/sheets
Setters & Modifiers
setCollaborators
Set multiple collaborators at once (replaces existing collaborators).
Signature
async setCollaborators(collaborators: Array<{ user: ICollaboratorUser; role: UnitRole }>): Promise<void>Parameters
collaborators{ user: ICollaboratorUser; role: UnitRole; }[]— No description
Returns
Promise<void>— A promise that resolves when the collaborators are set.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const permission = fWorkbook.getWorkbookPermission();
await permission.setCollaborators([
{
user: { userID: 'user1', name: 'John Doe', avatar: 'https://...' },
role: univerAPI.Enum.UnitRole.Editor
},
{
user: { userID: 'user2', name: 'Jane Smith', avatar: '' },
role: univerAPI.Enum.UnitRole.Reader
}
]);@univerjs/sheets
setEditable
Set the workbook to editable mode (editor mode).
Signature
async setEditable(): Promise<void>Returns
Promise<void>— A promise that resolves when the mode is set.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
await fWorkbook.getWorkbookPermission().setEditable();@univerjs/sheets
setMode
Set permission mode for the workbook.
Signature
async setMode(mode: WorkbookMode): Promise<void>Parameters
modeWorkbookMode— No description
Returns
Promise<void>— A promise that resolves when the mode is set.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
await fWorkbook.getWorkbookPermission().setMode('editor');@univerjs/sheets
setPoint
Set a specific permission point.
Signature
async setPoint(point: WorkbookPermissionPoint, value: boolean): Promise<void>Parameters
pointWorkbookPermissionPoint— No descriptionvalueboolean— No description
Returns
Promise<void>— A promise that resolves when the point is set.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const permission = fWorkbook.getWorkbookPermission();
await permission.setPoint(univerAPI.Enum.WorkbookPermissionPoint.Print, false);@univerjs/sheets
setReadOnly
Set the workbook to read-only mode (viewer mode).
Signature
async setReadOnly(): Promise<void>Returns
Promise<void>— A promise that resolves when the mode is set.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
await fWorkbook.getWorkbookPermission().setReadOnly();@univerjs/sheets
updateCollaborator
Update an existing collaborator's role and information.
Signature
async updateCollaborator(user: ICollaboratorUser, role: UnitRole): Promise<void>Parameters
userICollaboratorUser— No descriptionroleUnitRole— No description
Returns
Promise<void>— A promise that resolves when the collaborator is updated.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const permission = fWorkbook.getWorkbookPermission();
await permission.updateCollaborator(
{ userID: 'user1', name: 'John Doe Updated', avatar: 'https://...' },
univerAPI.Enum.UnitRole.Reader
);@univerjs/sheets
Actions & Operations
removeCollaborator
Remove a collaborator from the workbook.
Signature
async removeCollaborator(userId: string): Promise<void>Parameters
userIdstring— No description
Returns
Promise<void>— A promise that resolves when the collaborator is removed.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const permission = fWorkbook.getWorkbookPermission();
await permission.removeCollaborator('user1');@univerjs/sheets
removeCollaborators
Remove multiple collaborators at once.
Signature
async removeCollaborators(userIds: string[]): Promise<void>Parameters
userIdsstring[]— No description
Returns
Promise<void>— A promise that resolves when the collaborators are removed.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const permission = fWorkbook.getWorkbookPermission();
await permission.removeCollaborators(['user1', 'user2']);@univerjs/sheets