Repository navigation
fix: one can edit team's memory - #17104
Conversation
📝 WalkthroughWalkthroughMemory access validation was added to the DAO, allowing tenant owners or active team members to access team-permitted memories. ChangesMemory access enforcement
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
internal/dao/memory.go (2)
394-408: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueFix grammatical error in error messages.
The error messages state "have no access", but it should be "has no access" since "user" is singular.
💬 Proposed fix
- return false, fmt.Errorf("user %s have no access to this memory", userID) + return false, fmt.Errorf("user %s has no access to this memory", userID) ... - return false, fmt.Errorf("user %s have no access to this memory", userID) + return false, fmt.Errorf("user %s has no access to this memory", userID)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/dao/memory.go` around lines 394 - 408, Update both error messages in the access-checking flow to use the grammatically correct phrase “user %s has no access to this memory,” including the early return and the final return after the user_tenant count check.
394-408: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueFix grammatical error in error messages.
The error messages state "have no access", but it should be "has no access" since "user" is singular.
💬 Proposed fix
- return false, fmt.Errorf("user %s have no access to this memory", userID) + return false, fmt.Errorf("user %s has no access to this memory", userID) ... - return false, fmt.Errorf("user %s have no access to this memory", userID) + return false, fmt.Errorf("user %s has no access to this memory", userID)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/dao/memory.go` around lines 394 - 408, Update both “user %s have no access to this memory” error messages in the surrounding access-check flow to use the grammatically correct “user %s has no access to this memory,” preserving the existing error behavior and formatting.internal/service/memory.go (1)
450-457: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winAvoid redundant queries and preserve clear error messages.
Currently,
s.memoryDAO.Accessiblefetches the memory by its ID, and thens.memoryDAO.GetByID(memoryID)fetches it a second time. Furthermore, becauseAccessibleis executed first, if the memory doesn't exist, it will return a raw database error (e.g.,record not found) instead of the clearer"memory '%s' not found"custom error provided on line 456.Consider modifying
Accessibleto accept an already-loaded*entity.Memoryparameter rather than fetching it internally. This allows you to load the memory first (preserving the custom error message) and then verify access, which eliminates the redundant database query.💡 Suggested refactor outline
In
internal/dao/memory.go:func (dao *MemoryDAO) Accessible(userID string, memory *entity.Memory) (bool, error) { // Remove GetByID call and use the provided memory struct // ...In
internal/service/memory.go:currentMemory, err := s.memoryDAO.GetByID(memoryID) if err != nil { return nil, fmt.Errorf("memory '%s' not found", memoryID) } if ok, err := s.memoryDAO.Accessible(userID, currentMemory); !ok || err != nil { return nil, err }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/service/memory.go` around lines 450 - 457, The memory access flow performs a redundant lookup and loses the custom not-found error. Update MemoryDAO.Accessible to accept the already-loaded *entity.Memory and use it directly, then in the relevant service method call GetByID first, preserve the “memory '%s' not found” error, and pass currentMemory to Accessible for authorization.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/dao/memory.go`:
- Around line 394-408: Update both error messages in the access-checking flow to
use the grammatically correct phrase “user %s has no access to this memory,”
including the early return and the final return after the user_tenant count
check.
- Around line 394-408: Update both “user %s have no access to this memory” error
messages in the surrounding access-check flow to use the grammatically correct
“user %s has no access to this memory,” preserving the existing error behavior
and formatting.
In `@internal/service/memory.go`:
- Around line 450-457: The memory access flow performs a redundant lookup and
loses the custom not-found error. Update MemoryDAO.Accessible to accept the
already-loaded *entity.Memory and use it directly, then in the relevant service
method call GetByID first, preserve the “memory '%s' not found” error, and pass
currentMemory to Accessible for authorization.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7533ded8-3633-49ef-ba8f-12876f3c353f
📒 Files selected for processing (2)
internal/dao/memory.gointernal/service/memory.go
Summary
As title