# FRangePermission

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

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

- Requested language: `en-US`

- Content language: `en-US`

- Documentation version: `1.0.0-rc.0`

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

---

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

Implementation class for RangePermission
Manages range-level permissions

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

## Overview

### @univerjs/sheets

| Method                        | Description                                                       |
| ----------------------------- | ----------------------------------------------------------------- |
| [`isProtected`](#isprotected) | Check if the current range is protected                           |
| [`listRules`](#listrules)     | List all protection rules that intersect with the current range   |
| [`protect`](#protect)         | Protect the current range                                         |
| [`unprotect`](#unprotect)     | Cancel all protection rules that intersect with the current range |

## APIs

### Getters & Queries

### `isProtected`

Check if the current range is protected.

**Signature**

```typescript
isProtected(): boolean
```

**Returns**

* `boolean` — True if the range is protected, false otherwise.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
// Check if the A1:B2 range is protected
const isProtected = fRange.getRangePermission().isProtected();
console.log(isProtected);
```

Source: 

`@univerjs/sheets`

### `listRules`

List all protection rules that intersect with the current range.

**Signature**

```typescript
async listRules(options?: {
            ignoreCollaborators?: boolean; // Option to ignore fetching collaborators for performance
        }): Promise<FRangeProtectionRule[]>
```

**Parameters**

* `options` `{ ignoreCollaborators?: boolean; }` *(optional)* — *No description*

**Returns**

* `Promise<FRangeProtectionRule[]>` — Array of protection rules.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
const rules = await fRange.getRangePermission().listRules();
console.log(rules);
```

Source: 

`@univerjs/sheets`

### Miscellaneous

### `protect`

Protect the current range.

**Signature**

```typescript
async protect(options?: IRangeProtectionOptions): Promise<FRangeProtectionRule>
```

**Parameters**

* `options` `IRangeProtectionOptions` *(optional)* — *No description*

**Returns**

* `Promise<FRangeProtectionRule>` — The created protection rule.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
const rule = await fRange.getRangePermission().protect({
  name: 'My protected range',
  allowedUsers: ['user1', 'user2'],
  allowViewByOthers: false,
});
console.log(rule);
```

Source: 

`@univerjs/sheets`

### `unprotect`

Remove all protection rules that intersect with the current range.

**Signature**

```typescript
async unprotect(): Promise<boolean>
```

**Returns**

* `Promise<boolean>` — True if all rules were successfully removed, false otherwise.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
const result = await fRange.getRangePermission().unprotect();
console.log(result);
```

Source: 

`@univerjs/sheets`
