Add permission checks for collection removal
- Implemented authorization checks in the RemoveCollection function to ensure users have the necessary permissions before removing a collection. - Introduced error handling for unauthorized access attempts, returning appropriate responses for permission denials. - Enhanced security by validating user access based on their authorization information.
This commit is contained in:
parent
d6713ecddb
commit
5c2f323e64
1 changed files with 24 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue