更新

说明

object role.update(object/array roles)

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

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

参数

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

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

除了标准角色属性之外,该方法还接受以下参数。

参数 Type 说明
rules array 要为该角色更新的访问rules

返回值

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

示例

关闭运行脚本功能

更新ID号为5的角色,关闭其运行脚本的功能。 请求:

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

响应:

{
    "jsonrpc": "2.0",
    "result": {
        "roleids": [
            "5"
        ]
    },
    "id": 1
}

限制对API的访问

更新ID号为5的角色,拒绝任何 "创建", "更新" 或者 "删除" 方式。 请求:

{
    "jsonrpc": "2.0",
    "method": "role.update",
    "params": [
        {
            "roleid": "5",
            "rules": {
                "api.access": "1",
                "api.mode": "0",
                "api": ["*.create", "*.update", "*.delete"]
            }
        }
    ],
    "id": 1
}

Response: 响应:

{
    "jsonrpc": "2.0",
    "result": {
        "roleids": [
            "5"
        ]
    },
    "id": 1
}

参考来源

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