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/database/postgres/pii.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
import { expire_time } from "@cocalc/util/misc";
7
import { PostgreSQL } from "./types";
8
import { get_server_settings } from "./server-settings";
9
10
// this converts what's in the pii_expired setting to a new Date in the future
11
export function pii_retention_to_future<T extends object>(
12
pii_retention: number | false,
13
data?: T & { expire?: Date }
14
): Date | undefined {
15
if (!pii_retention) return;
16
const future: Date = expire_time(pii_retention);
17
if (data != null) {
18
data.expire = future;
19
}
20
return future;
21
}
22
23
// use this to get the "expire" value for storing certain entries in the DB,
24
// which contain personally identifiable information.
25
// if data is set, it's expire field will be set. in any case, it returns the "Date"
26
// in the future.
27
export async function pii_expire<T extends object>(
28
db: PostgreSQL,
29
data?: T & { expire?: Date }
30
): Promise<Date | undefined> {
31
const settings = await get_server_settings(db);
32
return pii_retention_to_future<T>(settings.pii_retention, data);
33
}
34
35