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/get.ts
Views: 687
/* Get projects that the authenticated user is a collaborator on. */12import getProjects from "@cocalc/server/projects/get";3import userIsInGroup from "@cocalc/server/accounts/is-in-group";4import getAccountId from "lib/account/get-account";5import getParams from "lib/api/get-params";6import { apiRoute, apiRouteOperation } from "lib/api";78import {9GetAccountProjectsInputSchema,10GetAccountProjectsOutputSchema,11} from "lib/api/schema/projects/get";1213async function handle(req, res) {14const client_account_id = await getAccountId(req);15try {16if (client_account_id == null) {17throw Error("Must be signed in.");18}1920const { account_id, limit } = getParams(req);2122// User must be an admin to specify account_id field23//24if (account_id && !(await userIsInGroup(client_account_id, "admin"))) {25throw Error(26"The `account_id` field may only be specified by account administrators.",27);28}2930res.json(31await getProjects({32account_id: account_id || client_account_id,33limit,34}),35);36} catch (err) {37res.json({ error: err.message });38}39}4041export default apiRoute({42getProject: apiRouteOperation({43method: "POST",44openApiOperation: {45tags: ["Projects", "Admin"],46},47})48.input({49contentType: "application/json",50body: GetAccountProjectsInputSchema,51})52.outputs([53{54status: 200,55contentType: "application/json",56body: GetAccountProjectsOutputSchema,57},58])59.handler(handle),60});616263