Display conditions
通过在扩展模块上设置显示条件,可以控制扩展模块在用户界面中的可见性,显示条件通过 display 属性设置。
概述
显示条件在客户端执行,无法保证执行结果不会通过浏览器开发者工具被覆盖,不能依赖显示条件作为保护敏感数据的机制。对于将要操作的任何敏感数据,强烈建议在显示条件的基础上,在代码中进行适当的权限检查。
示例:
yaml
extensions:
- key: hello-world-project-page
resource: main
target: "pcm:pjm:project:page"
resolver:
function: resolver
title: Hello world
display:
and:
hasPermission: "pca:global:pjm:configuration"
project.name: scrum
not:
project.id: 111111
or:
workitem.identifier: TT-2条件操作符
显示条件支持以下操作符用于进行多个条件之间的逻辑判断,默认情况下,多个显示条件之间通过 and 操作符连接。
| 名称 | 描述 |
|---|---|
and | 所有子条件为 true |
or | 任一子条件为 true |
not | 子条件取反 |
示例:
yaml
extensions:
- key: hello-world-project-page
resource: main
target: "pcm:pjm:project:page"
resolver:
function: resolver
title: Hello world
display:
or:
project.type: scrum
and:
project.identifier: PJM
workitem.type_group: 1通用条件
通用条件对所有扩展模块都适用,目前平台支持以下三个通用条件判断:
| 名称 | 描述 |
|---|---|
hasPermission | 用户拥有指定权限点,可以指定的权限点参考: 权限点定义 |
isTeamOwner | 是否为组织所有者 |
isLoggedIn | 当前用户是否已登录 |
示例:
yaml
extensions:
- key: hello-world-project-page
resource: main
target: "pcm:pjm:project:page"
resolver:
function: resolver
title: Hello world
display:
hasPermission: "pca:global:pjm:configuration"
isTeamOwner: true表达式条件
可通过 expression 使用 表达式 ,与同层条件及 and / or / not 组合。结果须为 true 才视为成立。
typescript
display:
isLoggedIn: true
expression: "workitem.assignee.id == user.id"求值上下文:
| 字段 | 描述 |
|---|---|
user | 当前登录用户,字段见 User |
app | 当前安装对应 manifest 的 app ,字段见 App |
资源(如 workitem 、 project ) | 平台按 id 加载,结构同对应 REST API |
例如 workitem 的字段与 获取一个工作项 ( GET /v2/pjm/workitems/{workitem_id} )的响应一致,可直接读取其中属性。其他资源同理,以对应 REST API 为准。
上下文条件
不同的扩展模块,可以使用扩展模块所能访问的上下文数据进行显示条件的判断,每个扩展模块可以访问的上下文数据定义参考具体模块定义。
示例:
yaml
extensions:
- key: hello-world-project-page
resource: main
target: "pcm:pjm:project:page"
resolver:
function: resolver
title: Hello world
display:
and:
project.name: scrum
not:
project.identifier: PJM
or:
workitem.type_group: 1