mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 00:13:12 +09:00
Merge branch 'master' into feature/update-all
This commit is contained in:
275 files changed
+2394
-2073
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import type React from "react";
|
||||
import type { AccountRole, FieldDefinition, Logger, PluginWebpackEnvInfo } from "@clusterio/lib";
|
||||
import type { AccountRole, FieldDefinition, Logger, PermissionName, PluginWebpackEnvInfo } from "@clusterio/lib";
|
||||
import type { Control } from "./util/websocket";
|
||||
|
||||
/**
|
||||
@@ -37,11 +37,11 @@ export type UserAccount = {
|
||||
/** Roles of the corrently logged in account. */
|
||||
roles: AccountRole[];
|
||||
/** Check if the currently logged in account has the given permission. */
|
||||
hasPermission: (permission: string) => boolean | null;
|
||||
hasPermission: (permission: PermissionName) => boolean | null;
|
||||
/** Check if the currently logged in account has any of the given permissions. */
|
||||
hasAnyPermission: (...permissions: string[]) => boolean | null;
|
||||
hasAnyPermission: (...permissions: PermissionName[]) => boolean | null;
|
||||
/** Check if the currently logged in account has all of given permissions. */
|
||||
hasAllPermission: (...permissions: string[]) => boolean | null;
|
||||
hasAllPermission: (...permissions: PermissionName[]) => boolean | null;
|
||||
/** Logs out of the web interface. */
|
||||
logOut: () => void;
|
||||
};
|
||||
@@ -75,7 +75,7 @@ export interface PluginPage {
|
||||
/**
|
||||
* Permission to access page. function are expected to throw an error if access is deny.
|
||||
*/
|
||||
permission?: string | ((account: UserAccount) => (boolean|null));
|
||||
permission?: PermissionName | ((account: UserAccount) => (boolean|null));
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,6 +49,9 @@ async function loadPluginInfos(): Promise<[lib.PluginWebpackEnvInfo[], string]>
|
||||
logger.error(`Failed to load plugin ${meta.name}: ${meta.web.error}`);
|
||||
continue;
|
||||
}
|
||||
if (!meta.web.main) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
await loadScript(`${staticRoot}${meta.web.main}`);
|
||||
let container: any = (window as { [key: string]: any })[`plugin_${meta.name}`];
|
||||
@@ -136,6 +139,7 @@ export default async function bootstrap() {
|
||||
}));
|
||||
let [pluginInfos, pluginSetKey] = await loadPluginInfos();
|
||||
lib.registerPluginMessages(pluginInfos);
|
||||
lib.registerPluginPermissions(pluginInfos);
|
||||
lib.addPluginConfigFields(pluginInfos);
|
||||
|
||||
let wsUrl = new URL(webRoot, document.location.href);
|
||||
|
||||
@@ -46,11 +46,14 @@ export default function PluginViewPage() {
|
||||
}
|
||||
|
||||
const pluginError = pluginMeta.web.error ?? pluginInfo?.error;
|
||||
const hasWebModule = Boolean(pluginMeta.web.main || pluginMeta.web.error);
|
||||
if (!plugin) {
|
||||
return <PageLayout nav={nav}>
|
||||
<Descriptions bordered size="small" title={pluginTitle}>
|
||||
<Descriptions.Item label="Version">{pluginMeta.version}</Descriptions.Item>
|
||||
<Descriptions.Item label="Loaded in Web UI" span={2}>No</Descriptions.Item>
|
||||
<Descriptions.Item label="Loaded in Web UI" span={2}>
|
||||
{hasWebModule ? "No" : "No web module"}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="Loaded on controller">{pluginMeta.loaded ? "Yes" : "No"}</Descriptions.Item>
|
||||
<Descriptions.Item label="Enabled on controller" span={2}>
|
||||
{pluginMeta.enabled ? "Yes" : "No"}
|
||||
|
||||
@@ -88,6 +88,9 @@ export default function PluginsPage() {
|
||||
if (!plugin.meta.enabled) {
|
||||
return <><InfoCircleFilled style={{ color: "#1668dc" }} /> Disabled on controller</>;
|
||||
}
|
||||
if (!plugin.meta.web.main && !plugin.meta.web.error) {
|
||||
return plugin.meta.version;
|
||||
}
|
||||
if (!plugin.meta.web.error && !control.pluginInfos.has(plugin.meta.name)) {
|
||||
return <><InfoCircleFilled style={{ color: "#1668dc" }} /> Reload page to load</>;
|
||||
}
|
||||
@@ -105,7 +108,15 @@ export default function PluginsPage() {
|
||||
{
|
||||
title: "Loaded",
|
||||
key: "loaded",
|
||||
render: (_, plugin) => (plugin.package ? "Yes" : null),
|
||||
render: (_, plugin) => {
|
||||
if (plugin.package) {
|
||||
return "Yes";
|
||||
}
|
||||
if (!plugin.meta.web.main && !plugin.meta.web.error) {
|
||||
return "No web module";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
sorter: (a, b) => Number(Boolean(a.package)) - Number(Boolean(b.package)),
|
||||
sortOrder: tableState.sortOrder("loaded"),
|
||||
responsive: ["sm"],
|
||||
|
||||
@@ -22,13 +22,13 @@ export function useAccount(): UserAccount {
|
||||
};
|
||||
}, [control]);
|
||||
|
||||
function checkPermissionExists(permission: string) {
|
||||
function checkPermissionExists(permission: lib.PermissionName) {
|
||||
if (!lib.permissions.has(permission)) {
|
||||
throw new Error(`permission ${permission} does not exist`);
|
||||
}
|
||||
}
|
||||
|
||||
function hasPermission(permission: string): boolean {
|
||||
function hasPermission(permission: lib.PermissionName): boolean {
|
||||
for (let role of roles) {
|
||||
if (role.permissions.includes("core.admin") || role.permissions.includes(permission)) {
|
||||
return true;
|
||||
@@ -40,14 +40,14 @@ export function useAccount(): UserAccount {
|
||||
return {
|
||||
name,
|
||||
roles,
|
||||
hasPermission(permission: string): boolean | null {
|
||||
hasPermission(permission: lib.PermissionName): boolean | null {
|
||||
if (!roles) {
|
||||
return null;
|
||||
}
|
||||
checkPermissionExists(permission);
|
||||
return hasPermission(permission);
|
||||
},
|
||||
hasAnyPermission(...permissions: string[]): boolean | null {
|
||||
hasAnyPermission(...permissions: lib.PermissionName[]): boolean | null {
|
||||
if (!roles) {
|
||||
return null;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ export function useAccount(): UserAccount {
|
||||
}
|
||||
return false;
|
||||
},
|
||||
hasAllPermission(...permissions: string[]): boolean | null {
|
||||
hasAllPermission(...permissions: lib.PermissionName[]): boolean | null {
|
||||
if (!roles) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user