(self, request, key)
| 503 | |
| 504 | class PluginEnabledAPIView(PluginAuthMixin, APIView): |
| 505 | def post(self, request, key): |
| 506 | enabled_raw = request.data.get("enabled") |
| 507 | if enabled_raw is None: |
| 508 | return Response({"success": False, "error": "Missing 'enabled' boolean"}, status=status.HTTP_400_BAD_REQUEST) |
| 509 | enabled = _parse_bool(enabled_raw) |
| 510 | if enabled is None: |
| 511 | return Response({"success": False, "error": "Invalid 'enabled' boolean"}, status=status.HTTP_400_BAD_REQUEST) |
| 512 | try: |
| 513 | cfg = PluginConfig.objects.get(key=key) |
| 514 | pm = PluginManager.get() |
| 515 | if not enabled and cfg.enabled: |
| 516 | try: |
| 517 | pm.stop_plugin(key, reason="disable") |
| 518 | except Exception: |
| 519 | logger.exception("Failed to stop plugin '%s' on disable", key) |
| 520 | cfg.enabled = enabled |
| 521 | # Mark that this plugin has been enabled at least once |
| 522 | if cfg.enabled and not cfg.ever_enabled: |
| 523 | cfg.ever_enabled = True |
| 524 | cfg.save(update_fields=["enabled", "ever_enabled", "updated_at"]) |
| 525 | pm.discover_plugins(force_reload=True) |
| 526 | plugin_entry = None |
| 527 | try: |
| 528 | plugin_entry = next((p for p in pm.list_plugins() if p.get("key") == key), None) |
| 529 | except Exception: |
| 530 | plugin_entry = None |
| 531 | response = {"success": True, "enabled": cfg.enabled, "ever_enabled": cfg.ever_enabled} |
| 532 | if plugin_entry: |
| 533 | plugin_entry["logo_url"] = _absolutize_logo_url(request, plugin_entry.get("logo_url")) |
| 534 | response["plugin"] = plugin_entry |
| 535 | return Response(response) |
| 536 | except PluginConfig.DoesNotExist: |
| 537 | return Response({"success": False, "error": "Plugin not found"}, status=status.HTTP_404_NOT_FOUND) |
| 538 | |
| 539 | |
| 540 | class PluginLogoAPIView(APIView): |
nothing calls this directly
no test coverage detected