> For the complete documentation index, see [llms.txt](https://docs.forgenie.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.forgenie.com/specification/diamond-foundry/facets/accesscontrolfacet.md).

# AccessControlFacet

[Git Source](https://github.com/Forgenie/diamond-foundry/blob/e69a7af04e0636b77b9dd15df62c58172ec045da/src/facets/access-control/AccessControlFacet.sol)

**Inherits:** IAccessControl, AccessControlBase, Facet

## Functions

### AccessControl\_init

```solidity
function AccessControl_init(address roleAdmin) external onlyInitializing;
```

### setFunctionAccess

Sets the function access for a given role.

```solidity
function setFunctionAccess(bytes4 functionSig, uint8 role, bool enabled) external onlyAuthorized;
```

**Parameters**

| Name          | Type     | Description                                           |
| ------------- | -------- | ----------------------------------------------------- |
| `functionSig` | `bytes4` | The function signature to set access for.             |
| `role`        | `uint8`  | The role to set access for.                           |
| `enabled`     | `bool`   | Whether the role should be able to call the function. |

### setUserRole

Sets the role for a given user.

```solidity
function setUserRole(address user, uint8 role, bool enabled) external onlyAuthorized;
```

**Parameters**

| Name      | Type      | Description                            |
| --------- | --------- | -------------------------------------- |
| `user`    | `address` | The user to set the role for.          |
| `role`    | `uint8`   | The role to set.                       |
| `enabled` | `bool`    | Whether the user should have the role. |

### canCall

Checks whether a given user can call a given function.

```solidity
function canCall(address user, bytes4 functionSig) external view returns (bool);
```

**Parameters**

| Name          | Type      | Description                      |
| ------------- | --------- | -------------------------------- |
| `user`        | `address` | The user to check.               |
| `functionSig` | `bytes4`  | The function signature to check. |

**Returns**

| Name     | Type   | Description                             |
| -------- | ------ | --------------------------------------- |
| `<none>` | `bool` | Whether the user can call the function. |

### userRoles

Gets the roles for a given user.

```solidity
function userRoles(address user) external view returns (bytes32);
```

**Parameters**

| Name   | Type      | Description                    |
| ------ | --------- | ------------------------------ |
| `user` | `address` | The user to get the roles for. |

**Returns**

| Name     | Type      | Description                                 |
| -------- | --------- | ------------------------------------------- |
| `<none>` | `bytes32` | The roles the user has encoded in 256 bits. |

### functionRoles

Gets the roles that can call a given function.

```solidity
function functionRoles(bytes4 functionSig) external view returns (bytes32);
```

**Parameters**

| Name          | Type     | Description                                  |
| ------------- | -------- | -------------------------------------------- |
| `functionSig` | `bytes4` | The function signature to get the roles for. |

**Returns**

| Name     | Type      | Description                                               |
| -------- | --------- | --------------------------------------------------------- |
| `<none>` | `bytes32` | The roles that can call the function encoded in 256 bits. |

### hasRole

Checks whether a given user has a given role.

```solidity
function hasRole(address user, uint8 role) external view returns (bool);
```

**Parameters**

| Name   | Type      | Description        |
| ------ | --------- | ------------------ |
| `user` | `address` | The user to check. |
| `role` | `uint8`   | The role to check. |

**Returns**

| Name     | Type   | Description                    |
| -------- | ------ | ------------------------------ |
| `<none>` | `bool` | Whether the user has the role. |

### roleHasAccess

Checks whether a given role can call a given function.

```solidity
function roleHasAccess(uint8 role, bytes4 functionSig) external view returns (bool);
```

**Parameters**

| Name          | Type     | Description                      |
| ------------- | -------- | -------------------------------- |
| `role`        | `uint8`  | The role to check.               |
| `functionSig` | `bytes4` | The function signature to check. |

**Returns**

| Name     | Type   | Description                             |
| -------- | ------ | --------------------------------------- |
| `<none>` | `bool` | Whether the role can call the function. |
