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

Implemented correct user roles Fixes #3106 #3111

Merged

Conversation

raggettii
Copy link
Contributor

@raggettii raggettii commented Jan 1, 2025

What kind of change does this PR introduce?
It introduces correct role for admin and user.

Issue Number:

Fixes #3106

Did you add tests for your changes?
Yes

Snapshots/Videos:
image

If relevant, did you update the documentation?

Summary

Does this PR introduce a breaking change?

Other information

Have you read the contributing guide?

Summary by CodeRabbit

  • Bug Fixes

    • Improved user authentication handling in the app.
    • Enhanced member data management and filtering in the People component.
  • New Features

    • Added a route for leaving an organization in the user portal.
  • Refactor

    • Replaced __typename with a more descriptive userType property.
    • Enhanced state management for members and admins.
  • Tests

    • Removed deprecated property validation tests.
    • Maintained core component rendering and interaction tests.

Copy link
Contributor

coderabbitai bot commented Jan 1, 2025

Walkthrough

The pull request enhances user role management in the People component by updating the InterfaceMember interface to replace the __typename property with a userType property, differentiating 'Admin' and 'Member' roles. It introduces new state variables allMembers and admins for effective data management and updates useEffect hooks to correctly assign user types based on roles. Additionally, the authentication handling in App.tsx is improved, and a new route for leaving an organization is added.

Changes

File Change Summary
src/screens/UserPortal/People/People.spec.tsx Removed InterfaceMember type import and deleted compareProperties function and associated tests.
src/screens/UserPortal/People/People.tsx Updated InterfaceMember interface to include userType, added allMembers and admins states, and modified data processing logic to assign userType.
src/App.tsx Updated authentication handling and added a new route for leaving an organization.

Assessment against linked issues

