Allow Edit for admin in circle

This commit is contained in:
Mo Tarbin 2025-02-07 00:38:09 -05:00
parent bafc519150
commit 3919429f77
4 changed files with 16 additions and 5 deletions

View file

@ -427,7 +427,7 @@ func (h *Handler) editChore(c *gin.Context) {
})
return
}
if currentUser.ID != oldChore.CreatedBy {
if !oldChore.CanEdit(currentUser.ID, circleUsers) {
c.JSON(403, gin.H{
"error": "You are not allowed to edit this chore",
})

View file

@ -3,6 +3,7 @@ package model
import (
"time"
cModel "donetick.com/core/internal/circle/model"
lModel "donetick.com/core/internal/label/model"
tModel "donetick.com/core/internal/thing/model"
thingModel "donetick.com/core/internal/thing/model"
@ -169,3 +170,15 @@ type ChoreReq struct {
CompletionWindow *int `json:"completionWindow"`
Description *string `json:"description"`
}
func (c *Chore) CanEdit(userID int, circleUsers []*cModel.UserCircleDetail) bool {
if c.CreatedBy == userID {
return true
}
for _, cu := range circleUsers {
if cu.UserID == userID && cu.Role == "admin" {
return true
}
}
return false
}