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/lib/share/get-collaborators.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
/*
7
Get the collaborators on a given project. Unlisted collaborators are NOT included.
8
*/
9
10
import getPool from "@cocalc/database/pool";
11
import { isUUID } from "./util";
12
import { ProjectCollaborator } from "../api/schema/projects/collaborators/list";
13
14
export default async function getCollaborators(
15
project_id: string,
16
account_id?: string,
17
): Promise<ProjectCollaborator[]> {
18
if (!isUUID(project_id)) {
19
throw Error("project_id must be a uuid");
20
}
21
const pool = getPool("medium");
22
let subQuery = `SELECT jsonb_object_keys(users) AS account_id FROM projects WHERE project_id=$1`;
23
24
const queryParams = [project_id];
25
26
if (account_id) {
27
queryParams.push(account_id);
28
subQuery += ` AND users ? $${queryParams.length}::TEXT`;
29
}
30
31
const result = await pool.query(
32
`SELECT accounts.account_id, accounts.first_name, accounts.last_name FROM accounts, (${subQuery})
33
AS users WHERE accounts.account_id=users.account_id::UUID
34
AND accounts.unlisted IS NOT TRUE`,
35
queryParams,
36
);
37
return result.rows;
38
}
39
40