# informat.user 用户操作

## 概述

使用`informat.user`对象进行用户信息操作

***

## getUser

查询用户信息getUser

```javascript
informat.user.getUser(id)
```

| 参数 | 类型     | 描述   |
|----|--------|------|
| id | String | 用户ID |

**返回值**
类型为 [User](/guide/script/model.md#user)
返回用户信息，如果用户不存在返回`null`

示例：

:::code-group

```js[调用]
informat.user.getUser('zhangsan');
```

```json[返回值]
{
  "avatar": "pic10.png",
  "companyRoleList": [
    "admin",
    "tester"
  ],
  "departmentList": [
    "yanfabu",
    "yunyingbu"
  ],
  "id": "zhangsan",
  "leaderList": [
    "lisi"
  ],
  "name": "张三",
  "roleList": [
    "tester",
    "admin"
  ],
  "userInfo": {
    "age": 20
  }
}
```

:::

## getUserInfo

查询用户详细信息

```javascript
informat.user.getUserInfo(id)
```

| 参数 | 类型     | 描述   |
|----|--------|------|
| id | String | 用户ID |

**返回值**
类型为 [UserInfo](/guide/script/model.md#userinfo)
返回用户信息，如果用户不存在返回`null`

示例：

:::code-group

```js[调用]
informat.user.getUserInfo('zhangsan');
```

```json[返回值]
{
  "avatar": "pic10.png",
  "companyRoleList": [
    "admin",
    "tester"
  ],
  "departmentList": [
    "yanfabu",
    "yunyingbu"
  ],
  "email": "zhangsan@informat.cn",
  "id": "zhangsan",
  "leaderList": [
    "lisi"
  ],
  "mobileNo": "19900000000",
  "name": "张三",
  "roleList": [
    "tester",
    "admin"
  ],
  "userInfo": {
    "age": 20
  },
  "userName": "zhangsan"
}
```

:::

## getUserList

根据用户ID列表查询用户列表
:::tip
列表查询不返回用户扩展信息
:::

```javascript
informat.user.getUserList(idList)
```

| 参数     | 类型              | 描述     |
|--------|-----------------|--------|
| idList | `Array<String>` | 用户ID列表 |

**返回值**
类型为 Array<[User](/guide/script/model.md#user)>
返回用户列表

示例：

:::code-group

```js[调用]
informat.user.getUserList(['zhangsan','lisi']);
```

```json[返回值]
[
  {
    "avatar": "pic10.png",
    "companyRoleList": [
      "admin",
      "tester"
    ],
    "departmentList": [
      "yanfabu",
      "yunyingbu"
    ],
    "id": "zhangsan",
    "leaderList": [
      "lisi"
    ],
    "name": "张三",
    "roleList": [
      "tester",
      "admin"
    ]
  }
]
```

:::

## getAppUserList

查询应用成员列表
:::tip
需要注意的是这里不返回用户扩展信息
:::

```javascript
informat.user.getAppUserList()
```

**返回值**
类型为 Array<[User](/guide/script/model.md#user)>
返回应用成员列表

示例：

:::code-group

```js[调用]
informat.user.getAppUserList();
```

```json[返回值]
[
  {
    "avatar": "pic10.png",
    "companyRoleList": [
      "admin",
      "tester"
    ],
    "departmentList": [
      "yanfabu",
      "yunyingbu"
    ],
    "id": "zhangsan",
    "leaderList": [
      "lisi"
    ],
    "name": "张三",
    "roleList": [
      "admin"
    ]
  }
]
```

:::

## getUserByRoleList

根据应用角色查询用户列表
:::tip
需要注意的是这里不返回用户扩展信息
:::

```javascript
informat.user.getUserByRoleList(['admin'])
```

| 参数       | 类型              | 描述        |
|----------|-----------------|-----------|
| roleList | `Array<String>` | 应用角色标识符列表 |

**返回值**
类型为 Array<[User](/guide/script/model.md#user)>
返回用户列表

示例：

:::code-group

```js[调用]
informat.user.getUserByRoleList('admin');
```

```json[返回值]
[
  {
    "avatar": "pic10.png",
    "companyRoleList": [
      "admin",
      "tester"
    ],
    "departmentList": [
      "yanfabu",
      "yunyingbu"
    ],
    "id": "zhangsan",
    "leaderList": [
      "lisi"
    ],
    "name": "张三",
    "roleList": [
      "admin"
    ]
  },
  {
    "avatar": "pic22.png",
    "companyRoleList": [
      "admin",
      "tester"
    ],
    "departmentList": [
      "yanfabu",
      "yunyingbu"
    ],
    "id": "lisi",
    "leaderList": [],
    "name": "李四",
    "roleList": [
      "admin"
    ]
  }
]
```

:::

## getUserByDeptList

根据部门查询用户列表

```javascript
informat.user.getUserByDeptList(deptList)
```

| 参数       | 类型              | 描述      |
|----------|-----------------|---------|
| deptList | `Array<String>` | 部门标识符列表 |

**返回值**
类型为 Array<[User](/guide/script/model.md#user)>
返回用户列表

示例：

:::code-group

```javascript
informat.user.getUserByDeptList(['yanfabu', 'yunyingbu']); 
```

```json[返回值]
[
  {
    "avatar": "pic10.png",
    "companyRoleList": [
      "admin",
      "tester"
    ],
    "departmentList": [
      "yanfabu",
      "yunyingbu"
    ],
    "id": "zhangsan",
    "leaderList": [
      "lisi"
    ],
    "name": "张三",
    "roleList": [
      "admin"
    ]
  }
]
```

:::

## getSuperiorUsers

查询用户的直接上级

```javascript
informat.user.getSuperiorUsers(userId)
```

| 参数     | 类型     | 描述   |
|--------|--------|------|
| userId | String | 用户ID |

**返回值**
类型为 Array<[User](/guide/script/model.md#user)>
返回用户上级列表

示例:

:::code-group

```js[调用]
informat.user.getSuperiorUsers('zhangsan');
```

```json[返回值]
[
  {
    "avatar": "pic22.png",
    "companyRoleList": [
      "admin",
      "tester"
    ],
    "departmentList": [
      "yanfabu",
      "yunyingbu"
    ],
    "id": "lisi",
    "leaderList": [],
    "name": "李四",
    "roleList": [
      "admin"
    ]
  }
]
```

:::

## getSubordinateUsers

查询用户的直接下属

```javascript
informat.user.getSubordinateUsers(userId)
```

| 参数     | 类型     | 描述   |
|--------|--------|------|
| userId | String | 用户ID |

**返回值**
类型为 Array<[User](/guide/script/model.md#user)>
返回用户下属列表

示例：

:::code-group

```js[调用]
informat.user.getSubordinateUsers('lisi');
```

```json[返回值]
[
  {
    "avatar": "pic10.png",
    "companyRoleList": [
      "admin",
      "tester"
    ],
    "departmentList": [
      "yanfabu",
      "yunyingbu"
    ],
    "id": "zhangsan",
    "leaderList": [
      "lisi"
    ],
    "name": "张三",
    "roleList": [
      "tester",
      "admin"
    ]
  }
]
```

:::

## getLeaderOfDeptList

查询部门的负责人

```javascript
informat.user.getLeaderOfDeptList(deptList)
```

| 参数       | 类型              | 描述     |
|----------|-----------------|--------|
| deptList | `Array<String>` | 部门ID列表 |

**返回值**
类型为 Array<[User](/guide/script/model.md#user)>
返回部门负责人列表

示例：

:::code-group

```js[调用]
informat.user.getLeaderOfDeptList(['yunyingbu']);
```

```json[返回值]
[
  {
    "avatar": "pic14.png",
    "companyRoleList": [
      "admin"
    ],
    "departmentList": [
      "yunyingbu"
    ],
    "id": "l4cntsd6j16qv",
    "leaderList": [],
    "name": "大熊",
    "roleList": []
  }
]
```

:::

## getUserRoleList

查询应用角色列表

```javascript
informat.user.getUserRoleList()
```

**返回值**
类型为Array<[UserRole](/guide/script/model.md#userrole)>
返回所有应用角色列表

示例：

:::code-group

```js[调用]
informat.user.getUserRoleList();
```

```json[返回值]
[
  {
    "admin": true,
    "id": "admin",
    "isAdmin": true,
    "name": "管理员",
    "permissionList": []
  },
  {
    "admin": false,
    "id": "hrManager",
    "isAdmin": false,
    "name": "HR",
    "permissionList": [
      "AppAccess",
      "AppMember",
      "gkxv4nq60zdwm",
      "task_taskCustomPermission"
    ]
  }
]
```

:::

## addUser

添加用户到应用中

```javascript
informat.user.addUser(userId, roleList)
```

| 参数       | 类型              | 描述     |
|----------|-----------------|--------|
| userId   | String          | 用户ID   |
| roleList | `Array<String>` | 应用角色列表 |

示例：将用户张三添加到应用中，并赋予管理员和测试两个角色

```javascript
informat.user.addUser('zhangsan', ['admin', 'tester']);
```

## updateUserRole

更新应用成员的角色

```javascript
informat.user.updateUserRole(userId, roleList)
```

| 参数       | 类型              | 描述     |
|----------|-----------------|--------|
| userId   | String          | 用户ID   |
| roleList | `Array<String>` | 应用角色列表 |

示例:将用户张三的应用角色改为测试人员

```javascript
informat.user.updateUserRole('zhangsan', ['tester']);
```

## deleteUser

将用户从应用中移除

```javascript
informat.user.deleteUser(userId)
```

| 参数     | 类型     | 描述   |
|--------|--------|------|
| userId | String | 用户ID |

示例：将用户张三从应用中移除

```javascript
informat.user.deleteUser('zhangsan');
```

## getUserPermissions

查询用户所有应用权限

```javascript
informat.user.getUserPermissions(userId)
```

| 参数     | 类型       | 描述   |
|--------|----------|------|
| userId | `String` | 用户ID |

**返回值**
类型为`Array<String>`
返回用户所有应用权限列表

示例：查询用户张三所有应用权限

```javascript
informat.user.getUserPermissions('zhangsan');
```

## getAllPermissions

查询所有应用权限定义

```javascript
informat.user.getAllPermissions()
```

**返回值**
类型为`Array<String>`
返回所有应用权限定义

示例：查询所有应用权限定义

```javascript
informat.user.getAllPermissions();
```

