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

@ -158,9 +158,6 @@ func LoadConfig() *Config {
panic(err)
}
fmt.Printf("--ConfigLoad name : %s ", config.Name)
panic(config.OAuth2Config.ClientID)
// bind all the environment variables to the config:
configEnvironmentOverrides(&config)
return &config

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
}

View file

@ -4,6 +4,7 @@ import (
"donetick.com/core/config"
jwt "github.com/appleboy/gin-jwt/v2"
"github.com/gin-gonic/gin"
"github.com/ulule/limiter/v3"
)
type Resource struct {
@ -35,7 +36,7 @@ func (h *Handler) getResource(c *gin.Context) {
})
}
func (h *Handler) Routes(r *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
func Routes(r *gin.Engine, h *Handler, auth *jwt.GinJWTMiddleware, limiter *limiter.Limiter) {
resourceRoutes := r.Group("api/v1/resource")
// skip resource endpoint for donetick.com