Delete an explicit user permission for a project

Deletes the project user permission between the requested project and user, if one exists. Only users with admin permission for the project may access this resource. Due to security concerns, the JWT and OAuth authentication methods are unsupported. This is to ensure integrations and add-ons are not allowed to change permissions.

Script bitbucket Verified

by hugo697 ยท 10/24/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 375 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * Delete an explicit user permission for a project
7
 * Deletes the project user permission between the requested project and user, if one exists.
8

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

11
Due to security concerns, the JWT and OAuth authentication methods are unsupported.
12
This is to ensure integrations and add-ons are not allowed to change permissions.
13
 */
14
export async function main(
15
  auth: Bitbucket,
16
  project_key: string,
17
  selected_user_id: string,
18
  workspace: string
19
) {
20
  const url = new URL(
21
    `https://api.bitbucket.org/2.0/workspaces/${workspace}/projects/${project_key}/permissions-config/users/${selected_user_id}`
22
  );
23

24
  const response = await fetch(url, {
25
    method: "DELETE",
26
    headers: {
27
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
28
    },
29
    body: undefined,
30
  });
31
  if (!response.ok) {
32
    const text = await response.text();
33
    throw new Error(`${response.status} ${text}`);
34
  }
35
  return await response.text();
36
}
37