Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Group Members fixes #1445

Merged
merged 1 commit into from
Jan 2, 2025
Merged

fix: Group Members fixes #1445

merged 1 commit into from
Jan 2, 2025

Conversation

alexrisch
Copy link
Collaborator

@alexrisch alexrisch commented Dec 31, 2024

Fixed usage of permission policies
Updated tests
Setup logic to automaitcally do the only action sheet option if available

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced group member action handling with more granular permission checks
    • Improved action sheet functionality for single-option scenarios
  • Bug Fixes

    • Corrected group member status messaging to accurately reflect member leaving
  • Refactor

    • Streamlined group member action logic
    • Updated role and permission handling conventions
    • Improved parameter management in utility functions
  • Style

    • Standardized role naming conventions (e.g., "superAdmin" instead of "super_admin")

Fixed usage of permission policies
Updated tests
Setup logic to automaitcally do the only action sheet option if available
@alexrisch alexrisch requested a review from a team as a code owner December 31, 2024 05:26
Copy link
Contributor

coderabbitai bot commented Dec 31, 2024

Walkthrough

The pull request introduces several modifications across multiple files, focusing on group management and action handling. The changes primarily involve refactoring the getGroupMemberActions function, updating group member role handling, and improving the action sheet state management. The modifications enhance permission checks, streamline parameter handling, and adjust the logic for determining group member actions and roles.

Changes

File Change Summary
components/StateHandlers/ActionSheetStateHandler.tsx Added conditional check in showActionSheetWithOptions to handle single-option scenarios
containers/GroupScreenMembersTable.tsx Introduced currentAccountIsAdmin and updated member actions logic
features/conversation/...chat-group-update.tsx Changed group member status text from "joined" to "left"
utils/groupUtils/getGroupMemberActions.ts Refactored function to use single object parameter with new type GetGroupMemberActionsProps
utils/groupUtils/userCanDoGroupActions.ts Updated MemberRole type and role string from "super_admin" to "superAdmin"

Suggested Reviewers

  • thierryskoda

Poem

🐰 In the realm of code, where rabbits hop and play,
Permissions dance, roles find their way
From single options to admin's might
We refactor with pure delight! 🔧
A cleaner path, a smoother flow
Watch our changes gracefully grow! 🌱

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

Performance Comparison Report

  • Current: 7704e02 - 2024-12-31 05:30:19Z
  • Baseline: release/3.0.0 (187d108) - 2024-12-31 05:28:59Z

Significant Changes To Duration

There are no entries

Meaningless Changes To Duration

Show entries
Name Type Duration Count
Avatar Image 10 runs render 1.1 ms → 1.1 ms 1 → 1
Avatar Image 50 runs render 1.0 ms → 1.0 ms (+0.0 ms, +2.0%) 1 → 1
Empty Avatar 10 runs render 0.7 ms → 0.9 ms (+0.2 ms, +28.6%) 🔴 1 → 1
Empty Avatar 50 runs render 0.7 ms → 0.8 ms (+0.0 ms, +2.7%) 1 → 1
Text Component with color prop - 10 runs render 0.3 ms → 0.1 ms (-0.2 ms, -66.7%) 🟢 1 → 1
Text Component with default props - 10 runs render 0.2 ms → 0.4 ms (+0.2 ms, +100.0%) 🔴 1 → 1
Text Component with translation key - 10 runs render 0.1 ms → 0.3 ms (+0.2 ms, +200.0%) 🔴 1 → 1
Text Component with weight and size - 10 runs render 0.2 ms → 0.2 ms 1 → 1
Show details
Name Type Duration Count
Avatar Image 10 runs render Baseline
Mean: 1.1 ms
Stdev: 0.3 ms (28.7%)
Runs: 1 1 1 1 1 1 1 1 2 1
Warmup runs: 3

Current
Mean: 1.1 ms
Stdev: 0.3 ms (28.7%)
Runs: 2 1 1 1 1 1 1 1 1 1
Warmup runs: 3
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:
Avatar Image 50 runs render Baseline
Mean: 1.0 ms
Stdev: 0.2 ms (24.2%)
Runs: 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Warmup runs: 1

