Home > Software engineering >  Is there a way to get the active user permissions for a specific Azure Devops Git Branch, using REST
Is there a way to get the active user permissions for a specific Azure Devops Git Branch, using REST

Time:01-27

I've experimented several ways, but I failed to find how to solve my problem.

Before starting an heavy process, I'd like to check if the use has proper rights to do it, for instance the "Force Push" permission.

For instance are there some undocumented parameters on this one to be more specific (at Git branch level instead of global permissions at organisation level) ? GET enter image description here

Checking and changing the branch Policies works fine, but I'm stuck to retrieve Permissions of the current User.

Any help would be very welcome, thanks.

I've tried for instance:

https://dev.azure.com/{organisation}/_apis/permissions/2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87/128?api-version=7.0 => global, not specific for a branch
https://dev.azure.com/{organization}/_apis/permissionsreport/2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87?api-version=7.0 => global, not specific for a branch

This page look very promising, but is missing petinent example or detailed explanations on how to do. https://learn.microsoft.com/en-us/rest/api/azure/devops/permissionsreport/?view=azure-devops-rest-7.0 Permissions reports can help administrators determine the effective permissions of users and groups upon securable resources in Azure DevOps. Generating a report for a resource (Git repository, branch, etc.) will list the effective permissions, upon that resource, for each user who has logged into the Azure DevOps organization and each group in the Azure DevOps organization. => Great, but how to do that?

CodePudding user response:

After quite a lot of experimentations, we found out the way to do it.

In order to get the permission for a given Git branch, you have to use the poorly documented Tokens parameter on the url. https://dev.azure.com/{organization}/_apis/permissions/{securityNamespaceId}/{permissions}?tokens=repoV2/{Project}/{RepositoryId}/refs/heads/{Branche}&api-version=7.0

Where Project is the guid for your project

RepositoryId is the Guid of your repository

And Branch is the hexa-encoded name of your branch.

  • Related