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/database/postgres/public-paths.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/* Queries related to public_paths.67Probably more need to be rewritten and moved here...8*/910import { callback2 } from "@cocalc/util/async-utils";11import { PostgreSQL } from "./types";12import { query } from "./query";13import { is_valid_uuid_string } from "@cocalc/util/misc";14import { PublicPath } from "@cocalc/util/db-schema/public-paths";1516/* Unlist all public paths on all projects that the17given account is a collaborator on. If is_owner is18true (the default), only projects the account_id19is the owner of are considered.2021This is not written to be optimally fast since it should22barely ever get used.23*/24export async function unlist_all_public_paths(25db: PostgreSQL,26account_id: string,27is_owner: boolean = true28): Promise<void> {29const project_ids = await callback2(db.get_project_ids_with_user, {30account_id,31is_owner,32});33await query({34db,35query: "UPDATE public_paths SET unlisted=true",36where: { "project_id = ANY($)": project_ids },37});38}3940export async function get_all_public_paths(41db: PostgreSQL,42account_id: string43): Promise<PublicPath[]> {44if (!is_valid_uuid_string(account_id)) {45throw Error(`account_id="${account_id}" must be a valid uuid`);46}47return await query({48db,49query: `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_image50FROM public_paths AS pp, projects51WHERE pp.project_id = projects.project_id52AND projects.users ? '${account_id}'53AND projects.last_active ? '${account_id}'54ORDER BY pp.last_edited DESC`,55});56}575859