Current
Mean: 1.0 ms
Stdev: 0.3 ms (27.2%)
Runs: 1 1 1 0 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Warmup runs: 1
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Render issues:
Empty Avatar 10 runs render Baseline
Mean: 0.7 ms
Stdev: 0.5 ms (69.0%)
Runs: 1 1 1 1 1 0 1 0 1 0
Warmup runs: 1

Current
Mean: 0.9 ms
Stdev: 0.6 ms (63.1%)
Runs: 1 1 1 1 2 1 0 1 1 0
Warmup runs: 3
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:
Empty Avatar 50 runs render Baseline
Mean: 0.7 ms
Stdev: 0.4 ms (59.9%)
Runs: 1 0 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 0 0 1 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 0 0 1 1 1 1 1
Warmup runs: 1

Current
Mean: 0.8 ms
Stdev: 0.4 ms (56.8%)
Runs: 1 0 1 1 1 1 0 1 1 0 0 1 0 1 1 1 0 1 0 1 1 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 0 1
Warmup runs: 1
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Render issues:
Text Component with color prop - 10 runs render Baseline
Mean: 0.3 ms
Stdev: 0.5 ms (161.0%)
Runs: 1 0 1 1 0 0 0 0 0 0
Warmup runs: 0

Current
Mean: 0.1 ms
Stdev: 0.3 ms (316.2%)
Runs: 0 0 0 0 1 0 0 0 0 0
Warmup runs: 0
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:
Text Component with default props - 10 runs render Baseline
Mean: 0.2 ms
Stdev: 0.4 ms (210.8%)
Runs: 0 0 1 0 0 1 0 0 0 0
Warmup runs: 0

Current
Mean: 0.4 ms
Stdev: 0.5 ms (129.1%)
Runs: 0 0 1 1 1 0 0 0 1 0
Warmup runs: 1
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:
Text Component with translation key - 10 runs render Baseline
Mean: 0.1 ms
Stdev: 0.3 ms (316.2%)
Runs: 0 0 0 0 0 0 0 0 0 1
Warmup runs: 1

Current
Mean: 0.3 ms
Stdev: 0.5 ms (161.0%)
Runs: 0 1 0 0 1 0 0 1 0 0
Warmup runs: 0
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:
Text Component with weight and size - 10 runs render Baseline
Mean: 0.2 ms
Stdev: 0.4 ms (210.8%)
Runs: 1 0 0 0 0 1 0 0 0 0
Warmup runs: 0

Current
Mean: 0.2 ms
Stdev: 0.4 ms (210.8%)
Runs: 0 0 0 1 0 1 0 0 0 0
Warmup runs: 0
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:

Render Count Changes

There are no entries

Render Issues

There are no entries

Added Scenarios

There are no entries

Removed Scenarios

There are no entries

Generated by 🚫 dangerJS against 63c36f5

Copy link
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

🧹 Nitpick comments (1)
containers/GroupScreenMembersTable.tsx (1)

112-119: Ensure consistent parameter naming in getGroupMemberActions.

The function call includes multiple booleans (isAdmin, isSuperAdmin, currentAccountIsAdmin, currentAccountIsSuperAdmin). Consider aligning naming or grouping these flags for clarity, especially within the called function. This will simplify reasoning about permission levels.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 187d108 and 63c36f5.

📒 Files selected for processing (6)
  • components/StateHandlers/ActionSheetStateHandler.tsx (1 hunks)
  • containers/GroupScreenMembersTable.tsx (4 hunks)
  • features/conversation/conversation-message/conversation-message-content-types/conversation-message-chat-group-update.tsx (1 hunks)
  • utils/groupUtils/getGroupMemberActions.test.ts (1 hunks)
  • utils/groupUtils/getGroupMemberActions.ts (2 hunks)
  • utils/groupUtils/userCanDoGroupActions.ts (3 hunks)
🔇 Additional comments (19)
components/StateHandlers/ActionSheetStateHandler.tsx (1)

18-21: Ensure desired UX when there is only one option.
Short-circuiting the action sheet when options.options.length === 1 is helpful to reduce user friction. However, consider how you handle special cases (e.g., a destructive-only option). Ensure this scenario aligns with your expected UX before automatically calling the callback.

utils/groupUtils/userCanDoGroupActions.ts (2)

14-14: Consistent logic when returning "superAdmin".
The condition properly returns "superAdmin" if isSuperAdmin is true. This looks good.


