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/restore.ts
Views: 687
/*1API endpoint to restore a deleted a project, which sets the "delete" flag to `false` in2the database.3*/4import { isValidUUID } from "@cocalc/util/misc";5import isCollaborator from "@cocalc/server/projects/is-collaborator";6import userIsInGroup from "@cocalc/server/accounts/is-in-group";7import userQuery from "@cocalc/database/user-query";89import getAccountId from "lib/account/get-account";10import getParams from "lib/api/get-params";11import { apiRoute, apiRouteOperation } from "lib/api";12import { OkStatus } from "lib/api/status";13import {14RestoreProjectInputSchema,15RestoreProjectOutputSchema,16} from "lib/api/schema/projects/restore";1718async function handle(req, res) {19const { project_id } = getParams(req);20const account_id = await getAccountId(req);2122try {23if (!isValidUUID(project_id)) {24throw Error("project_id must be a valid uuid");25}26if (!account_id) {27throw Error("must be signed in");28}2930// If client is not an administrator, they must be a project collaborator in order to31// restore a project.32if (33!(await userIsInGroup(account_id, "admin")) &&34!(await isCollaborator({ account_id, project_id }))35) {36throw Error("must be an owner to restore a project");37}3839await userQuery({40account_id,41query: {42projects: {43project_id,44deleted: false,45},46},47});4849res.json(OkStatus);50} catch (err) {51res.json({ error: err.message });52}53}5455export default apiRoute({56restoreProject: apiRouteOperation({57method: "POST",58openApiOperation: {59tags: ["Projects", "Admin"],60},61})62.input({63contentType: "application/json",64body: RestoreProjectInputSchema,65})66.outputs([67{68status: 200,69contentType: "application/json",70body: RestoreProjectOutputSchema,71},72])73.handler(handle),74});757677