Skip to content

Commit ecc4be4

Browse files
committed
server/projects/strict_collaborator_management: fix invalidated use of cached values and add test
1 parent 1e10ad7 commit ecc4be4

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/packages/server/projects/manage-users-owner-only.test.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
* License: MS-RSL – see LICENSE.md for details
44
*/
55

6-
import { callback2 } from "@cocalc/util/async-utils";
7-
import { uuid } from "@cocalc/util/misc";
86
import { db } from "@cocalc/database";
97
import getPool, { initEphemeralDatabase } from "@cocalc/database/pool";
8+
import { resetServerSettingsCache } from "@cocalc/database/settings/server-settings";
9+
import userQuery from "@cocalc/database/user-query";
1010
import createAccount from "@cocalc/server/accounts/create-account";
11-
import createProject from "@cocalc/server/projects/create";
1211
import {
1312
addCollaborator,
1413
changeUserType,
1514
removeCollaborator,
1615
} from "@cocalc/server/projects/collaborators";
17-
import { resetServerSettingsCache } from "@cocalc/database/settings/server-settings";
16+
import createProject from "@cocalc/server/projects/create";
17+
import { callback2 } from "@cocalc/util/async-utils";
18+
import { uuid } from "@cocalc/util/misc";
1819

1920
async function setSiteStrictCollab(value: "yes" | "no") {
2021
await callback2(db().set_server_setting, {
@@ -289,6 +290,22 @@ describe("strict collaborator management site setting", () => {
289290
);
290291
});
291292

293+
test("owner cannot disable manage_users_owner_only when site enforcement is on", async () => {
294+
await expect(
295+
userQuery({
296+
account_id: ownerId,
297+
query: {
298+
projects: {
299+
project_id: projectId,
300+
manage_users_owner_only: false,
301+
},
302+
},
303+
}),
304+
).rejects.toMatch(
305+
"Collaborator management is enforced by the site administrator and cannot be disabled.",
306+
);
307+
});
308+
292309
test("owner can remove non-owner collaborators when site enforcement is on", async () => {
293310
await expect(
294311
removeCollaborator({

src/packages/util/db-schema/projects.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import {
1111
ExecuteCodeOptionsAsyncGet,
1212
ExecuteCodeOutput,
1313
} from "@cocalc/util/types/execute-code";
14-
import { callback2 } from "@cocalc/util/async-utils";
1514
import { DEFAULT_QUOTAS } from "@cocalc/util/upgrade-spec";
1615
import { isUserGroup } from "@cocalc/util/project-ownership";
1716

1817
import { NOTES } from "./crm";
1918
import { FALLBACK_COMPUTE_IMAGE } from "./defaults";
2019
import { SCHEMA as schema } from "./index";
20+
import { callback2 } from "@cocalc/util/async-utils";
2121
import { Table } from "./types";
2222

2323
export const MAX_FILENAME_SEARCH_RESULTS = 100;
@@ -141,9 +141,8 @@ Table({
141141
}
142142

143143
const siteSettings =
144-
(await callback2(db.get_site_settings, {})) ?? {};
145-
const siteEnforced =
146-
siteSettings.strict_collaborator_management === true;
144+
(await callback2(db.get_server_settings_cached, {})) ?? {};
145+
const siteEnforced = !!siteSettings.strict_collaborator_management;
147146
if (siteEnforced && obj.manage_users_owner_only !== true) {
148147
throw Error(
149148
"Collaborator management is enforced by the site administrator and cannot be disabled.",

0 commit comments

Comments
 (0)