Last updated Apr 8, 2024

Conditions

A condition specifies requirements that must be met for a user to access the features or UI exposed by a module. For instance, the condition can require a user to be an administrator, have edit permissions, and apply other requirements for access. If the condition is not met, the panel, page, or other UI element exposed by the app does not appear on the page.

Various types of modules accept conditions, including generalPages, adminPages, and webItems. To see whether a certain module accepts conditions, see their specific module documentation page.

List of available conditions

The following conditions are currently available:

equals

This condition checks if target and value parameter are equal.

The target parameter is required.

1
2
{
    "name": "My App",
    "modules": {
        "generalPages": [
            {
                "conditions": [
                    {
                        "condition": "equals",
                        "target": "repository.uuid",
                        "params": {
                            "value": "{13eefc7e-5f6a-4d89-82f3-d85981e0bfa2}"
                        }
                    }
                ]
            }
        ]
    }
}

contains

This condition checks if the target object contains value parameter. It can only be applied if target was resolved to Array, Object or string

The target parameter is required.

1
2
{
    "name": "My App",
    "modules": {
        "generalPages": [
            {
                "conditions": [
                    {
                        "condition": "contains",
                        "target": "repository.properties.get(attribute=app.key)",
                        "invert": true,
                        "params": {
                            "value": "myproperty"
                        }
                    }
                ]
            }
        ]
    }
}

has_account_permission

This condition restricts access to the modules based upon user permission settings for the account and can have the following parameters:

  • collaborator: is a member of the team but not an administrator.
  • admin: is an administrator for the team.
The `Collaborator` role is being removed from the Bitbucket Cloud API. For more information, see the [deprecation announcement](/cloud/bitbucket/deprecation-notice-collaborator-role/).
1
2
{
    "name": "My App",
    "modules": {
        "generalPages": [
            {
                "conditions": [
                    {
                        "condition": "has_account_permission",
                        "invert": true,
                        "params": {
                            "permission": "collaborator"
                        }
                    }
                ]
            }
        ]
    }
}

has_permission

This condition restricts access to the modules based upon user permission settings for the repository and has the following parameters:

  • read: has read access to the repository.
  • write: has write access to the repository.
  • admin: has administrator access to the repository.
1
2
{
    "name": "My App",
    "modules": {
        "generalPages": [
            {
                "conditions": [
                    {
                        "condition": "has_permission",
                        "invert": false,
                        "params": {
                            "permission": "admin"
                        }
                    }
                ]
            }
        ]
    }
}

has_workspace_permission

This condition restricts access to the modules based upon user permission settings for the workspace and has the following parameters:

  • collaborator: is a member of the workspace but not an administrator.
  • admin: is an administrator for the workspace.
1
2
{
    "name": "My App",
    "modules": {
        "generalPages": [
            {
                "conditions": [
                    {
                        "condition": "has_workspace_permission",
                        "target": "workspace",
                        "params": {
                            "permission": "admin"
                        }
                    }
                ]
            }
        ]
    }
}

has_issue_permission

This condition restricts access to the modules based upon user's ability to interact with repository issue tracker.

1
2
{
    "name": "My App",
    "modules": {
        "generalPages": [
            {
                "conditions": [
                    {
                        "condition": "has_issue_permission",
                        "target": "repository"
                    }
                ]
            }
        ]
    }
}

meets_access_requirements

This condition checks if the user meets access conditions like a team's requirement for its members to have 2fa enabled, or coming from a whitelisted IP in cases where a team has that configured.

1
2
{
    "name": "My App",
    "modules": {
        "generalPages": [
            {
                "conditions": [
                    {
                        "condition": "meets_access_requirements",
                        "target": "target_user"
                    }
                ]
            }
        ]
    }
}

is_repo_private

This condition checks to see if the repository in question is private or not.

1
2
{
    "name": "My App",
    "modules": {
        "generalPages": [
            {
                "conditions": [
                    {
                        "condition": "is_repo_private",
                        "target": "repository"
                    }
                ]
            }
        ]
    }
}

property_exists

This condition checks to see if an application property exists. Learn more about application properties.

In the example below the module is only rendered if the property myproperty has been set.

1
2
{
    "name": "My App",
    "modules": {
        "generalPages": [
            {
                "conditions": [
                    {
                        "condition": "property_exists",
                        "target": "repository.properties",
                        "params": {
                            "appKey": {
                                "eval": "app.key"
                            },
                            "propertyKey": "myproperty"
                        }
                    }
                ]
            }
        ]
    }
}

Optionally, objectName parameter can be provided to check if the property value contains a specific key.

1
2
{
    "name": "My App",
    "modules": {
        "generalPages": [
            {
                "conditions": [
                    {
                        "condition": "property_exists",
                        "target": "repository.properties",
                        "params": {
                            "appKey": {
                                "eval": "app.key"
                            },
                            "propertyKey": "myproperty",
                            "objectName": "foo"
                        }
                    }
                ]
            }
        ]
    }
}

In this example the condition will be met if the property myproperty has been set and it contains key foo:

1
2
{
  "foo": "any_value",
  "bar": "any_value"
}

has_file

This condition checks to see if the file in question exists.

Optionally, cset parameter can be provided to look for a file in a specific commit.

1
2
{
    "name": "My App",
    "modules": {
        "generalPages": [
            {
                "conditions": [
                    {
                        "condition": "has_file",
                        "target": "repository",
                        "params": {
                            "filename": "myfile.txt"
                        }
                    }
                ]
            }
        ]
    }
}

is_binary

This condition checks to see if the file in question is binary or not.

1
2
{
    "name": "My App",
    "modules": {
        "fileViews": [
            {
                "conditions": [
                    {
                        "condition": "is_binary",
                        "target": "file",
                        "invert": true
                    }
                ]
            }
        ]
    }
}

user_is_logged_in

This condition checks to see if the user is logged in.

1
2
{
    "name": "My App",
    "modules": {
        "generalPages": [
            {
                "conditions": [
                    {
                        "condition": "user_is_logged_in"
                    }
                ]
            }
        ]
    }
}

user_has_premium

This condition checks to see if the user has premium account.

1
2
{
    "name": "My App",
    "modules": {
        "generalPages": [
            {
                "conditions": [
                    {
                        "condition": "user_has_premium"
                    }
                ]
            }
        ]
    }
}

has_addon

This condition checks if an addon is installed to the account based on the provided addon key.

1
2
{
    "name": "My App",
    "modules": {
        "generalPages": [
            {
                "conditions": [
                    {
                        "condition": "has_addon",
                        "target": "repository.owner",
                        "params": {
                            "key": "some-addon-key"
                        }
                    }
                ]
            }
        ]
    }
}

Boolean operations

The Composite Condition module fragment can be used wherever a condition is expected. This allows the construction of boolean expressions aggregating multiple conditions.

For example, the condition bellow evaluates to true when:

  • the user is logged in AND
  • repository has Dockerfile OR docker-compose file

Written as a composite condition that looks like this:

1
2
{
  "conditions": [
      {
          "type": "or",
          "conditions": [
              {
                  "condition": "has_file",
                  "target": "repository",
                  "params": {
                      "filename": "Dockerfile"
                  }
              },
              {
                  "condition": "has_file",
                  "target": "repository",
                  "params": {
                      "filename": "docker-compose.yml"
                  }
              }
          ]
      },
      {
          "condition": "user_is_logged_in"
      }
  ]
}

Composite conditions allow "or" and "and" conditions to be written for Atlassian Connect apps. You can also get a NOT operation by using the "invert" field on single conditions; as the above example shows.

Note: The top most conditions block is implicitly a composite "and" condition.

Rate this page: