Skip to content

Fix content sharing external badge#4589

Open
reneshen0328 wants to merge 3 commits into
masterfrom
fix-content-sharing-external-badge
Open

Fix content sharing external badge#4589
reneshen0328 wants to merge 3 commits into
masterfrom
fix-content-sharing-external-badge

Conversation

@reneshen0328
Copy link
Copy Markdown
Contributor

@reneshen0328 reneshen0328 commented May 22, 2026

Summary by CodeRabbit

  • Bug Fixes

    • More accurate detection of external vs. internal collaborators and owner status in shared content.
  • Improvements

    • Current user information (including login/email) is now used end-to-end, improving collaborator display and ownership recognition.
    • Collaborator avatars and metadata render more consistently when building sharing lists.

Review Change Stack

@reneshen0328 reneshen0328 requested review from a team as code owners May 22, 2026 23:18
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

Walkthrough

Pass a full currentUser: User through ContentSharingV2/useSharingService/convertCollaborators, add FIELD_LOGIN to fetchCurrentUser, and change convertCollab's isExternal gating (owner-or-same-domain plus differing collaborator domain). Tests updated to use mockCurrentUser and to expect isExternal for external entries.

Changes

Content sharing: currentUser + external gating update

Layer / File(s) Summary
Constants and fetchCurrentUser
src/constants.js, src/elements/content-sharing/apis/fetchCurrentUser.ts, src/elements/content-sharing/apis/__tests__/fetchCurrentUser.test.ts
Add FIELD_LOGIN and include it in the getUser fields requested by fetchCurrentUser; update the test to expect the additional field.
ContentSharingV2 state and wiring
src/elements/content-sharing/ContentSharingV2.tsx
Extend component currentUser state to include email from API login, and pass the full currentUser object into useSharingService and convertCollabsResponse.
useSharingService signature & invite flow
src/elements/content-sharing/hooks/useSharingService.ts, src/elements/content-sharing/hooks/__tests__/useSharingService.test.ts
Change hook to accept currentUser, derive isCurrentUserOwner from currentUser.id in invite success handling, and update tests to pass currentUser objects and assert calls accordingly.
convertCollab & convertCollabsResponse logic
src/elements/content-sharing/utils/convertCollaborators.ts
Change ConvertCollabProps/function signatures to accept currentUser: User, compute isCurrentUser from currentUser.id, and update isExternal gating to require owner-or-same-domain plus differing collaborator/owner email domains.
convertCollaborators tests
src/elements/content-sharing/utils/__tests__/convertCollaborators.test.ts
Replace currentUserId with mockCurrentUser in test call sites, set isCurrentUserOwner where applicable, and update expected isExternal assertions for external collaborator entries; adjust related empty/null-avatar-map tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

ready-to-merge

Suggested reviewers

  • jpan-box
  • tjiang-box

Poem

🐇 I pass the user whole, not just an id,
I sniff domains where email ties hid,
Tests now hop in line, expectations true,
External flags flipped — a clean carrot for you! 🥕

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description contains only boilerplate HTML comments about the merge process with no actual implementation details, change rationale, or context about the external badge fix. Replace the boilerplate content with a substantive description explaining what the external badge issue was, why the currentUser parameter refactoring fixes it, and any relevant context for reviewers.
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 (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: fixing the external badge in content sharing, which aligns with the refactored isExternal logic and currentUser parameter updates throughout the changeset.
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.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-content-sharing-external-badge

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.

Comment on lines +51 to +52
// External collaborator icons will only be displayed in the USM if the current user owns
// the item and if the collaborator's email domain differs from the owner's email domain.
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.

no

Copy link
Copy Markdown
Contributor

@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.

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@src/elements/content-sharing/hooks/useSharingService.ts`:
- Around line 95-97: The invite-success path dereferences currentUser
(currentUser.id) without a null check; update the logic where the object with
currentUser, isCurrentUserOwner, and ownerEmailDomain is built (the block
referencing currentUser and ownerId) to guard currentUser first — compute
isCurrentUserOwner only if currentUser exists (e.g., currentUser &&
currentUser.id === ownerId or optional chaining), and only append to
collaborators or access any currentUser properties when currentUser is non-null;
ensure the invite callback in useSharingService.ts skips collaborator mutations
or uses a safe fallback when currentUser is null.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e8ad0dee-2450-428a-8490-5ed350e7a6e7

📥 Commits

Reviewing files that changed from the base of the PR and between ade9bdf and 03ac124.

📒 Files selected for processing (8)
  • src/constants.js
  • src/elements/content-sharing/ContentSharingV2.tsx
  • src/elements/content-sharing/apis/__tests__/fetchCurrentUser.test.ts
  • src/elements/content-sharing/apis/fetchCurrentUser.ts
  • src/elements/content-sharing/hooks/__tests__/useSharingService.test.ts
  • src/elements/content-sharing/hooks/useSharingService.ts
  • src/elements/content-sharing/utils/__tests__/convertCollaborators.test.ts
  • src/elements/content-sharing/utils/convertCollaborators.ts
✅ Files skipped from review due to trivial changes (1)
  • src/elements/content-sharing/apis/fetchCurrentUser.ts

Comment on lines +95 to 97
currentUser,
isCurrentUserOwner: currentUser.id === ownerId,
ownerEmailDomain,
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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Guard currentUser before dereferencing in invite success path.

Line 96 can throw when currentUser is still null (caller initializes it as null). Add a null-safe guard before using currentUser.id and appending collaborators.

Proposed fix
         setCollaborators(prevCollabs => {
+            if (!currentUser) {
+                return prevCollabs;
+            }
+
             const nextCollab = convertCollab({
                 avatarUrlMap,
                 collab: response,
                 currentUser,
                 isCurrentUserOwner: currentUser.id === ownerId,
                 ownerEmailDomain,
             });

-            return nextCollab ? [...prevCollabs, nextCollab] : prevCollabs;
+            return nextCollab ? [...(prevCollabs ?? []), nextCollab] : prevCollabs;
         });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
currentUser,
isCurrentUserOwner: currentUser.id === ownerId,
ownerEmailDomain,
setCollaborators(prevCollabs => {
if (!currentUser) {
return prevCollabs;
}
const nextCollab = convertCollab({
avatarUrlMap,
collab: response,
currentUser,
isCurrentUserOwner: currentUser.id === ownerId,
ownerEmailDomain,
});
return nextCollab ? [...(prevCollabs ?? []), nextCollab] : prevCollabs;
});
🤖 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 `@src/elements/content-sharing/hooks/useSharingService.ts` around lines 95 -
97, The invite-success path dereferences currentUser (currentUser.id) without a
null check; update the logic where the object with currentUser,
isCurrentUserOwner, and ownerEmailDomain is built (the block referencing
currentUser and ownerId) to guard currentUser first — compute isCurrentUserOwner
only if currentUser exists (e.g., currentUser && currentUser.id === ownerId or
optional chaining), and only append to collaborators or access any currentUser
properties when currentUser is non-null; ensure the invite callback in
useSharingService.ts skips collaborator mutations or uses a safe fallback when
currentUser is null.

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