Changes plugin interface from 'roles' to 'enabled' method for more flexibility
This commit is contained in:
@@ -188,17 +188,21 @@ const useSettingsConfig = () => {
|
||||
|
||||
// Plugins
|
||||
PluginManager.getHooks(Hook.Settings).forEach((plugin) => {
|
||||
const group = plugin.value.group ?? "Integrations";
|
||||
const insertIndex = plugin.value.after
|
||||
? items.findIndex((i) => i.name === t(plugin.value.after!)) + 1
|
||||
: items.findIndex(
|
||||
(i) => i.group === t(plugin.value.group ?? "Integrations")
|
||||
);
|
||||
: items.findIndex((i) => i.group === t(group));
|
||||
items.splice(insertIndex, 0, {
|
||||
name: t(plugin.name),
|
||||
path: integrationSettingsPath(plugin.id),
|
||||
group: t(plugin.value.group),
|
||||
path:
|
||||
group === "Integrations"
|
||||
? integrationSettingsPath(plugin.id)
|
||||
: settingsPath(plugin.id),
|
||||
group: t(group),
|
||||
component: plugin.value.component,
|
||||
enabled: plugin.roles?.includes(user.role) || can.update,
|
||||
enabled: plugin.value.enabled
|
||||
? plugin.value.enabled(team, user)
|
||||
: can.update,
|
||||
icon: plugin.value.icon,
|
||||
} as ConfigItem);
|
||||
});
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import isArray from "lodash/isArray";
|
||||
import sortBy from "lodash/sortBy";
|
||||
import { action, observable } from "mobx";
|
||||
import Team from "~/models/Team";
|
||||
import User from "~/models/User";
|
||||
import { useComputed } from "~/hooks/useComputed";
|
||||
import Logger from "./Logger";
|
||||
import isCloudHosted from "./isCloudHosted";
|
||||
@@ -26,6 +28,8 @@ type PluginValueMap = {
|
||||
icon: React.ElementType;
|
||||
/** The settings screen somponent, should be lazy loaded. */
|
||||
component: React.LazyExoticComponent<React.ComponentType>;
|
||||
/** Whether the plugin is enabled in the current context. */
|
||||
enabled?: (team: Team, user: User) => boolean;
|
||||
};
|
||||
[Hook.Icon]: React.ElementType;
|
||||
};
|
||||
@@ -45,8 +49,6 @@ export type Plugin<T extends Hook> = {
|
||||
priority?: number;
|
||||
/** The deployments this plugin is enabled for (default: all) */
|
||||
deployments?: string[];
|
||||
/** The roles this plugin is enabled for. (default: admin) */
|
||||
roles?: string[];
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user