Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

feat(plugin): add plugins status api

LinkinStars1d46a54444fb
diff --git a/internal/controller_admin/plugin_controller.go b/internal/controller_admin/plugin_controller.go
index e565f2bd..930fffd0 100644
--- a/internal/controller_admin/plugin_controller.go
+++ b/internal/controller_admin/plugin_controller.go
@@ -20,6 +20,37 @@ func NewPluginController(PluginCommonService *plugin_common.PluginCommonService)
return &PluginController{PluginCommonService: PluginCommonService}
}
+// GetAllPluginStatus get all plugins status
+// @Summary get all plugins status
+// @Description get all plugins status
+// @Tags Plugin
+// @Security ApiKeyAuth
+// @Accept json
+// @Produce json
+// @Success 200 {object} handler.RespBody{data=[]schema.GetPluginListResp}
+// @Router /answer/api/v1/plugin/status [get]
+func (pc *PluginController) GetAllPluginStatus(ctx *gin.Context) {
+ resp := make([]*schema.GetAllPluginStatusResp, 0)
+ _ = plugin.CallBase(func(base plugin.Base) error {
+ info := base.Info()
+ resp = append(resp, &schema.GetAllPluginStatusResp{
+ SlugName: info.SlugName,
+ Enabled: plugin.StatusManager.IsEnabled(info.SlugName),
+ })
+ return nil
+ })
+
+ resp = append(resp, &schema.GetAllPluginStatusResp{
+ SlugName: "chart_editor",
+ Enabled: true,
+ })
+ resp = append(resp, &schema.GetAllPluginStatusResp{
+ SlugName: "formula_editor",
+ Enabled: true,
+ })
+ handler.HandleResponse(ctx, nil, resp)
+}
+
// GetPluginList get plugin list
// @Summary get plugin list
// @Description get plugin list
diff --git a/internal/router/answer_api_router.go b/internal/router/answer_api_router.go
index 4f196042..43509067 100644
--- a/internal/router/answer_api_router.go
+++ b/internal/router/answer_api_router.go
@@ -115,6 +115,9 @@ func (a *AnswerAPIRouter) RegisterMustUnAuthAnswerAPIRouter(authUserMiddleware *
routerGroup.POST("/user/password/reset", a.userController.RetrievePassWord)
routerGroup.POST("/user/password/replacement", a.userController.UseRePassWord)
routerGroup.PUT("/user/notification/unsubscribe", a.userController.UserUnsubscribeNotification)
+
+ // plugins
+ r.GET("/plugin/status", a.pluginController.GetAllPluginStatus)
}
func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r *gin.RouterGroup) {
diff --git a/internal/schema/plugin_admin_schema.go b/internal/schema/plugin_admin_schema.go
index 7684e264..1b1ea90d 100644
--- a/internal/schema/plugin_admin_schema.go
+++ b/internal/schema/plugin_admin_schema.go
@@ -27,6 +27,11 @@ type GetPluginListResp struct {
Link string `json:"link"`
}
+type GetAllPluginStatusResp struct {
+ SlugName string `json:"slug_name"`
+ Enabled bool `json:"enabled"`
+}
+
type UpdatePluginStatusReq struct {
PluginSlugName string `validate:"required,gt=1,lte=100" json:"plugin_slug_name"`
Enabled bool `json:"enabled"`