Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

The main Chief gets every new department from the start

milind-soniecbabb2f37c2
diff --git a/server/department-grants.ts b/server/department-grants.ts
index fb0ccb57cc..3bce0cae1a 100644
--- a/server/department-grants.ts
+++ b/server/department-grants.ts
@@ -27,7 +27,7 @@ export function grantNewDepartments(store: Pick<Store, "sections" | "bots" | "bo
for (const id of chiefs) {
const chief = store.bot(id);
if (!chief || !inChargeOfEvery(chief, before)) continue;
- const previous = [...chief.managedSections!];
+ const previous = [...(chief.managedSections ?? [])];
const managedSections = [...new Set([...previous, ...added])];
if (managedSections.length === previous.length || managedSections.length > MAX_MANAGED) continue;
try {
diff --git a/server/peer-roster.test.ts b/server/peer-roster.test.ts
index 90921bc3d9..bad806cfd7 100644
--- a/server/peer-roster.test.ts
+++ b/server/peer-roster.test.ts
@@ -103,15 +103,15 @@ describe("Chief authority over additional departments", () => {
expect(hasTeamAuthority({ ...chief, managedSections: [null] as unknown as string[] }, "Personal")).toBe(false);
expect(hasTeamAuthority({ ...chief, managedSections: [""] }, undefined)).toBe(true);
});
- it("counts a Chief in charge of every department only when the owner ticked each one, General included", () => {
+ it("counts a Chief in charge of every department when it covers each one, General included", () => {
const everywhere = { ...self, chiefOfStaff: true, managedSections: ["", "Personal", "Finance"] };
expect(inChargeOfEvery(everywhere, ["Work", "Personal", "Finance"])).toBe(true);
expect(inChargeOfEvery(everywhere, ["Work", "Personal", "Finance", "Legal"])).toBe(false);
expect(inChargeOfEvery({ ...everywhere, managedSections: ["Personal", "Finance"] }, ["Work", "Personal", "Finance"])).toBe(false);
expect(inChargeOfEvery({ ...everywhere, chiefOfStaff: false }, ["Work", "Personal", "Finance"])).toBe(false);
expect(inChargeOfEvery({ ...everywhere, managedSections: ["", "Personal", 7 as unknown as string] }, ["Work", "Personal", "Finance"])).toBe(false);
- // With nothing to tick yet, the owner has not put it in charge of anything beyond its own department.
- expect(inChargeOfEvery({ chiefOfStaff: true }, [])).toBe(false);
+ expect(inChargeOfEvery({ chiefOfStaff: true }, [])).toBe(true);
+ expect(inChargeOfEvery({ chiefOfStaff: true, section: "Work" }, ["Work"])).toBe(false);
// A member's own Chief on a Team Cloud answers for its person's bots, never for departments.
expect(inChargeOfEvery({ ...everywhere, createdBy: "[email protected]" }, ["Work", "Personal", "Finance"])).toBe(false);
});
diff --git a/server/peer-roster.ts b/server/peer-roster.ts
index d7a6948649..e4771e28b8 100644
--- a/server/peer-roster.ts
+++ b/server/peer-roster.ts
@@ -43,7 +43,7 @@ export function inChargeOfEvery(
bot: Pick<RosterMember, "section" | "chiefOfStaff" | "managedSections" | "createdBy" | "reportsTo" | "defaultBot">,
departments: readonly string[],
): boolean {
- if (bot.chiefOfStaff !== true || botOwner(bot) || !Array.isArray(bot.managedSections) || !bot.managedSections.length) return false;
+ if (bot.chiefOfStaff !== true || botOwner(bot)) return false;
return ["", ...departments].every(name => hasTeamAuthority(bot, name));
}