---
url: /reference/manifest/extensions-display-conditions.md
---

# 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` 操作符连接。

示例：

```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
```

## 通用条件

通用条件对所有扩展模块都适用，目前平台支持以下三个通用条件判断：

示例：

```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` 使用 [表达式](/guide/advanced/expressions) ，与同层条件及 `and` / `or` / `not` 组合。结果须为 `true` 才视为成立。

```typescript
display:
  isLoggedIn: true
  expression: "workitem.assignee.id == user.id"
```

求值上下文：

例如 `workitem` 的字段与 [获取一个工作项](https://developer.alpha.pingcode.live/restapi/pingcode/getV2PjmWorkitemsByWorkitemId) （ `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
```
