Skip to content

[TMail] JAMES-4191: KeywordEmailQueryViewListener should clean up sharee's view upon MessageContentDeletionEvent#2282

Merged
chibenwa merged 4 commits intolinagora:masterfrom
quantranhong1999:dmv-share-mailbox
Mar 23, 2026
Merged

[TMail] JAMES-4191: KeywordEmailQueryViewListener should clean up sharee's view upon MessageContentDeletionEvent#2282
chibenwa merged 4 commits intolinagora:masterfrom
quantranhong1999:dmv-share-mailbox

Conversation

@quantranhong1999
Copy link
Member

@quantranhong1999 quantranhong1999 commented Mar 23, 2026

Also, RagDeletionListener was adapted.

Summary by CodeRabbit

  • Bug Fixes

    • Keyword views in shared and team mailboxes now correctly reflect user access rights.
    • AI-indexed content is only removed when a message is completely unreferenced, not when other copies exist for the user.
  • Tests

    • Added tests for keyword cleanup behavior across shared and team mailbox scenarios.
    • Added tests for read-rights resolution and cross-mailbox message references.

Arsnael and others added 4 commits March 23, 2026 11:17
…n the message is no longer referenced by the user

Given the `MessageContentDeletionEvent` is emitted easygoing now.
…ree's view upon MessageContentDeletionEvent

Team mailbox cases + Keyword view added.
@quantranhong1999 quantranhong1999 self-assigned this Mar 23, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 23, 2026

Walkthrough

This pull request updates message deletion and keyword view handling to respect mailbox access rights. The MailboxReadRightsResolver method usersHavingReadRight is made public to support a new read-right-aware deletion flow in KeywordEmailQueryViewListener. Message content deletion events are enriched with mailbox ACL information across multiple listeners (TeamMailboxDeletedMessageVaultDeletionListener, RagDeletionListener). The RagDeletionListener now checks whether deleted message content is still referenced in other mailboxes before triggering cleanup. Test coverage is expanded to validate keyword view deletion for users losing access and message reference tracking across mailboxes.

Possibly related PRs

Suggested reviewers

  • chibenwa
  • Arsnael
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: KeywordEmailQueryViewListener cleanup of sharee's view upon MessageContentDeletionEvent, which aligns with the PR's core objective.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tmail-backend/tmail-third-party/ai-bot/src/main/java/com/linagora/tmail/mailet/rag/RagDeletionListener.java (1)

52-52: Consider using a more descriptive system session username.

The hardcoded Username.of("admin") works because mapper operations don't require specific user privileges, but it differs from patterns elsewhere in the codebase where sessionProvider.createSystemSession(actualUsername) is used (see CleanupService, RecomputeQuotaTeamMailboxesService).

Since the session is created once at construction and reused, this is functionally correct. However, for clarity and consistency, consider using a more descriptive constant like Username.of("rag-deletion-listener") to indicate this is a technical session for internal operations.

🔧 Optional: Use descriptive system session username
-    private static final Username ADMIN = Username.of("admin");
+    private static final Username SYSTEM_USER = Username.of("rag-deletion-listener");

Also applies to: 55-72

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@tmail-backend/tmail-third-party/ai-bot/src/main/java/com/linagora/tmail/mailet/rag/RagDeletionListener.java`
at line 52, Replace the generic admin username with a descriptive system-session
name in RagDeletionListener: change the ADMIN constant (private static final
Username ADMIN = Username.of("admin")) to something like
Username.of("rag-deletion-listener") and ensure the existing use with
sessionProvider.createSystemSession(ADMIN) remains unchanged so the session is
still created once in the constructor; update any related references in this
class (constructor and methods that reuse ADMIN/session) to use the new constant
for clarity and consistency with other services like CleanupService and
RecomputeQuotaTeamMailboxesService.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@tmail-backend/tmail-third-party/ai-bot/src/main/java/com/linagora/tmail/mailet/rag/RagDeletionListener.java`:
- Line 52: Replace the generic admin username with a descriptive system-session
name in RagDeletionListener: change the ADMIN constant (private static final
Username ADMIN = Username.of("admin")) to something like
Username.of("rag-deletion-listener") and ensure the existing use with
sessionProvider.createSystemSession(ADMIN) remains unchanged so the session is
still created once in the constructor; update any related references in this
class (constructor and methods that reuse ADMIN/session) to use the new constant
for clarity and consistency with other services like CleanupService and
RecomputeQuotaTeamMailboxesService.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ce965901-c76d-427d-8589-93339d403dd4

📥 Commits

Reviewing files that changed from the base of the PR and between 954345c and c4d1858.

📒 Files selected for processing (8)
  • james-project
  • tmail-backend/jmap/extensions/src/main/java/com/linagora/tmail/james/jmap/event/KeywordEmailQueryViewListener.java
  • tmail-backend/jmap/extensions/src/main/java/com/linagora/tmail/james/jmap/projections/MailboxReadRightsResolver.java
  • tmail-backend/jmap/extensions/src/test/java/com/linagora/tmail/james/jmap/event/KeywordEmailQueryViewListenerTest.java
  • tmail-backend/jmap/extensions/src/test/java/com/linagora/tmail/james/jmap/projections/MailboxReadRightsResolverTest.java
  • tmail-backend/mailbox/plugin/tmail-deleted-message-vault/common/src/main/java/com/linagora/tmail/vault/TeamMailboxDeletedMessageVaultDeletionListener.java
  • tmail-backend/tmail-third-party/ai-bot/src/main/java/com/linagora/tmail/mailet/rag/RagDeletionListener.java
  • tmail-backend/tmail-third-party/ai-bot/src/test/java/com/linagora/tmail/mailet/rag/RagDeletionListenerTest.java

Copy link
Member

@Arsnael Arsnael left a comment

Choose a reason for hiding this comment

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

Thanks for completing this :)

@Arsnael Arsnael mentioned this pull request Mar 23, 2026
Copy link
Member

@chibenwa chibenwa left a comment

Choose a reason for hiding this comment

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

Awesome tests!
Really good work.
Thanks a lot for this level of functional coverage on such a sensible fonctional topic.

@chibenwa chibenwa merged commit 918bd04 into linagora:master Mar 23, 2026
6 checks passed
@chibenwa
Copy link
Member

Merging fast for SHA-1 upgrades

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants