feat(supervisor): support revoke binding and tighten access
This commit is contained in:
@@ -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}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user