diff --git a/VERSION b/VERSION index fae6e3d..af8c8ec 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.2.1 +4.2.2 diff --git a/play-life-backend/main.go b/play-life-backend/main.go index af2b457..73b0255 100644 --- a/play-life-backend/main.go +++ b/play-life-backend/main.go @@ -7093,14 +7093,16 @@ func (a *App) createTaskHandler(w http.ResponseWriter, r *http.Request) { } } - // Валидация wishlist_id: если указан, проверяем что желание существует и принадлежит пользователю + // Валидация wishlist_id: если указан, проверяем что желание существует и пользователь имеет доступ var wishlistName string if req.WishlistID != nil { var wishlistOwnerID int + var authorID sql.NullInt64 + var boardID sql.NullInt64 err := a.DB.QueryRow(` - SELECT user_id, name FROM wishlist_items + SELECT user_id, name, author_id, board_id FROM wishlist_items WHERE id = $1 AND deleted = FALSE - `, *req.WishlistID).Scan(&wishlistOwnerID, &wishlistName) + `, *req.WishlistID).Scan(&wishlistOwnerID, &wishlistName, &authorID, &boardID) if err == sql.ErrNoRows { sendErrorWithCORS(w, "Wishlist item not found", http.StatusBadRequest) @@ -7112,7 +7114,27 @@ func (a *App) createTaskHandler(w http.ResponseWriter, r *http.Request) { return } - if wishlistOwnerID != userID { + hasAccess := wishlistOwnerID == userID + // Проверяем, является ли пользователь автором желания + if !hasAccess && authorID.Valid && authorID.Int64 == int64(userID) { + hasAccess = true + } + // Проверяем доступ к доске, если желание принадлежит доске + if !hasAccess && boardID.Valid { + var boardOwnerID int + err := a.DB.QueryRow(`SELECT owner_id FROM wishlist_boards WHERE id = $1 AND deleted = FALSE`, boardID.Int64).Scan(&boardOwnerID) + if err == nil && boardOwnerID == userID { + hasAccess = true + } else if err == nil { + var isMember bool + a.DB.QueryRow(`SELECT EXISTS(SELECT 1 FROM wishlist_board_members WHERE board_id = $1 AND user_id = $2)`, boardID.Int64, userID).Scan(&isMember) + if isMember { + hasAccess = true + } + } + } + + if !hasAccess { sendErrorWithCORS(w, "Wishlist item not found", http.StatusNotFound) return } diff --git a/play-life-web/package.json b/play-life-web/package.json index 90b833d..b13250a 100644 --- a/play-life-web/package.json +++ b/play-life-web/package.json @@ -1,6 +1,6 @@ { "name": "play-life-web", - "version": "4.2.1", + "version": "4.2.2", "type": "module", "scripts": { "dev": "vite",