mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-22 07:33:12 +09:00
Fix following upstream plugin changes
This commit is contained in:
3 files changed
+18
-17
No files matched your search
@@ -5,7 +5,7 @@ import * as lib from "@clusterio/lib";
|
|||||||
import { ControlContext, SectionHeader, useAccount, notifyErrorHandler } from "@clusterio/web_ui";
|
import { ControlContext, SectionHeader, useAccount, notifyErrorHandler } from "@clusterio/web_ui";
|
||||||
|
|
||||||
import { RoleColor, RoleMetaRecord, RoleMetaUpdateRequest } from "../../messages.js";
|
import { RoleColor, RoleMetaRecord, RoleMetaUpdateRequest } from "../../messages.js";
|
||||||
import type { WebPlugin } from "..";
|
import { useRoles } from "..";
|
||||||
|
|
||||||
const MS_PER_HOUR = 3600000;
|
const MS_PER_HOUR = 3600000;
|
||||||
|
|
||||||
@@ -25,13 +25,13 @@ type RoleFormValues = {
|
|||||||
* The name, description and permissions of a role are owned by clusterio, this
|
* The name, description and permissions of a role are owned by clusterio, this
|
||||||
* only covers the properties which only mean something in game.
|
* 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 control = useContext(ControlContext);
|
||||||
const account = useAccount();
|
const account = useAccount();
|
||||||
|
const [roles] = useRoles();
|
||||||
const [form] = Form.useForm<RoleFormValues>();
|
const [form] = Form.useForm<RoleFormValues>();
|
||||||
const [applying, setApplying] = useState(false);
|
const [applying, setApplying] = useState(false);
|
||||||
|
|
||||||
const [roles] = props.plugin.useRoles();
|
|
||||||
const record = props.role ? roles.get(props.role.id) : undefined;
|
const record = props.role ? roles.get(props.role.id) : undefined;
|
||||||
const meta = record?.meta;
|
const meta = record?.meta;
|
||||||
const canUpdate = account.hasPermission("core.role.update");
|
const canUpdate = account.hasPermission("core.role.update");
|
||||||
|
|||||||
+12
-14
@@ -1,24 +1,22 @@
|
|||||||
import React, { useCallback, useSyncExternalStore } from "react";
|
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 lib from "@clusterio/lib";
|
||||||
import * as messages from "../messages.js";
|
import * as messages from "../messages.js";
|
||||||
|
|
||||||
import RoleProperties from "./components/RoleProperties";
|
import RoleProperties from "./components/RoleProperties";
|
||||||
|
|
||||||
export class WebPlugin extends BaseWebPlugin {
|
let roles: lib.MapSubscriber<messages.RoleUpdatedEvent> | undefined;
|
||||||
roles = new lib.MapSubscriber(messages.RoleUpdatedEvent, this.control);
|
|
||||||
|
|
||||||
async init() {
|
export function useRoles() {
|
||||||
// The core components pass a role and the plugin, which componentExtra
|
const subscribe = useCallback((cb: () => void) => roles!.subscribe(cb), []);
|
||||||
// does not carry in its type
|
return useSyncExternalStore(subscribe, () => roles!.getSnapshot());
|
||||||
this.componentExtra = {
|
}
|
||||||
RoleViewPage: RoleProperties as React.ComponentType,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
useRoles() {
|
export default function registerPlugin(context: WebPluginContext) {
|
||||||
const subscribe = useCallback((cb: () => void) => this.roles.subscribe(cb), []);
|
context.control.hooks.extensionComponents.attach("exp_roles", () => ({
|
||||||
return useSyncExternalStore(subscribe, () => this.roles.getSnapshot());
|
RoleViewPage: RoleProperties,
|
||||||
}
|
}));
|
||||||
|
|
||||||
|
roles = new lib.MapSubscriber(messages.RoleUpdatedEvent, context.control);
|
||||||
}
|
}
|
||||||
@@ -19,6 +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 = this.controller.plugins.get("exp_roles") as RolesPlugin | undefined;
|
const rolesPlugin = this.controller.plugins.get("exp_roles") as RolesPlugin | undefined;
|
||||||
const groupsPlugin = this.controller.plugins.get("exp_groups") as GroupsPlugin | undefined;
|
const groupsPlugin = this.controller.plugins.get("exp_groups") as GroupsPlugin | undefined;
|
||||||
if (!rolesPlugin || !groupsPlugin) {
|
if (!rolesPlugin || !groupsPlugin) {
|
||||||
@@ -52,6 +54,7 @@ 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. */
|
||||||
|
|||||||
Reference in new issue
Block a user