# Permission（权限集管理）

Permission 模块用于管理 CloudCC 权限集的分配功能，包括查看权限集列表、查看已分配用户、添加分配用户和删除分配用户。

## 功能介绍

- **查看权限集列表**: 获取系统中的所有权限集
- **查看已分配用户**: 查看指定权限集已分配的用户列表
- **添加分配用户**: 为指定权限集分配用户
- **删除分配用户**: 从指定权限集中移除用户

## 命令

命令统一为 **`cloudcc <动作> <资源> …`**；本模块资源名为 **`permission`**。

### 获取权限集列表

```bash
cloudcc get permission <path> [viewId] [page] [pageSize] [searchKeyWord]
```

**参数说明：**
- `path` - 项目路径（可选，默认为当前目录）
- `viewId` - 视图ID（可选，不传则自动获取）
- `page` - 页码（可选，默认为1）
- `pageSize` - 每页数量（可选，默认为100000）
- `searchKeyWord` - 搜索关键词（可选）

**示例：**

```bash
# Get all permission sets
cloudcc get permission .

# Get permission sets with a specified view
cloudcc get permission . "00000000000000000000"

# Search permission sets
cloudcc get permission . "" 1 100 "Test"
```

### 查看已分配用户

```bash
cloudcc assign permission <path> <permsetId>
```

**参数说明：**
- `path` - 项目路径（可选，默认为当前目录）
- `permsetId` - 权限集ID（必需）

**示例：**

```bash
# View users assigned to a permission set
cloudcc assign permission . "cac20258F0E4ABBnTxwi"
```

**输出示例：**

```
Permission set: Ancient Saying
ID: cac20258F0E4ABBnTxwi

6 users assigned:

  User ID                 Name      Login Name           Profile           Role
  --------------------  --------  --------------------  ----------------  ----------------
  00520263DB1540FTPmXK  Re-registered User  421865903teet@qq.com  CloudCC Partner Profile  Partner User
  005202652FF2FA8dltk1  autoRow    autoTest@cloudcc.com  System Administrator        Test
  ...
```

### 添加分配用户

```bash
cloudcc add permission <path> <permsetId> [userIds...]
```

**参数说明：**
- `path` - 项目路径（可选，默认为当前目录）
- `permsetId` - 权限集ID（必需）
- `userIds` - 要分配的用户ID列表（可选，不传则进入交互式选择）

**示例：**

```bash
# Select users interactively for assignment
cloudcc add permission . "cac20258F0E4ABBnTxwi"

# Specify user IDs directly for assignment (separate multiple IDs with spaces)
cloudcc add permission . "cac20258F0E4ABBnTxwi" "00520260C00C6FEfsMnT" "0052026C0A60504jNcbV"
```

**交互式选择模式：**

如果不指定 userIds，命令会进入交互式选择模式，展示所有可用用户供选择：

```
? Select users to assign (space to select, enter to confirm): (Press <space> to select, <a> to toggle all, <i> to invert selection)
 ❯◯ John Zhang (zhangsan@example.com) - 00520260C00C6FEfsMnT
  ◯ Lisa Li (lisi@example.com) - 0052026C0A60504jNcbV
  ◯ Mark Wang (wangwu@example.com) - 0052026D0A60504jNcbW
```

### 删除分配用户

```bash
cloudcc remove permission <path> <permsetId> [userIds...]
```

**参数说明：**
- `path` - 项目路径（可选，默认为当前目录）
- `permsetId` - 权限集ID（必需）
- `userIds` - 要移除的用户ID列表（可选，不传则进入交互式选择）

**示例：**

```bash
# Select users interactively for removal
cloudcc remove permission . "cac20258F0E4ABBnTxwi"

# Specify user IDs directly for removal (separate multiple IDs with spaces)
cloudcc remove permission . "cac20258F0E4ABBnTxwi" "00520260C00C6FEfsMnT" "0052026C0A60504jNcbV"
```

**交互式选择模式：**

如果不指定 userIds，命令会进入交互式选择模式，展示当前已分配的用户供选择：

```
? Select users to remove (space to select, enter to confirm): (Press <space> to select, <a> to toggle all, <i> to invert selection)
 ❯◯ John Zhang (zhangsan@example.com) - 00520260C00C6FEfsMnT
  ◯ Lisa Li (lisi@example.com) - 0052026C0A60504jNcbV

? Remove 2 users from the permission set? (y/N)
```

## 完整使用流程示例

```bash
# 1. View all permission sets
cloudcc get permission .

# 2. View users assigned to a permission set
cloudcc assign permission . "cac20258F0E4ABBnTxwi"

# 3. Add users to a permission set (interactive selection)
cloudcc add permission . "cac20258F0E4ABBnTxwi"

# 4. View assigned users again to confirm the assignment succeeded
cloudcc assign permission . "cac20258F0E4ABBnTxwi"

# 5. Remove some users (interactive selection)
cloudcc remove permission . "cac20258F0E4ABBnTxwi"
```

## 数据结构

### 权限集对象

```json
{
    "name": "Ancient Saying",
    "licence": "CloudCC User",
    "id": "cac20258F0E4ABBnTxwi",
    "sysadmin": "0"
}
```

**字段说明：**
- `name` - 权限集名称
- `licence` - 许可证类型
- `id` - 权限集唯一标识
- `sysadmin` - 是否为系统管理员权限（"1"表示是，"0"表示否）

### 用户对象

```json
{
    "loginname": "421865903teet@qq.com",
    "profileid": "aaa000002",
    "rolename": "Partner User",
    "roleid": "2026A3D78466C42UokMO",
    "profilename": "CloudCC Partner Profile",
    "name": "Re-registered User",
    "alias": null,
    "id": "00520263DB1540FTPmXK"
}
```

**字段说明：**
- `id` - 用户唯一标识
- `name` - 用户姓名
- `loginname` - 登录名（邮箱）
- `profilename` - 简档名称
- `profileid` - 简档ID
- `rolename` - 角色名称
- `roleid` - 角色ID
- `alias` - 别名
