Skip to content

fix: content sharing external badge#4589

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

fix: content sharing external badge#4589
reneshen0328 wants to merge 6 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 object (including login/email) is used end-to-end, improving collaborator display, ownership recognition, and avatar/metadata consistency.
    • Profile fetching now requests additional login information to better determine collaborator relationships.
  • Tests

    • Updated tests to validate the new current-user-based collaborator logic and external-user flags.

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

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Pass a full currentUser object through ContentSharingV2/useSharingService/convertCollaborators, add FIELD_LOGIN to fetchCurrentUser, and change convertCollab's isExternal gating to require owner-or-same-domain plus differing collaborator domain. Tests and mocks updated accordingly.

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.
Mocks update
src/elements/content-sharing/utils/__mocks__/ContentSharingV2Mocks.js
Change mockOwnerId to string and add login to default user mock shape.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

ready-to-merge

Suggested reviewers

  • tjuanitas
  • jpan-box
  • tjiang-box

Poem

🐇 I carry the whole user, not just a name,
I hop through domains to check who's the same,
Tests tidy their burrows and mocks take their place,
External flags shimmer in the collaborators' space.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description only contains a template with generic merge queue instructions and lacks any meaningful explanation of the changes, objectives, or impact. Provide a substantive PR description explaining what was fixed, why the external badge logic needed changes, and any relevant implementation details or testing notes.
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 'fix: content sharing external badge' accurately describes the main change: updating the logic for determining when a collaborator should be marked as external.
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 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 thread src/elements/content-sharing/utils/convertCollaborators.ts Outdated
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 thread src/elements/content-sharing/hooks/useSharingService.ts
@reneshen0328 reneshen0328 force-pushed the fix-content-sharing-external-badge branch from 03ac124 to 0f7a123 Compare May 26, 2026 17:01
@reneshen0328 reneshen0328 changed the title Fix content sharing external badge Fix: content sharing external badge May 26, 2026
@reneshen0328 reneshen0328 changed the title Fix: content sharing external badge fix: content sharing external badge May 26, 2026
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/constants.js`:
- Line 174: The file contains TypeScript-only syntax (e.g., declare var
__VERSION__: string and exports like FIELD_LOGIN: 'login' = 'login') inside a
.js file causing Biome parse errors; either convert the file to TypeScript by
renaming src/constants.js to src/constants.ts and update all imports/usages
accordingly, or remove all TypeScript type annotations and declare statements
(replace patterns like "declare var __VERSION__: string;" and "export const
FIELD_LOGIN: 'login' = 'login';" with plain JS equivalents such as simple
const/exports) so the file is valid JavaScript; locate symbols like FIELD_LOGIN
and the declare __VERSION__ to ensure all TS syntax is handled consistently
across the file.
🪄 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: ca0af714-ac4c-49fd-8ae5-988ab6e1428f

📥 Commits

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

📒 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/hooks/tests/useSharingService.test.ts

Comment thread src/constants.js
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/utils/__mocks__/ContentSharingV2Mocks.js`:
- Line 97: DEFAULT_USER_API_RESPONSE pairs the owner's id ('789') with the wrong
login (collabUser2.login); change the login property to mockOwner.login (or
mockOwnerEmail) so the entry with id '789' matches the owner's email; update the
mock object in ContentSharingV2Mocks.js (look for DEFAULT_USER_API_RESPONSE and
the login: collabUser2.login line) to use mockOwner.login to keep owner identity
consistent for domain-based collaborator gating tests.
🪄 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: 1b002ddf-c1c3-4bab-8308-c3ad98e6680f

📥 Commits

Reviewing files that changed from the base of the PR and between 0f7a123 and 701b131.

📒 Files selected for processing (1)
  • src/elements/content-sharing/utils/__mocks__/ContentSharingV2Mocks.js

Comment thread src/elements/content-sharing/utils/__mocks__/ContentSharingV2Mocks.js Outdated
@reneshen0328 reneshen0328 force-pushed the fix-content-sharing-external-badge branch from 701b131 to c623626 Compare May 26, 2026 18:02
Comment thread src/elements/content-sharing/ContentSharingV2.tsx Outdated
Comment thread src/elements/content-sharing/utils/convertCollaborators.ts Outdated
Comment thread src/elements/content-sharing/utils/convertCollaborators.ts Outdated
Comment thread src/elements/content-sharing/utils/convertCollaborators.ts Outdated
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