32-32: Matching new role check for "superAdmin".
This change correctly checks for both "admin" and "superAdmin" in the policy.

utils/groupUtils/getGroupMemberActions.ts (7)

5-12: Refactor to a single object parameter enhances clarity.
Defining GetGroupMemberActionsProps and consolidating inputs into a single object is a clean design that improves maintainability.


14-21: Destructured props increase readability.
Using object destructuring is a best practice that clarifies parameter usage.


27-28: Pass consistent role flags to userCanDoGroupActions.
Replacing older flags with currentAccountIsSuperAdmin and currentAccountIsAdmin ensures consistency with the new naming convention.


31-41: Appropriate checks before promoting to admin or super admin.
The conditions logically guard against self-modification or reassigning existing roles. Ensure tests cover edge cases (e.g., can a super admin promote another super admin?).


44-52: Revoke checks appear correct.
Verifying that it’s not the current user and roles are set correctly before revoking. This is consistent with the rest of your role logic.


55-55: canRevokeSuperAdmin logic.
The additional check that ensures isSuperAdmin and currentAccountIsSuperAdmin are both true is sensible.


84-84: Naming suggests "remove" but double-check edge cases.
“Remove from group” seems correct. Just confirm that super admins can or cannot remove themselves, if that scenario is valid.

utils/groupUtils/getGroupMemberActions.test.ts (6)

6-15: Single object parameter in tests improves maintainability.
This approach is more explicit, making it easier to see how booleans affect outcomes.


21-30: Promote to super admin scenario.
Ensures correct logic flow. Good coverage of the super admin case.


36-45: Revoke admin tests.
Properly checks the new parameter structure and ensures the correct result.


51-60: Revoke super admin coverage.
Verifies that “Revoke super admin” is displayed under proper conditions.


66-75: Remove from group scenario.
Covers a key permission boundary. This test ensures consistency with group removal logic.


81-90: Excluding admin actions for the current user.
Clear test ensuring that self-targeted promotions/removals do not appear, aligning with the logic in getGroupMemberActions.

features/conversation/conversation-message/conversation-message-content-types/conversation-message-chat-group-update.tsx (1)

115-115: Keep translations consistent with updated semantics.

Using "group_member_left" clarifies that a member has left, matching the action more closely than "group_member_joined." This improvement helps communicate the event accurately.

containers/GroupScreenMembersTable.tsx (2)

81-85: Validate currentAccountIsAdmin logic when group membership changes.

The useMemo hook is correct for performance, but ensure that getAddressIsAdmin is updated/invalidated whenever group membership or permissions change. This helps avoid stale values if membership updates occur quickly.


211-211: Include currentAccountIsAdmin in effect or dependency checks if needed.

You have added currentAccountIsAdmin to the dependencies, which is correct for recalculating tableViewItems. Confirm that any side-effects or triggered reactions also handle the updated admin state.

@@ -1,6 +1,6 @@
import type { PermissionPolicySet } from "@xmtp/react-native-sdk/build/lib/types/PermissionPolicySet";

type MemberRole = "admin" | "super_admin" | "member";
type MemberRole = "admin" | "superAdmin" | "member";
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Update required: Multiple references to "super_admin" need to be changed

The codebase still contains multiple references to "super_admin" that need to be updated to maintain consistency with the new "superAdmin" naming convention. Here are the locations that require updates:

  • utils/groupUtils/getGroupMemberActions.ts: Translation key references
  • utils/groupUtils/adminUtils.ts: Permission level checks
  • utils/groupUtils/adminUtils.test.ts: Test case
  • queries/usePromoteToSuperAdminMutation.ts: Permission level assignment
  • screens/Profile.tsx: Translation key references
  • containers/GroupScreenMembersTable.tsx: Translation key reference
  • i18n/translations/en.ts and i18n/translations/fr.ts: Translation keys and values
🔗 Analysis chain

Renaming "super_admin" to "superAdmin" aligns with camelCase conventions.
This update maintains consistency. Ensure all references are updated.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify no lingering references to "super_admin" remain in the codebase.
rg "super_admin"

Length of output: 2014

@alexrisch alexrisch merged commit 1f3ce1f into release/3.0.0 Jan 2, 2025
6 checks passed
@alexrisch alexrisch deleted the ar/group-members-fix branch January 2, 2025 02:32
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