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/database/postgres/public-paths.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
/* Queries related to public_paths.
7
8
Probably more need to be rewritten and moved here...
9
*/
10
11
import { callback2 } from "@cocalc/util/async-utils";
12
import { PostgreSQL } from "./types";
13
import { query } from "./query";
14
import { is_valid_uuid_string } from "@cocalc/util/misc";
15
import { PublicPath } from "@cocalc/util/db-schema/public-paths";
16
17
/* Unlist all public paths on all projects that the
18
given account is a collaborator on. If is_owner is
19
true (the default), only projects the account_id
20
is the owner of are considered.
21
22
This is not written to be optimally fast since it should
23
barely ever get used.
24
*/
25
export async function unlist_all_public_paths(
26
db: PostgreSQL,
27
account_id: string,
28
is_owner: boolean = true
29
): Promise<void> {
30
const project_ids = await callback2(db.get_project_ids_with_user, {
31
account_id,
32
is_owner,
33
});
34
await query({
35
db,
36
query: "UPDATE public_paths SET unlisted=true",
37
where: { "project_id = ANY($)": project_ids },
38
});
39
}
40
41
export async function get_all_public_paths(
42
db: PostgreSQL,
43
account_id: string
44
): Promise<PublicPath[]> {
45
if (!is_valid_uuid_string(account_id)) {
46
throw Error(`account_id="${account_id}" must be a valid uuid`);
47
}
48
return await query({
49
db,
50
query: `SELECT pp.id, pp.project_id, pp.path, pp.description, pp.disabled, pp.authenticated, pp.unlisted, pp.license, pp.last_edited, pp.created, pp.last_saved, pp.counter, pp.compute_image
51
FROM public_paths AS pp, projects
52
WHERE pp.project_id = projects.project_id
53
AND projects.users ? '${account_id}'
54
AND projects.last_active ? '${account_id}'
55
ORDER BY pp.last_edited DESC`,
56
});
57
}
58
59