Skip to content

fix: one can edit team's memory - #17104

Merged
JinHai-CN merged 4 commits into
infiniflow:mainfrom
Haruko386:made
Jul 20, 2026
Merged

JinHai-CN merged 4 commits into
infiniflow:mainfrom
Haruko386:made

Conversation

@Haruko386

Copy link
Copy Markdown
Member

Summary

As title

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jul 20, 2026
@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Memory access validation was added to the DAO, allowing tenant owners or active team members to access team-permitted memories. UpdateMemory now performs this check before loading and modifying memory data.

Changes

Memory access enforcement

Layer / File(s) Summary
Memory authorization gate
internal/dao/memory.go, internal/service/memory.go
MemoryDAO.Accessible validates ownership or active team membership, while UpdateMemory stops early when access is denied or an error occurs.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Poem

A rabbit checks the memory door,
“Tenant or team?” it asks once more.
Active friends may hop inside,
Others meet a lock applied.
Updates wait till rights are clear.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description only says "As title" and lacks the required summary details and background context. Expand the Summary section with the problem, the fix, and any relevant reviewer context.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: preventing edits to a team's memory.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Haruko386 Haruko386 closed this Jul 20, 2026
@Haruko386 Haruko386 reopened this Jul 20, 2026
@Haruko386
Haruko386 marked this pull request as draft July 20, 2026 08:25
@Haruko386
Haruko386 marked this pull request as ready for review July 20, 2026 09:03
@Haruko386 Haruko386 added the ci Continue Integration label Jul 20, 2026
@Haruko386
Haruko386 marked this pull request as draft July 20, 2026 09:03
@Haruko386
Haruko386 marked this pull request as ready for review July 20, 2026 09:03
@Haruko386 Haruko386 changed the title fix: output [done] when AI summary ended fix: one can edit team's memory Jul 20, 2026
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jul 20, 2026
@Haruko386
Haruko386 marked this pull request as draft July 20, 2026 09:26
@Haruko386
Haruko386 marked this pull request as ready for review July 20, 2026 09:26
@Haruko386 Haruko386 added ci Continue Integration and removed ci Continue Integration labels Jul 20, 2026
@Haruko386
Haruko386 marked this pull request as draft July 20, 2026 09:28
@Haruko386
Haruko386 marked this pull request as ready for review July 20, 2026 09:28

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (3)
internal/dao/memory.go (2)

394-408: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Fix 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 value

Fix 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 win

Avoid redundant queries and preserve clear error messages.

Currently, s.memoryDAO.Accessible fetches the memory by its ID, and then s.memoryDAO.GetByID(memoryID) fetches it a second time. Furthermore, because Accessible is 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 Accessible to accept an already-loaded *entity.Memory parameter 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

📥 Commits

Reviewing files that changed from the base of the PR and between 8225b1e and 391b694.

📒 Files selected for processing (2)
  • internal/dao/memory.go
  • internal/service/memory.go

@JinHai-CN
JinHai-CN merged commit da2b1ce into infiniflow:main Jul 20, 2026
3 checks passed
@Haruko386
Haruko386 deleted the made branch August 18, 2026 05:05
@Haruko386
Haruko386 restored the made branch August 18, 2026 05:05
@Haruko386
Haruko386 deleted the made branch August 18, 2026 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants