(self, request, key)
| 477 | |
| 478 | class PluginRunAPIView(PluginAuthMixin, APIView): |
| 479 | def post(self, request, key): |
| 480 | pm = PluginManager.get() |
| 481 | action = request.data.get("action") |
| 482 | params = request.data.get("params", {}) |
| 483 | if not action: |
| 484 | return Response({"success": False, "error": "Missing 'action'"}, status=status.HTTP_400_BAD_REQUEST) |
| 485 | |
| 486 | # Respect plugin enabled flag |
| 487 | try: |
| 488 | cfg = PluginConfig.objects.get(key=key) |
| 489 | if not cfg.enabled: |
| 490 | return Response({"success": False, "error": "Plugin is disabled"}, status=status.HTTP_403_FORBIDDEN) |
| 491 | except PluginConfig.DoesNotExist: |
| 492 | return Response({"success": False, "error": "Plugin not found"}, status=status.HTTP_404_NOT_FOUND) |
| 493 | |
| 494 | try: |
| 495 | result = pm.run_action(key, action, params) |
| 496 | return Response({"success": True, "result": result}) |
| 497 | except PermissionError as e: |
| 498 | return Response({"success": False, "error": str(e)}, status=status.HTTP_403_FORBIDDEN) |
| 499 | except Exception as e: |
| 500 | logger.exception("Plugin action failed") |
| 501 | return Response({"success": False, "error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) |
| 502 | |
| 503 | |
| 504 | class PluginEnabledAPIView(PluginAuthMixin, APIView): |
nothing calls this directly
no test coverage detected