Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/pages/api/v2/projects/update.ts
Views: 687
/*1Set project title, description, etc.2*/34import userIsInGroup from "@cocalc/server/accounts/is-in-group";5import setProject from "@cocalc/server/projects/set-one";67import getAccountId from "lib/account/get-account";8import getParams from "lib/api/get-params";910import { OkStatus } from "lib/api/status";11import { apiRoute, apiRouteOperation } from "lib/api";12import {13UpdateProjectInputSchema,14UpdateProjectOutputSchema,15} from "lib/api/schema/projects/update";1617async function handle(req, res) {18try {19await get(req);20res.json(OkStatus);21} catch (err) {22res.json({ error: `${err.message ? err.message : err}` });23return;24}25}2627async function get(req) {28const client_account_id = await getAccountId(req);2930if (client_account_id == null) {31throw Error("Must be signed in to update project.");32}3334const { account_id, project_id, title, description, name } = getParams(req);3536// If the API client is an admin, they may act on any project on behalf of any account.37// Otherwise, the client may only update projects for which they are listed as38// collaborators.39//40if (account_id && !(await userIsInGroup(client_account_id, "admin"))) {41throw Error(42"The `account_id` field may only be specified by account administrators.",43);44}4546return setProject({47acting_account_id: account_id || client_account_id,48project_id,49project_update: {50title,51description,52name,53},54});55}5657export default apiRoute({58updateProject: apiRouteOperation({59method: "POST",60openApiOperation: {61tags: ["Projects", "Admin"],62},63})64.input({65contentType: "application/json",66body: UpdateProjectInputSchema,67})68.outputs([69{70status: 200,71contentType: "application/json",72body: UpdateProjectOutputSchema,73},74])75.handler(handle),76});777879