Skip to content

fix(mention): restore organization and group mentions - #1598

Merged
ganta merged 1 commit into
mainfrom
fix-organization-and-group-mentions
Aug 2, 2026
Merged

fix(mention): restore organization and group mentions#1598
ganta merged 1 commit into
mainfrom
fix-organization-and-group-mentions

Conversation

@ganta

@ganta ganta commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Migrating DirectoryEntity to Zod (#869) changed DirectoryEntityType values from the Markdown notation prefixes (user/org/group) to display names, but the mention regexp kept matching the old lowercase prefixes. Since then, picking an organization or a group from the autocomplete inserted an unparsable @Organization/code, which was looked up as a user, missed, and stayed plain text. A hand-written @org/code was worse: the switch on the captured prefix never matched the new enum values, so it fell through to the user lookup and could silently mention an unrelated user sharing that code.

The notation prefix is now a mapping owned by MentionReplacer, and the regexp, the emitted text and the data-*-mention-id attribute name are all derived from it. The reverse lookup deliberately does not reuse toDirectoryEntityType, whose silent User fallback is what hid this for over a year.

MentionReplacer had no tests, which is why this shipped green. The new suite pins the round trip (createMentionfetchDirectoryEntityInTextreplaceMention) per entity type, the exact anchor attributes, and — across modules — that extractReplyMentions can read those anchors back. 6 of its 12 cases fail against the unfixed source.

Verification

pnpm run test / typecheck / lint / build all pass.

Verified by hand on the legacy UI of a dev environment (space thread comments):

  • Autocomplete inserts @org/test_org / @group/Administrators, rendering anchors with data-org-mention-id / data-group-mention-id
  • Posting persists those anchors server-side, and kintone's own submit payload carries mentions / groupMentions / orgMentions correctly derived from them
  • "Reply to all" prefills @org/test_org and @group/Administrators
  • User mentions unchanged

Note: mentioning the root organization is rejected by kintone with CB_IL02 regardless of the markup (orgMentions:["<root org id>"] fails even with a plain body), so verification used a regular organization.

Summary by CodeRabbit

  • Bug Fixes

    • Improved mention recognition for users, organizations, and groups.
    • Added validation for supported mention formats, including @, @org/, and @group/.
    • Improved directory lookups and conversion of valid mentions into clickable links.
    • Preserved mention details when generating reply data and extracting mentions.
    • Improved handling of missing entities and mentions followed by trailing characters.
  • Tests

    • Added comprehensive coverage for mention creation, lookup, conversion, and extraction scenarios.

Migrating `DirectoryEntity` to Zod changed `DirectoryEntityType` values from the Markdown notation prefixes (`user`/`org`/`group`) to display names, but the mention regexp kept matching the old lowercase prefixes. Since then `createMention` emitted an unparsable `@Organization/code`, and a hand-written `@org/code` fell through to the user lookup, which could silently mention an unrelated user sharing that code.
@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1afbdd0a-9f20-4f28-bf66-108c3fa1ba20

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)

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.

@ganta
ganta requested a review from Copilot August 2, 2026 15:07
@ganta ganta self-assigned this Aug 2, 2026
@ganta
ganta marked this pull request as ready for review August 2, 2026 15:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Not ready to approve

The new test file uses a non-standard toHaveBeenCalledExactlyOnceWith matcher that is not defined in the Vitest setup and will likely fail in CI.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

This PR fixes mention parsing/rendering for organizations and groups after the DirectoryEntityType enum migration by centralizing the Markdown mention prefix mapping inside MentionReplacer, and ensuring the regexp, emitted mention text, and rendered data-*-mention-id attributes are derived from the same source. It also adds unit tests to lock in round-trip behavior and cross-module compatibility with extractReplyMentions.

Changes:

  • Introduce explicit mention-prefix mappings and a derived mention regexp in MentionReplacer, avoiding the previous silent fallback behavior that masked type mismatches.
  • Update mention creation, lookup, and anchor attribute naming to consistently use the new prefix mapping (org/group) rather than enum display names.
  • Add a new test suite covering mention round trips per entity type and verifying anchors are readable by extractReplyMentions.
File summaries
File Description
src/app/markdown/replacer/mention-replacer.ts Centralizes prefix/type mapping and derives parsing + rendered anchor attribute naming from it to restore org/group mentions.
tests/unit/app/markdown/replacer/mention-replacer.test.ts Adds coverage for mention creation/lookup/rendering and verifies extractReplyMentions interoperability.
Review details

Suppressed comments (1)

tests/unit/app/markdown/replacer/mention-replacer.test.ts:119

  • Same issue here: toHaveBeenCalledExactlyOnceWith isn't provided by default in Vitest/Jest (and isn’t added in tests/setup.ts). Replace with standard call count + argument assertions.
      expect(kintoneClient.findUserByCode).toHaveBeenCalledExactlyOnceWith(
        "org/",
      );
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment thread tests/unit/app/markdown/replacer/mention-replacer.test.ts
@ganta
ganta merged commit f599125 into main Aug 2, 2026
15 checks passed
@ganta
ganta deleted the fix-organization-and-group-mentions branch August 2, 2026 15:18
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.

2 participants