mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-21 07:33:12 +09:00
Merge pull request #481 from bbassie/fix/upstream-plugin-changes
Restore seeding without controller.plugins
This commit is contained in:
1 parent
862fe49b60
commit
53e07aa761
4 files changed
+28
-16
No files matched your search
@@ -1,15 +1,23 @@
|
|||||||
import { BaseControllerPlugin } from "@clusterio/controller";
|
import { BaseControllerPlugin, type Controller } from "@clusterio/controller";
|
||||||
import * as lib from "@clusterio/lib";
|
import * as lib from "@clusterio/lib";
|
||||||
import * as messages from "./messages.js";
|
import * as messages from "./messages.js";
|
||||||
import * as path from "node:path";
|
import * as path from "node:path";
|
||||||
|
|
||||||
|
const loaded = new WeakMap<Controller, ControllerPlugin>();
|
||||||
|
|
||||||
export class ControllerPlugin extends BaseControllerPlugin {
|
export class ControllerPlugin extends BaseControllerPlugin {
|
||||||
groups!: lib.SubscribableDatastore<messages.GroupRecord>;
|
groups!: lib.SubscribableDatastore<messages.GroupRecord>;
|
||||||
roleMappings!: lib.SubscribableDatastore<messages.RoleMappingRecord>;
|
roleMappings!: lib.SubscribableDatastore<messages.RoleMappingRecord>;
|
||||||
manualAssignments!: lib.SubscribableDatastore<messages.AssignmentRecord>;
|
manualAssignments!: lib.SubscribableDatastore<messages.AssignmentRecord>;
|
||||||
resolvedAssignments!: lib.SubscribableDatastore<messages.AssignmentRecord>;
|
resolvedAssignments!: lib.SubscribableDatastore<messages.AssignmentRecord>;
|
||||||
|
|
||||||
|
/** The plugin loaded on a controller, for the exp_scenario seed. */
|
||||||
|
static get(controller: Controller) {
|
||||||
|
return loaded.get(controller);
|
||||||
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
|
loaded.set(this.controller, this);
|
||||||
const databaseDirectory = this.controller.config.get("controller.database_directory");
|
const databaseDirectory = this.controller.config.get("controller.database_directory");
|
||||||
|
|
||||||
this.groups = new lib.SubscribableDatastore(
|
this.groups = new lib.SubscribableDatastore(
|
||||||
|
|||||||
@@ -1,12 +1,20 @@
|
|||||||
import { BaseControllerPlugin, InstanceRecord } from "@clusterio/controller";
|
import { BaseControllerPlugin, InstanceRecord, type Controller } from "@clusterio/controller";
|
||||||
import * as lib from "@clusterio/lib";
|
import * as lib from "@clusterio/lib";
|
||||||
import * as messages from "./messages.js";
|
import * as messages from "./messages.js";
|
||||||
import * as path from "node:path";
|
import * as path from "node:path";
|
||||||
|
|
||||||
|
const loaded = new WeakMap<Controller, ControllerPlugin>();
|
||||||
|
|
||||||
export class ControllerPlugin extends BaseControllerPlugin {
|
export class ControllerPlugin extends BaseControllerPlugin {
|
||||||
roleMeta!: lib.SubscribableDatastore<messages.RoleMetaRecord>;
|
roleMeta!: lib.SubscribableDatastore<messages.RoleMetaRecord>;
|
||||||
|
|
||||||
|
/** The plugin loaded on a controller, for the exp_scenario seed. */
|
||||||
|
static get(controller: Controller) {
|
||||||
|
return loaded.get(controller);
|
||||||
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
|
loaded.set(this.controller, this);
|
||||||
const databaseDirectory = this.controller.config.get("controller.database_directory");
|
const databaseDirectory = this.controller.config.get("controller.database_directory");
|
||||||
|
|
||||||
this.roleMeta = new lib.SubscribableDatastore(
|
this.roleMeta = new lib.SubscribableDatastore(
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import * as lib from "@clusterio/lib";
|
import * as lib from "@clusterio/lib";
|
||||||
import { BaseControllerPlugin } from "@clusterio/controller";
|
import { BaseControllerPlugin } from "@clusterio/controller";
|
||||||
import { RoleMetaRecord, type ControllerPlugin as RolesPlugin } from "@expcluster/roles";
|
import { RoleMetaRecord } from "@expcluster/roles";
|
||||||
import {
|
import { GroupRecord, GroupPermissions, RoleMappingRecord } from "@expcluster/permission-groups";
|
||||||
GroupRecord, GroupPermissions, RoleMappingRecord, type ControllerPlugin as GroupsPlugin,
|
import { ControllerPlugin as RolesPlugin } from "@expcluster/roles/dist/node/controller.js";
|
||||||
} from "@expcluster/permission-groups";
|
import { ControllerPlugin as GroupsPlugin } from "@expcluster/permission-groups/dist/node/controller.js";
|
||||||
import * as messages from "./messages.js";
|
import * as messages from "./messages.js";
|
||||||
import { SeedRole, SeedGroup, seedRoles, seedGroups, flattenSeedPermissions } from "./seed.js";
|
import { SeedRole, SeedGroup, seedRoles, seedGroups, flattenSeedPermissions } from "./seed.js";
|
||||||
|
|
||||||
@@ -19,10 +19,8 @@ export class ControllerPlugin extends BaseControllerPlugin {
|
|||||||
* permissions, groups which already exist by name are reset to the seed.
|
* permissions, groups which already exist by name are reset to the seed.
|
||||||
*/
|
*/
|
||||||
async handleSeedRequest() {
|
async handleSeedRequest() {
|
||||||
throw new lib.RequestError("Seeding is temporarily disabled, please contact the server administrator to seed the roles and groups");
|
const rolesPlugin = RolesPlugin.get(this.controller);
|
||||||
/*
|
const groupsPlugin = GroupsPlugin.get(this.controller);
|
||||||
const rolesPlugin = this.controller.plugins.get("exp_roles") as RolesPlugin | undefined;
|
|
||||||
const groupsPlugin = this.controller.plugins.get("exp_groups") as GroupsPlugin | undefined;
|
|
||||||
if (!rolesPlugin || !groupsPlugin) {
|
if (!rolesPlugin || !groupsPlugin) {
|
||||||
throw new lib.RequestError("Seeding requires the exp_roles and exp_groups plugins");
|
throw new lib.RequestError("Seeding requires the exp_roles and exp_groups plugins");
|
||||||
}
|
}
|
||||||
@@ -54,7 +52,6 @@ export class ControllerPlugin extends BaseControllerPlugin {
|
|||||||
|
|
||||||
this.seedRoleMappings(groupsPlugin, roleIds, groupIds);
|
this.seedRoleMappings(groupsPlugin, roleIds, groupIds);
|
||||||
this.logger.info(`Seeded ${roleIds.size} roles and ${groupIds.size} permission groups`);
|
this.logger.info(`Seeded ${roleIds.size} roles and ${groupIds.size} permission groups`);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Find or create the clusterio role for a seed role, returns undefined if it has no role to use. */
|
/** Find or create the clusterio role for a seed role, returns undefined if it has no role to use. */
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ async function startPlugin(t2, { withPlugins = true } = {}) {
|
|||||||
for (const [name, Plugin] of [["exp_roles", RolesPlugin], ["exp_groups", GroupsPlugin]]) {
|
for (const [name, Plugin] of [["exp_roles", RolesPlugin], ["exp_groups", GroupsPlugin]]) {
|
||||||
const plugin = new Plugin({ name }, controller, undefined, logger);
|
const plugin = new Plugin({ name }, controller, undefined, logger);
|
||||||
await plugin.init();
|
await plugin.init();
|
||||||
controller.plugins.set(name, plugin);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +64,7 @@ t.test("class ControllerPlugin", t2 => {
|
|||||||
|
|
||||||
t2.test(".handleSeedRequest() creates the roles and reuses them by name", async t3 => {
|
t2.test(".handleSeedRequest() creates the roles and reuses them by name", async t3 => {
|
||||||
const { plugin, controller } = await startPlugin(t3);
|
const { plugin, controller } = await startPlugin(t3);
|
||||||
const rolesPlugin = controller.plugins.get("exp_roles");
|
const rolesPlugin = RolesPlugin.get(controller);
|
||||||
|
|
||||||
await plugin.handleSeedRequest();
|
await plugin.handleSeedRequest();
|
||||||
t3.strictSame(controller.roles.size, seedRoles.length, "every seed role exists");
|
t3.strictSame(controller.roles.size, seedRoles.length, "every seed role exists");
|
||||||
@@ -80,7 +79,7 @@ t.test("class ControllerPlugin", t2 => {
|
|||||||
|
|
||||||
t2.test(".handleSeedRequest() creates the groups and resets them by name", async t3 => {
|
t2.test(".handleSeedRequest() creates the groups and resets them by name", async t3 => {
|
||||||
const { plugin, controller } = await startPlugin(t3);
|
const { plugin, controller } = await startPlugin(t3);
|
||||||
const groupsPlugin = controller.plugins.get("exp_groups");
|
const groupsPlugin = GroupsPlugin.get(controller);
|
||||||
|
|
||||||
await plugin.handleSeedRequest();
|
await plugin.handleSeedRequest();
|
||||||
t3.strictSame(groupsPlugin.groups.size, seedGroups.length, "every seed group exists");
|
t3.strictSame(groupsPlugin.groups.size, seedGroups.length, "every seed group exists");
|
||||||
@@ -101,7 +100,7 @@ t.test("class ControllerPlugin", t2 => {
|
|||||||
|
|
||||||
t2.test(".handleSeedRequest() maps each role onto its group by rank", async t3 => {
|
t2.test(".handleSeedRequest() maps each role onto its group by rank", async t3 => {
|
||||||
const { plugin, controller } = await startPlugin(t3);
|
const { plugin, controller } = await startPlugin(t3);
|
||||||
const groupsPlugin = controller.plugins.get("exp_groups");
|
const groupsPlugin = GroupsPlugin.get(controller);
|
||||||
|
|
||||||
await plugin.handleSeedRequest();
|
await plugin.handleSeedRequest();
|
||||||
const mapped = seedRoles.filter(role => role.group !== undefined);
|
const mapped = seedRoles.filter(role => role.group !== undefined);
|
||||||
@@ -123,7 +122,7 @@ t.test("class ControllerPlugin", t2 => {
|
|||||||
|
|
||||||
t2.test(".handleSeedRequest() reuses mappings and keeps clear of other mappings", async t3 => {
|
t2.test(".handleSeedRequest() reuses mappings and keeps clear of other mappings", async t3 => {
|
||||||
const { plugin, controller } = await startPlugin(t3);
|
const { plugin, controller } = await startPlugin(t3);
|
||||||
const groupsPlugin = controller.plugins.get("exp_groups");
|
const groupsPlugin = GroupsPlugin.get(controller);
|
||||||
|
|
||||||
groupsPlugin.roleMappings.set(new RoleMappingRecord(99, new Set([0, 1]), 5, 2, true));
|
groupsPlugin.roleMappings.set(new RoleMappingRecord(99, new Set([0, 1]), 5, 2, true));
|
||||||
await plugin.handleSeedRequest();
|
await plugin.handleSeedRequest();
|
||||||
|
|||||||
Reference in new issue
Block a user