Write access (aka push access) is required to use the restart or deploy buttons. Drone uses the Bitbucket API endpoints to determine whether or not a user has read, write or admin access.
First the system checks if the user has read access access. We know a user has read access to the repository if they can access the repository API endpoint [1] without error:
rest/api/1.0/projects/{PROJECT}/repos/{NAME}
If this fails, the user is denied access and you will see an error in the server logs:
api: repository permissions not found
Else if the user has read access, the system checks if the user also has admin access. Bitbucket does not provide a clean API for checking admin permissions, however, we know that only admin users can access repository webhooks. So to determine admin access, the system makes an API call to the webhook list endpoint to test for admin access [2].
rest/api/1.0/projects/{PROJECT}/repos/{NAME}/webhooks
If the user does not have admin access to the repository, the system checks to see if the user has write access to the repository. For write access, the system uses the list repositories endpoint [3], with a filter on write permissions:
rest/api/1.0/repos?size=1000&permission=REPO_WRITE&projectname=${PROJECT}&name=${NAME}
The above endpoint performs a wildcard search on the repository name, which means the response can include multiple repositories in the list. The system iterates through the results and checks for an entry in the list that is an exact match to the repository name. If an exact match is found, the user is granted write permissions to the repository:
repos, _, _ := s.listWrite(ctx, repo)
for _, repo := range repos {
if repo.Name == name {
return &scm.Perm{
Pull: true,
Push: true,
Admin: false,
}, nil, nil
}
}
Else the user is granted read access (aka pull access) to the repository and will not have access to the restart or deploy buttons in the user interface.
Users should be able to reproduce and verify this behavior using the above logic and endpoints.
[1] https://github.com/drone/go-scm/blob/master/scm/driver/stash/repo.go#L120
[2] https://github.com/drone/go-scm/blob/master/scm/driver/stash/repo.go#L130
[3] https://github.com/drone/go-scm/blob/master/scm/driver/stash/repo.go#L139