Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/database/postgres/project/manage-users-owner-only.ts
5700 views
1
/*
2
* This file is part of CoCalc: Copyright © 2025 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
export function sanitizeManageUsersOwnerOnly(
7
value: unknown,
8
): boolean | undefined {
9
if (value === undefined || value === null) {
10
return undefined;
11
}
12
if (typeof value === "object") {
13
// Allow nested shape { manage_users_owner_only: boolean } from callers that wrap input.
14
const candidate = (value as any).manage_users_owner_only;
15
if (candidate !== undefined) {
16
return sanitizeManageUsersOwnerOnly(candidate);
17
}
18
// Allow Immutable.js style get("manage_users_owner_only")
19
const getter = (value as any).get;
20
if (typeof getter === "function") {
21
const maybe = getter.call(value, "manage_users_owner_only");
22
if (maybe !== undefined) {
23
return sanitizeManageUsersOwnerOnly(maybe);
24
}
25
}
26
}
27
if (typeof value !== "boolean") {
28
throw Error("manage_users_owner_only must be a boolean");
29
}
30
return value;
31
}
32
33