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/util/db-schema/project-invite-tokens.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
Project invite tokens. If a user presents one of these tokens and it is
8
not expired and the counter hasn't hit the usage_limit, then they get added
9
as a collaborator to the given project.
10
*/
11
12
import { Table } from "./types";
13
14
export interface ProjectInviteToken {
15
token: string;
16
project_id: string;
17
created: Date;
18
expires?: Date;
19
usage_limit?: number;
20
counter?: number;
21
}
22
23
Table({
24
name: "project_invite_tokens",
25
fields: {
26
token: {
27
type: "string",
28
desc: "random unique id (intention: this is a random string)",
29
},
30
project_id: {
31
type: "uuid",
32
desc: "project_id of the project that this token provides access to",
33
},
34
created: {
35
type: "timestamp",
36
desc:
37
"when this token was created (just used for user convenience so no sanity checking)",
38
},
39
expires: {
40
type: "timestamp",
41
desc: "when this token expires",
42
},
43
usage_limit: {
44
type: "number",
45
desc: "how many times this token can be used",
46
},
47
counter: {
48
type: "number",
49
desc: "how many times this token has been used",
50
},
51
},
52
rules: {
53
primary_key: "token",
54
pg_indexes: ["project_id"],
55
user_query: {
56
get: {
57
options: [{ order_by: "-created" }],
58
pg_where: ["projects"],
59
fields: {
60
project_id: null,
61
token: null,
62
expires: null,
63
created: null,
64
usage_limit: null,
65
counter: null,
66
},
67
},
68
set: {
69
fields: {
70
project_id: "project_write",
71
token: null,
72
expires: null,
73
created: null,
74
usage_limit: null,
75
},
76
required_fields: {
77
project_id: true,
78
token: true,
79
},
80
},
81
},
82
},
83
});
84
85