Path: blob/master/src/packages/next/lib/share/get-collaborators.ts
1450 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6Get the collaborators on a given project. Unlisted collaborators are NOT included.7*/89import getPool from "@cocalc/database/pool";10import { isUUID } from "./util";11import { ProjectCollaborator } from "../api/schema/projects/collaborators/list";1213export default async function getCollaborators(14project_id: string,15account_id?: string,16): Promise<ProjectCollaborator[]> {17if (!isUUID(project_id)) {18throw Error("project_id must be a uuid");19}20const pool = getPool("medium");21let subQuery = `SELECT jsonb_object_keys(users) AS account_id FROM projects WHERE project_id=$1`;2223const queryParams = [project_id];2425if (account_id) {26queryParams.push(account_id);27subQuery += ` AND users ? $${queryParams.length}::TEXT`;28}2930const result = await pool.query(31`SELECT accounts.account_id, accounts.first_name, accounts.last_name FROM accounts, (${subQuery})32AS users WHERE accounts.account_id=users.account_id::UUID33AND accounts.unlisted IS NOT TRUE`,34queryParams,35);36return result.rows;37}383940