Fix following upstream plugin changes

This commit is contained in:
Cooldude2606 committed 2026-09-26 21:34:17 +01:00
1 parent 06fc1086e3
commit 311506372b
3 files changed
+18 -17

No files matched your search

+3 -3
View File
@@ -5,7 +5,7 @@ import * as lib from "@clusterio/lib";
import { ControlContext, SectionHeader, useAccount, notifyErrorHandler } from "@clusterio/web_ui";
import { RoleColor, RoleMetaRecord, RoleMetaUpdateRequest } from "../../messages.js";
import type { WebPlugin } from "..";
import { useRoles } from "..";
const MS_PER_HOUR = 3600000;
@@ -25,13 +25,13 @@ type RoleFormValues = {
* The name, description and permissions of a role are owned by clusterio, this
* only covers the properties which only mean something in game.
*/
export default function RoleProperties(props: { plugin: WebPlugin, role?: lib.Role }) {
export default function RoleProperties(props: { role?: lib.Role }) {
const control = useContext(ControlContext);
const account = useAccount();
const [roles] = useRoles();
const [form] = Form.useForm<RoleFormValues>();
const [applying, setApplying] = useState(false);
const [roles] = props.plugin.useRoles();
const record = props.role ? roles.get(props.role.id) : undefined;
const meta = record?.meta;
const canUpdate = account.hasPermission("core.role.update");
+12 -14
View File
@@ -1,24 +1,22 @@
import React, { useCallback, useSyncExternalStore } from "react";
import { BaseWebPlugin } from "@clusterio/web_ui";
import { WebPluginContext } from "@clusterio/web_ui";
import * as lib from "@clusterio/lib";
import * as messages from "../messages.js";
import RoleProperties from "./components/RoleProperties";
export class WebPlugin extends BaseWebPlugin {
roles = new lib.MapSubscriber(messages.RoleUpdatedEvent, this.control);
let roles: lib.MapSubscriber<messages.RoleUpdatedEvent> | undefined;
async init() {
// The core components pass a role and the plugin, which componentExtra
// does not carry in its type
this.componentExtra = {
RoleViewPage: RoleProperties as React.ComponentType,
};
}
export function useRoles() {
const subscribe = useCallback((cb: () => void) => roles!.subscribe(cb), []);
return useSyncExternalStore(subscribe, () => roles!.getSnapshot());
}
useRoles() {
const subscribe = useCallback((cb: () => void) => this.roles.subscribe(cb), []);
return useSyncExternalStore(subscribe, () => this.roles.getSnapshot());
}
export default function registerPlugin(context: WebPluginContext) {
context.control.hooks.extensionComponents.attach("exp_roles", () => ({
RoleViewPage: RoleProperties,
}));
roles = new lib.MapSubscriber(messages.RoleUpdatedEvent, context.control);
}
+3
View File
@@ -19,6 +19,8 @@ export class ControllerPlugin extends BaseControllerPlugin {
* permissions, groups which already exist by name are reset to the seed.
*/
async handleSeedRequest() {
throw new lib.RequestError("Seeding is temporarily disabled, please contact the server administrator to seed the roles and groups");
/*
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) {
@@ -52,6 +54,7 @@ export class ControllerPlugin extends BaseControllerPlugin {
this.seedRoleMappings(groupsPlugin, roleIds, groupIds);
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. */