0
Get an explicit user permission for a project
One script reply has been approved by the moderators Verified

Returns the explicit user permission for a given user and project.

Only users with admin permission for the project may access this resource.

Permissions can be:

  • admin
  • create-repo
  • write
  • read
  • none
Created by hugo697 429 days ago Viewed 9563 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 429 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * Get an explicit user permission for a project
7
 * Returns the explicit user permission for a given user and project.
8

9
Only users with admin permission for the project may access this resource.
10

11
Permissions can be:
12

13
* `admin`
14
* `create-repo`
15
* `write`
16
* `read`
17
* `none`
18
 */
19
export async function main(
20
  auth: Bitbucket,
21
  project_key: string,
22
  selected_user_id: string,
23
  workspace: string
24
) {
25
  const url = new URL(
26
    `https://api.bitbucket.org/2.0/workspaces/${workspace}/projects/${project_key}/permissions-config/users/${selected_user_id}`
27
  );
28

29
  const response = await fetch(url, {
30
    method: "GET",
31
    headers: {
32
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42