CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/api/v2/licenses/get-projects-with-license.ts
Views: 687
1
/*
2
Get all projects that have a given license applied to them. Signed in user
3
must be a manager of the given license so they are allowed access to this data.
4
5
See docs in @cocalc/server/licenses/get-projects-with-license.ts
6
7
Returns [Project1, Project2, ...] on success or {error:'a message'} on failure.
8
For the fields in the projects, see @cocalc/server/licenses/get-projects.ts
9
*/
10
11
import getProjectsWithLicense, {
12
Project,
13
} from "@cocalc/server/licenses/get-projects-with-license";
14
import { isManager } from "@cocalc/server/licenses/get-license";
15
import getAccountId from "lib/account/get-account";
16
import getParams from "lib/api/get-params";
17
import { isValidUUID } from "@cocalc/util/misc";
18
19
export default async function handle(req, res) {
20
try {
21
res.json(await get(req));
22
} catch (err) {
23
res.json({ error: `${err.message}` });
24
return;
25
}
26
}
27
28
async function get(req): Promise<Project[]> {
29
const account_id = await getAccountId(req);
30
if (account_id == null) {
31
throw Error("must be signed in as a manager of the license");
32
}
33
const { license_id } = getParams(req);
34
if (!isValidUUID(license_id)) {
35
throw Error("license_id must be a valid uuid");
36
}
37
if (!(await isManager(license_id, account_id))) {
38
throw Error("signed in user must be a manager of the license");
39
}
40
return await getProjectsWithLicense(license_id);
41
}
42
43