type Bitbucket = {
username: string;
password: string;
};
/**
* Update an explicit user permission for a project
* Updates the explicit user permission for a given user and project. The selected
user must be a member of the workspace, and cannot be the workspace owner.
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.
Permissions can be:
* `admin`
* `create-repo`
* `write`
* `read`
*/
export async function main(
auth: Bitbucket,
project_key: string,
selected_user_id: string,
workspace: string,
body: { permission: "read" | "write" | "create-repo" | "admin" }
) {
const url = new URL(
`https://api.bitbucket.org/2.0/workspaces/${workspace}/projects/${project_key}/permissions-config/users/${selected_user_id}`
);
const response = await fetch(url, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 375 days ago
type Bitbucket = {
username: string;
password: string;
};
/**
* Update an explicit user permission for a project
* Updates the explicit user permission for a given user and project. The selected
user must be a member of the workspace, and cannot be the workspace owner.
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.
Permissions can be:
* `admin`
* `create-repo`
* `write`
* `read`
*/
export async function main(
auth: Bitbucket,
project_key: string,
selected_user_id: string,
workspace: string,
body: { permission: "read" | "write" | "create-repo" | "admin" }
) {
const url = new URL(
`https://api.bitbucket.org/2.0/workspaces/${workspace}/projects/${project_key}/permissions-config/users/${selected_user_id}`
);
const response = await fetch(url, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 935 days ago