diff --git a/openapi/kb/collection.go b/openapi/kb/collection.go index c33b1118..088d4e5e 100644 --- a/openapi/kb/collection.go +++ b/openapi/kb/collection.go @@ -148,6 +148,9 @@ func CreateCollection(c *gin.Context) { // RemoveCollection removes an existing collection func RemoveCollection(c *gin.Context) { + + authInfo := authorized.GetInfo(c) + // Get collection ID from URL parameter collectionID := c.Param("collectionID") if collectionID == "" { @@ -169,6 +172,27 @@ func RemoveCollection(c *gin.Context) { return } + // Check remove permission + hasPermission, err := checkCollectionPermission(authInfo, collectionID) + if err != nil { + errorResp := &response.ErrorResponse{ + Code: response.ErrServerError.Code, + ErrorDescription: err.Error(), + } + response.RespondWithError(c, response.StatusForbidden, errorResp) + return + } + + // 403 Forbidden + if !hasPermission { + errorResp := &response.ErrorResponse{ + Code: response.ErrAccessDenied.Code, + ErrorDescription: "Forbidden: No permission to remove collection", + } + response.RespondWithError(c, response.StatusForbidden, errorResp) + return + } + // Call the actual RemoveCollection method removed, err := kb.Instance.RemoveCollection(c.Request.Context(), collectionID) if err != nil {