# FWorkbookPermission

> Language fallback: requested `zh-CN`; content is `en-US`.

- Human documentation: [https://docs.univer.ai/zh-CN/reference/facade/workbook-permission](https://docs.univer.ai/zh-CN/reference/facade/workbook-permission)

- Agent Markdown: [https://docs.univer.ai/zh-CN/reference/facade/workbook-permission.md](https://docs.univer.ai/zh-CN/reference/facade/workbook-permission.md)

- Requested language: `zh-CN`

- Content language: `en-US`

- Documentation version: `1.0.0-rc.0`

- Source: [facade/workbook-permission.mdx](https://github.com/dream-num/documentation/blob/dev/content/reference/facade/workbook-permission.mdx)

---

| Packages | `@univerjs/sheets` |
| -------- | ------------------ |

Implementation class for WorkbookPermission
Provides workbook-level permission control

> This class should not be instantiated directly. Use factory methods on `univerAPI` instead.

## Overview

### @univerjs/sheets

| Method                                        | Description                                                          |
| --------------------------------------------- | -------------------------------------------------------------------- |
| [`addCollaborator`](#addcollaborator)         | Add a single collaborator                                            |
| [`canEdit`](#canedit)                         | Check if the workbook is editable                                    |
| [`getPoint`](#getpoint)                       | Get the value of a specific permission point                         |
| [`getSnapshot`](#getsnapshot)                 | Get a snapshot of all permission points                              |
| [`listCollaborators`](#listcollaborators)     | List all collaborators of the workbook                               |
| [`removeCollaborator`](#removecollaborator)   | Remove a collaborator from the workbook                              |
| [`removeCollaborators`](#removecollaborators) | Remove multiple collaborators at once                                |
| [`setCollaborators`](#setcollaborators)       | Set multiple collaborators at once (replaces existing collaborators) |
| [`setEditable`](#seteditable)                 | Set the workbook to editable mode (editor mode)                      |
| [`setMode`](#setmode)                         | Set permission mode for the workbook                                 |
| [`setPoint`](#setpoint)                       | Set a specific permission point                                      |
| [`setReadOnly`](#setreadonly)                 | Set the workbook to read-only mode (viewer mode)                     |
| [`updateCollaborator`](#updatecollaborator)   | Update an existing collaborator's role and information               |

## APIs

### Lifecycle & Creation

### `addCollaborator`

Add a single collaborator.

**Signature**

```typescript
async addCollaborator(user: ICollaboratorUser, role: UnitRole): Promise<void>
```

**Parameters**

* `user` `ICollaboratorUser` — *No description*
* `role` `UnitRole` — *No description*

**Returns**

* `Promise<void>` — A promise that resolves when the collaborator is added.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const permission = fWorkbook.getWorkbookPermission();
await permission.addCollaborator(
  { userID: 'user1', name: 'John Doe', avatar: 'https://...' },
  univerAPI.Enum.UnitRole.Editor
);
```

Source: 

`@univerjs/sheets`

### Getters & Queries

### `canEdit`

Check if the workbook is editable.

**Signature**

```typescript
canEdit(): boolean
```

**Returns**

* `boolean` — true if the workbook can be edited, false otherwise.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
if (fWorkbook.getWorkbookPermission().canEdit()) {
  console.log('Workbook is editable');
}
```

Source: 

`@univerjs/sheets`

### `getPoint`

Get the value of a specific permission point.

**Signature**

```typescript
getPoint(point: WorkbookPermissionPoint): boolean
```

**Parameters**

* `point` `WorkbookPermissionPoint` — *No description*

**Returns**

* `boolean` — true if allowed, false if denied.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const permission = fWorkbook.getWorkbookPermission();
const canPrint = permission.getPoint(univerAPI.Enum.WorkbookPermissionPoint.Print);
console.log(canPrint);
```

Source: 

`@univerjs/sheets`

### `getSnapshot`

Get a snapshot of all permission points.

**Signature**

```typescript
getSnapshot(): WorkbookPermissionSnapshot
```

**Returns**

* `WorkbookPermissionSnapshot` — An object containing all permission point values.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const snapshot = fWorkbook.getWorkbookPermission().getSnapshot();
console.log(snapshot);
```

Source: 

`@univerjs/sheets`

### `listCollaborators`

List all collaborators of the workbook.

**Signature**

```typescript
async listCollaborators(): Promise<ICollaborator[]>
```

**Returns**

* `Promise<ICollaborator[]>` — Array of collaborators with their roles.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const permission = fWorkbook.getWorkbookPermission();
const collaborators = await permission.listCollaborators();
console.log(collaborators);
```

Source: 

`@univerjs/sheets`

### Setters & Modifiers

### `setCollaborators`

Set multiple collaborators at once (replaces existing collaborators).

**Signature**

```typescript
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**

```ts
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
  }
]);
```

Source: 

`@univerjs/sheets`

### `setEditable`

Set the workbook to editable mode (editor mode).

**Signature**

```typescript
async setEditable(): Promise<void>
```

**Returns**

* `Promise<void>` — A promise that resolves when the mode is set.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
await fWorkbook.getWorkbookPermission().setEditable();
```

Source: 

`@univerjs/sheets`

### `setMode`

Set permission mode for the workbook.

**Signature**

```typescript
async setMode(mode: WorkbookMode): Promise<void>
```

**Parameters**

* `mode` `WorkbookMode` — *No description*

**Returns**

* `Promise<void>` — A promise that resolves when the mode is set.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
await fWorkbook.getWorkbookPermission().setMode('editor');
```

Source: 

`@univerjs/sheets`

### `setPoint`

Set a specific permission point.

**Signature**

```typescript
async setPoint(point: WorkbookPermissionPoint, value: boolean): Promise<void>
```

**Parameters**

* `point` `WorkbookPermissionPoint` — *No description*
* `value` `boolean` — *No description*

**Returns**

* `Promise<void>` — A promise that resolves when the point is set.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const permission = fWorkbook.getWorkbookPermission();
await permission.setPoint(univerAPI.Enum.WorkbookPermissionPoint.Print, false);
```

Source: 

`@univerjs/sheets`

### `setReadOnly`

Set the workbook to read-only mode (viewer mode).

**Signature**

```typescript
async setReadOnly(): Promise<void>
```

**Returns**

* `Promise<void>` — A promise that resolves when the mode is set.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
await fWorkbook.getWorkbookPermission().setReadOnly();
```

Source: 

`@univerjs/sheets`

### `updateCollaborator`

Update an existing collaborator's role and information.

**Signature**

```typescript
async updateCollaborator(user: ICollaboratorUser, role: UnitRole): Promise<void>
```

**Parameters**

* `user` `ICollaboratorUser` — *No description*
* `role` `UnitRole` — *No description*

**Returns**

* `Promise<void>` — A promise that resolves when the collaborator is updated.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const permission = fWorkbook.getWorkbookPermission();
await permission.updateCollaborator(
  { userID: 'user1', name: 'John Doe Updated', avatar: 'https://...' },
  univerAPI.Enum.UnitRole.Reader
);
```

Source: 

`@univerjs/sheets`

### Actions & Operations

### `removeCollaborator`

Remove a collaborator from the workbook.

**Signature**

```typescript
async removeCollaborator(userId: string): Promise<void>
```

**Parameters**

* `userId` `string` — *No description*

**Returns**

* `Promise<void>` — A promise that resolves when the collaborator is removed.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const permission = fWorkbook.getWorkbookPermission();
await permission.removeCollaborator('user1');
```

Source: 

`@univerjs/sheets`

### `removeCollaborators`

Remove multiple collaborators at once.

**Signature**

```typescript
async removeCollaborators(userIds: string[]): Promise<void>
```

**Parameters**

* `userIds` `string[]` — *No description*

**Returns**

* `Promise<void>` — A promise that resolves when the collaborators are removed.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const permission = fWorkbook.getWorkbookPermission();
await permission.removeCollaborators(['user1', 'user2']);
```

Source: 

`@univerjs/sheets`
