fix plugins deletion logic
Alessandro committed
Mar 4, 2026 at 15:58 UTC
bb186c55c46be178fc7eefb07ecc5b13662b0bae
3 files changed
+16
-12
python/api/plugins.py
+5
-10
@@ -157,19 +157,14 @@ class Plugins(ApiHandler):
157
158
if action == "delete_plugin":
159
plugin_name = input.get("plugin_name", "")
160
- path = input.get("path", "")
160
if not plugin_name:
161
return Response(status=400, response="Missing plugin_name")
163
- if not path:
164
- return Response(status=400, response="Missing path")
165
-
166
- # Validate that the plugin is actually a custom plugin
167
- custom_plugins_dir = files.get_abs_path(files.USER_DIR, files.PLUGINS_DIR)
168
- if not os.path.abspath(path).startswith(os.path.abspath(custom_plugins_dir)):
169
- return Response(status=400, response="Only custom plugins can be deleted")
170
-
162
try:
172
- files.delete_dir(path)
163
+ plugins.delete_plugin(plugin_name)
164
+ except FileNotFoundError as e:
165
+ return Response(status=404, response=str(e))
166
+ except ValueError as e:
167
+ return Response(status=400, response=str(e))
168
except Exception as e:
169
return Response(status=500, response=f"Failed to delete plugin: {str(e)}")
170
return {"ok": True}
python/helpers/plugins.py
+10
@@ -181,6 +181,16 @@ def find_plugin_dir(plugin_name: str):
181
return None
182
183
184
+def delete_plugin(plugin_name: str):
185
+ plugin_dir = find_plugin_dir(plugin_name)
186
+ if not plugin_dir:
187
+ raise FileNotFoundError(f"Plugin '{plugin_name}' not found")
188
+ custom_plugins_dir = files.get_abs_path(files.USER_DIR, files.PLUGINS_DIR)
189
+ if not files.is_in_dir(plugin_dir, custom_plugins_dir):
190
+ raise ValueError("Only custom plugins can be deleted")
191
+ files.delete_dir(plugin_dir)
192
+
193
+
194
def get_plugin_paths(*subpaths: str) -> List[str]:
195
sub = "*/" + "/".join(subpaths) if subpaths else "*"
196
paths: List[str] = []
webui/components/plugins/list/pluginListStore.js
+1
-2
@@ -152,7 +152,7 @@ const model = {
152
},
153
154
async deletePlugin(plugin) {
155
- if (!plugin?.path) return;
155
+ if (!plugin?.name) return;
156
157
if (!plugin.is_custom) {
158
showErrorNotification(
@@ -166,7 +166,6 @@ const model = {
166
const response = await api.callJsonApi("plugins", {
167
action: "delete_plugin",
168
plugin_name: plugin.name,
169
- path: plugin.path,
169
});
170
if (response?.error) {
171
throw new Error(response.error);