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/lib/names/project.ts
Views: 687
/*1Get basic information about a user or organization2from the database. This should be enough to render3a nice "homepage" for that user or organization.45*/67import getPool from "@cocalc/database/pool";8import getOwner from "./owner";9import getProxyProjectId from "lib/share/proxy/project";1011// Throws an exception if there is no project with this name.12// TODO: take into account redirects for when name is changed.13export default async function getProjectId(14owner: string,15project: string16): Promise<string> {17if (owner == "github") {18return await getProxyProjectId();19}2021const { owner_id } = await getOwner(owner);22const pool = getPool("long"); // map from owner/project --> project_id unlikely to change and when it does, stale data is ok.2324// NOTE: it's not enough that owner is a collab on the project -- they have to be the owner.25// We do users ? $2 also, since it's fast/indexed, then dig in to the JSON...26// Note that we have put owner_id in the query string explicitly (as far as I know),27// though it is NOT user supplied so that's safe.28const result = await pool.query(29`SELECT project_id FROM projects WHERE LOWER(name)=$1 AND users ? $2 AND users#>>'{${owner_id},group}' = 'owner'`,30[project.toLowerCase(), owner_id]31);32if (result.rows.length > 0) {33return result.rows[0].project_id;34}35throw Error(`no project ${owner}/${project}`);36}373839