feat(supervisor): support revoke binding and tighten access

This commit is contained in:
nepiedg
2026-04-16 11:55:00 +08:00
parent 0eaf3a206a
commit 55d84576f3
4 changed files with 103 additions and 5 deletions
@@ -94,3 +94,26 @@ func (h *Handler) GetSupervisorStatus(c *gin.Context) {
}
c.JSON(http.StatusOK, model.Success(res))
}
type revokeSupervisorBindingRequest struct {
OwnerUID int `json:"owner_uid"`
SupervisorUID int `json:"supervisor_uid"`
}
// RevokeSupervisorBinding POST /api/v2/supervisor/revoke
func (h *Handler) RevokeSupervisorBinding(c *gin.Context) {
user := middleware.MustCurrentUser(c)
var req revokeSupervisorBindingRequest
if err := c.ShouldBindJSON(&req); err != nil || req.OwnerUID <= 0 || req.SupervisorUID <= 0 {
c.JSON(http.StatusBadRequest, model.Error(http.StatusBadRequest, "请求参数错误"))
return
}
if err := h.service.RevokeSupervisorBinding(c.Request.Context(), int(user.ID), req.OwnerUID, req.SupervisorUID, time.Now()); err != nil {
c.JSON(http.StatusBadRequest, model.Error(http.StatusBadRequest, "解除失败"))
return
}
c.JSON(http.StatusOK, model.Success(gin.H{"ok": true}))
}