Define permissions on PluginDeclaration (#988)

Adds a permissions array to PluginDeclaration, a type-level Permissions
registry that plugins extend with module augmentation, and
registerPluginPermissions() called from all entrypoints. checkPermission
and the web UI hasPermission helpers now take PermissionName so typos are
compile errors. Core definitions move into a corePermissions array that
the interface derives its keys from.

Closes #987

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-09-11 23:28:30 +01:00
1 parent 2aee5379b5
commit 8c03ac15ab
23 files changed
+758 -575

No files matched your search

+11 -7
View File
@@ -8,15 +8,11 @@ declare module "@clusterio/lib" {
export interface ControllerConfigFields {
"inventory_sync.player_lock_timeout": number;
}
export interface Permissions {
"inventory_sync.inventory.view": never;
}
}
lib.definePermission({
name: "inventory_sync.inventory.view",
title: "View player inventories",
description: "View player inventories",
grantByDefault: true,
});
export const plugin: lib.PluginDeclaration = {
name: "inventory_sync",
title: "Inventory sync",
@@ -57,6 +53,14 @@ export const plugin: lib.PluginDeclaration = {
messages.DownloadRequest,
messages.DatabaseStatsRequest,
],
permissions: [
{
name: "inventory_sync.inventory.view",
title: "View player inventories",
description: "View player inventories",
grantByDefault: true,
},
],
webEntrypoint: "./web",
routes: ["/inventory"],
};
+1 -1
View File
@@ -4,5 +4,5 @@
{ "path": "../../packages/lib/tsconfig.browser.json" },
{ "path": "../../packages/web_ui/tsconfig.browser.json" },
],
"include": [ "web/**/*.tsx", "web/**/*.ts", "messages.ts", "package.json" ],
"include": [ "web/**/*.tsx", "web/**/*.ts", "index.ts", "messages.ts", "package.json" ],
}
+11 -7
View File
@@ -9,15 +9,11 @@ declare module "@clusterio/lib" {
export interface InstanceConfigFields {
"subspace_storage.log_item_transfers": boolean;
}
export interface Permissions {
"subspace_storage.storage.view": never;
}
}
lib.definePermission({
name: "subspace_storage.storage.view",
title: "View Subspace Storage",
description: "View the items and fluids stored in the shared subspace.",
grantByDefault: true,
});
export const plugin: lib.PluginDeclaration = {
name: "subspace_storage",
title: "Subspace Storage",
@@ -60,6 +56,14 @@ export const plugin: lib.PluginDeclaration = {
messages.UpdateStorageEvent,
messages.SetStorageSubscriptionRequest,
],
permissions: [
{
name: "subspace_storage.storage.view",
title: "View Subspace Storage",
description: "View the items and fluids stored in the shared subspace.",
grantByDefault: true,
},
],
webEntrypoint: "./web",
routes: ["/storage"],
};
@@ -4,5 +4,5 @@
{ "path": "../../packages/lib/tsconfig.browser.json" },
{ "path": "../../packages/web_ui/tsconfig.browser.json" },
],
"include": [ "web/**/*.tsx", "web/**/*.ts", "messages.ts", "package.json" ],
"include": [ "web/**/*.tsx", "web/**/*.ts", "index.ts", "messages.ts", "package.json" ],
}