Objective Addressed Explanation
Display correct admin role [#3106]
Differentiate between admin and member roles

Possibly related PRs

  • fix: removed unused references of group chat and direct chat #2394: The main PR involves the removal of the InterfaceMember type and related functionality, which aligns with the focus of this PR on cleaning up unused references to chat functionalities, indicating a broader effort to streamline the codebase by removing unnecessary types and references.

Suggested reviewers

  • pranshugupta54
  • palisadoes

Poem

🐰 In the realm of code, a rabbit's delight,
Roles now shine clear and ever so bright!
From hidden types to roles displayed true,
Admin or Member, we've fixed the view!
A hop of progress, a leap of glee! 🌟


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 16a9bb7 and 2103c33.

📒 Files selected for processing (1)
  • src/App.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/App.tsx

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.

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

github-actions bot commented Jan 1, 2025

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

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 (2)
src/screens/UserPortal/People/People.spec.tsx (1)

14-14: Remove or clarify the commented import.
The InterfaceMember import is no longer used. Consider removing it altogether to avoid confusion and maintain a clean codebase.

src/screens/UserPortal/People/People.tsx (1)

25-31: Consider using a more specific type for userType.
Currently, userType is a free-form string. Since it seems to only accept 'Admin' or 'Member', using a string-literal union or an enum would help prevent accidental misspellings or other invalid values.

-interface InterfaceMember {
+type UserType = 'Admin' | 'Member';

-interface InterfaceMember {
   firstName: string;
   lastName: string;
   image: string;
   _id: string;
   email: string;
-  userType: string;
+  userType: UserType;
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a60179f and f7079bb.

📒 Files selected for processing (2)
  • src/screens/UserPortal/People/People.spec.tsx (1 hunks)
  • src/screens/UserPortal/People/People.tsx (4 hunks)
🔇 Additional comments (6)
src/screens/UserPortal/People/People.tsx (6)

53-55: Good separation of concerns with multiple state variables.
Having separate states for members, allMembers, and admins can improve clarity. Make sure to keep them in sync and avoid redundant data transformations.


137-146: Verify multiple admins scenario.
This logic currently handles only one admin (data2.organizations[0].admins[0]). If your application must handle multiple admins, consider mapping over each admin rather than storing a single one.

Would you like a script to search for references to this admin array usage in other files, confirming whether multi-admin scenarios need to be addressed elsewhere?


150-159: User type assignment seems correct.
The code updates each member’s userType to 'Member' by default unless already 'Admin'. This appears consistent with the PR’s objective of clarifying roles.


183-183: All members list assignment is correct.
When the mode is 0 (All Members), assigning allMembers to members correctly reflects the entire list.


187-187: Admin assignment logic is consistent with the selected mode.
When the mode is 1 (Admins), assigning admins to members ensures the screen only shows admin users. Keep in mind the multi-admin suggestion above.


279-279: Role property usage shows clarity of user type.
Using member.userType for the role field ensures that the UI reflects the newly introduced userType. This aligns with the PR’s goal of displaying correct roles.

src/screens/UserPortal/People/People.tsx Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jan 1, 2025

Codecov Report

Attention: Patch coverage is 97.05882% with 1 line in your changes missing coverage. Please review.

Project coverage is 89.32%. Comparing base (a60179f) to head (2103c33).
Report is 6 commits behind head on develop-postgres.

Files with missing lines Patch % Lines
src/screens/UserPortal/People/People.tsx 95.23% 1 Missing ⚠️
Additional details and impacted files
@@                  Coverage Diff                  @@
##           develop-postgres    #3111       +/-   ##
=====================================================
+ Coverage             25.37%   89.32%   +63.95%     
=====================================================
  Files                   301      322       +21     
  Lines                  7623     8451      +828     
  Branches               1667     1843      +176     
=====================================================
+ Hits                   1934     7549     +5615     
+ Misses                 5562      669     -4893     
- Partials                127      233      +106     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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: 2

🧹 Nitpick comments (2)
src/App.tsx (2)

202-205: Route for leaving an organization.
Adding a dedicated route to leave an organization is good for clarity, but confirm you have proper role checks. For instance, a user should presumably not be able to leave if they are the only admin in an org.


218-218: Commented code for chat route.
The chat feature appears to be commented out. If it’s not intended for near-future release, consider removing or move it to a separate WIP branch. This will help maintain a cleaner codebase.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f7079bb and a5c1185.

📒 Files selected for processing (2)
  • src/App.tsx (5 hunks)
  • src/screens/UserPortal/People/People.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/screens/UserPortal/People/People.tsx
🔇 Additional comments (5)
src/App.tsx (5)

33-33: Good use of useEffect import.
The addition of useEffect from react is consistent with the usage below and follows React best practices.


42-43: GraphQL queries are now integrated properly.
The useQuery hook and CHECK_AUTH import appear correct; this is a clean way to fetch authentication data via GraphQL. Confirm that the environment and server endpoints are correctly configured to avoid runtime errors.


53-53: New import for organization exit functionality.
LeaveOrganization is introduced here. Ensure that the logic in this component adequately handles edge cases such as a user leaving an org when they're the sole admin, or membership is mandatory under certain conditions.


55-55: Initialization of useLocalStorage.
Consider verifying that getItem calls (if any) happen in a safe manner. Currently, only setItem usage is shown. This looks straightforward, but keep an eye on potential stale or missing data issues.


102-113: Data-driven authentication setup.
Storing user info in local storage is a reasonable approach for quick session management. However, ensure session tokens or other sensitive credentials, if present, are not inadvertently exposed. If a token is being used, consider using HTTP-only cookies for stronger security.

src/App.tsx Show resolved Hide resolved
src/App.tsx Show resolved Hide resolved
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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a5c1185 and 5e991fb.

📒 Files selected for processing (1)
  • src/screens/UserPortal/People/People.tsx (4 hunks)
🔇 Additional comments (5)
src/screens/UserPortal/People/People.tsx (5)

25-32: LGTM: Interface changes align with role management requirements

The InterfaceMember interface has been correctly updated to use userType for role management.


50-52: LGTM: Well-structured state management

The state variables are properly typed and follow a clear separation of concerns between all members, filtered members, and admins.


126-136: LGTM: Proper member data handling

The member data processing correctly preserves existing userType while mapping the data.


248-248: LGTM: UI correctly displays user roles

The PeopleCard component now properly uses the userType property for role display.


114-123: ⚠️ Potential issue

Fix admin data handling to support multiple admins

The current implementation assumes only one admin exists by accessing data2.organizations[0].admins[0]. This could lead to missing other admins in the organization.

Consider updating the code to handle multiple admins:

 useEffect(() => {
   if (data2) {
-    const admin = data2.organizations[0].admins[0];
-    const updatedAdmin: InterfaceMember = {
-      ...admin,
-      userType: 'Admin',
-    };
-    setAdmins([updatedAdmin]);
+    const updatedAdmins = data2.organizations[0].admins.map((admin: any) => ({
+      ...admin,
+      userType: 'Admin',
+    }));
+    setAdmins(updatedAdmins);
   }
 }, [data2]);

Likely invalid or redundant comment.

src/screens/UserPortal/People/People.tsx Show resolved Hide resolved
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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5e991fb and 16a9bb7.

📒 Files selected for processing (2)
  • src/App.tsx (4 hunks)
  • src/screens/UserPortal/People/People.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/screens/UserPortal/People/People.tsx
🔇 Additional comments (3)
src/App.tsx (3)

100-100: Make sure to handle GraphQL errors.

The useQuery(CHECK_AUTH) currently destructures { data, loading }. Consider also handling the error property to ensure fallback logic or user notifications are invoked if the query fails or returns an error.


104-111: Validate security of user data in local storage.

While useLocalStorage is convenient, consider encrypting or carefully handling sensitive user data (e.g., email, ID) to mitigate potential security vulnerabilities.


202-205: Verify LeaveOrganization component integration.

The route for leaving an organization is correctly added and secured. However, please ensure:

  1. The LeaveOrganization component handles the orgId parameter correctly
  2. There are proper confirmations before leaving an organization
  3. The component updates the user's organization list after successful operation

Run the following script to verify the component implementation:

✅ Verification successful

LeaveOrganization component is well-implemented with all required safeguards

The component implementation has been verified and includes all the necessary features:

  1. ✓ Correctly handles orgId parameter using useParams hook
  2. ✓ Implements a two-step confirmation process:
    • Initial confirmation dialog
    • Email verification step
  3. ✓ Proper error handling with:
    • Network error handling
    • Email verification validation
    • Loading states
  4. ✓ Updates user's organization list after leaving via refetchQueries
  5. ✓ Navigates to organizations page after successful operation
  6. ✓ Uses toast notifications for success feedback

The implementation is robust and includes additional safety features like keyboard support, loading states, and accessibility attributes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify LeaveOrganization component implementation

# Check if the component handles orgId parameter
ast-grep --pattern 'const { orgId } = useParams()' 'screens/UserPortal/LeaveOrganization/LeaveOrganization.tsx'

# Check for confirmation dialog
ast-grep --pattern 'confirm($$$)' 'screens/UserPortal/LeaveOrganization/LeaveOrganization.tsx'

# Check for proper error handling
ast-grep --pattern 'catch($$$)' 'screens/UserPortal/LeaveOrganization/LeaveOrganization.tsx'

# Check for navigation after leaving
ast-grep --pattern 'navigate($$$)' 'screens/UserPortal/LeaveOrganization/LeaveOrganization.tsx'

Length of output: 819


Script:

#!/bin/bash
# Let's first find the correct location of the LeaveOrganization component
fd -e tsx -e ts -e js -e jsx LeaveOrganization

# Once we find the file, let's see its content
fd -e tsx -e ts -e js -e jsx LeaveOrganization --exec cat {}

Length of output: 22869

src/App.tsx Outdated Show resolved Hide resolved
@raggettii
Copy link
Contributor Author

@coderabbitai resolve

Copy link
Contributor

coderabbitai bot commented Jan 1, 2025

✅ Actions performed

Comments resolved and changes approved.

@raggettii
Copy link
Contributor Author

@palisadoes all checks passed please review
image

@palisadoes palisadoes merged commit cbba422 into PalisadoesFoundation:develop-postgres Jan 1, 2025
16 checks passed
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