|
| 1 | +/* |
| 2 | +API endpoint to remove a user from an existing project. |
| 3 | +
|
| 4 | +Permissions checks are performed by the underlying API call and are NOT |
| 5 | +executed at this stage. |
| 6 | +
|
| 7 | +*/ |
| 8 | +import { db } from "@cocalc/database"; |
| 9 | +import { remove_collaborators_from_projects } from "@cocalc/server/projects/collab"; |
| 10 | + |
| 11 | +import getAccountId from "lib/account/get-account"; |
| 12 | +import getParams from "lib/api/get-params"; |
| 13 | +import { apiRoute, apiRouteOperation } from "lib/api"; |
| 14 | +import { OkStatus } from "lib/api/status"; |
| 15 | +import { |
| 16 | + RemoveProjectCollaboratorInputSchema, |
| 17 | + RemoveProjectCollaboratorOutputSchema, |
| 18 | +} from "lib/api/schema/projects/collaborators/remove"; |
| 19 | + |
| 20 | +async function handle(req, res) { |
| 21 | + const { project_id, account_id } = getParams(req); |
| 22 | + const client_account_id = await getAccountId(req); |
| 23 | + |
| 24 | + try { |
| 25 | + if (!client_account_id) { |
| 26 | + throw Error("must be signed in"); |
| 27 | + } |
| 28 | + |
| 29 | + await remove_collaborators_from_projects( |
| 30 | + db(), |
| 31 | + client_account_id, |
| 32 | + [account_id], |
| 33 | + [project_id], |
| 34 | + ); |
| 35 | + |
| 36 | + res.json(OkStatus); |
| 37 | + } catch (err) { |
| 38 | + res.json({ error: err.message }); |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +export default apiRoute({ |
| 43 | + removeProjectCollaborator: apiRouteOperation({ |
| 44 | + method: "POST", |
| 45 | + openApiOperation: { |
| 46 | + tags: ["Projects", "Admin"], |
| 47 | + }, |
| 48 | + }) |
| 49 | + .input({ |
| 50 | + contentType: "application/json", |
| 51 | + body: RemoveProjectCollaboratorInputSchema, |
| 52 | + }) |
| 53 | + .outputs([ |
| 54 | + { |
| 55 | + status: 200, |
| 56 | + contentType: "application/json", |
| 57 | + body: RemoveProjectCollaboratorOutputSchema, |
| 58 | + }, |
| 59 | + ]) |
| 60 | + .handler(handle), |
| 61 | +}); |
0 commit comments