[comment]: # translation:outdated

[comment]: # ({a0f60ec7-a0f60ec7})
# 更新

[comment]: # ({/a0f60ec7-a0f60ec7})

[comment]: # ({473edc13-63875138})
### 说明
`object role.update(object/array roles)`

This method allows to update existing roles.
用户使用该方法可以用来更新存在的角色用户。

::: 请注意
该方式仅对_超级管理员_类型的用户生效。 用户可以在用户角色设置中对该方式的使用权限进行设定修改。请参考 [用户角色](/manual/web_interface/frontend_sections/users/user_roles)以获取更多信息。
:::

[comment]: # ({/473edc13-63875138})

[comment]: # ({d414178e-fa5c3d93})
### 参数

`(object/array)` 要更新的角色属性。

必须为每个角色定义 `roleid` 属性，所有其他属性均为可选。
只有传入的属性会被更新，其他所有属性将保持不变。

除了[标准角色属性](object#role)之外，该方法还接受以下参数。

|参数|[Type](/manual/api/reference_commentary#data-types)|说明|
|--|--|------|
|rules|array|要为该角色更新的访问[rules](object#role-rules)。|

[comment]: # ({/d414178e-fa5c3d93})

[comment]: # ({12d196f6-12d196f6})
### 返回值

根据`roleids`的特性，`(object)`返回一个包含已更新职责用户ID的对象

[comment]: # ({/12d196f6-12d196f6})

[comment]: # ({b41637d2-b41637d2})
### 示例

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({0832e69f-1ce1fe70})
#### 关闭运行脚本功能
更新ID号为5的角色，关闭其运行脚本的功能。
[请求](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "role.update",
    "params": [
        {
            "roleid": "5",
            "rules": {
                "actions": [
                    {
                        "name": "execute_scripts",
                        "status": "0"
                    }
                ]
            }
        }
    ],
    "id": 1
}
```

响应：
```json
{
    "jsonrpc": "2.0",
    "result": {
        "roleids": [
            "5"
        ]
    },
    "id": 1
}
```

[comment]: # ({/0832e69f-1ce1fe70})

[comment]: # ({19ad5660-a6349165})
#### 限制对API的访问
更新ID号为5的角色，拒绝任何 "创建", "更新" 或者 "删除" 方式。
[请求](/manual/api#performing-requests):
```json
{
    "jsonrpc": "2.0",
    "method": "role.update",
    "params": [
        {
            "roleid": "5",
            "rules": {
                "api.access": "1",
                "api.mode": "0",
                "api": ["*.create", "*.update", "*.delete"]
            }
        }
    ],
    "id": 1
}
```

Response:
响应：
```json
{
    "jsonrpc": "2.0",
    "result": {
        "roleids": [
            "5"
        ]
    },
    "id": 1
}
```

[comment]: # ({/19ad5660-a6349165})

[comment]: # ({36db1bd2-36db1bd2})
### 参考来源

CRole::update() in *ui/include/classes/api/services/CRole.php*.

[comment]: # ({/36db1bd2-36db1bd2})
