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

Fixes #3558 NoMongo: Postgres Migration Support for Settings in orgDashboard #3597

Draft
wants to merge 3 commits into
base: develop-postgres
Choose a base branch
from

Conversation

gurramkarthiknetha
Copy link
Contributor

@gurramkarthiknetha gurramkarthiknetha commented Feb 14, 2025

What kind of change does this PR introduce?

Feature update: Updated queries and mutations to align with the recently migrated develop-postgres branch of talawa-api.

Issue Number:

Fixes #3558

Snapshots/Videos:
https://www.loom.com/share/a26e865e314d48b48336f1f9193c64c9?sid=7a7e550d-190e-488e-9c73-fbf1304c3e07
If relevant, did you update the documentation?

No

Summary

This PR updates the GraphQL schema to support the latest changes in the develop-postgres branch. The queries and mutations have been modified accordingly to ensure compatibility with the new structure.

Does this PR introduce a breaking change?

No, this PR does not introduce breaking changes.

Checklist

CodeRabbit AI Review

  • I have reviewed and addressed all critical issues flagged by CodeRabbit AI
  • I have implemented or provided justification for each non-critical suggestion
  • I have documented my reasoning in the PR comments where CodeRabbit AI suggestions were not implemented

Test Coverage

  • I have written tests for all new changes/features
  • I have verified that test coverage meets or exceeds 95%
  • I have run the test suite locally and all tests pass

Other information

N/A

Have you read the contributing guide?

Yes

Summary by CodeRabbit

  • New Features

    • Expanded data display for organizations and user profiles, now including detailed address, contact, and metadata.
    • Added new functionalities to retrieve organization events and custom field details.
  • Refactor

    • Streamlined update and deletion flows for organizations with enhanced validations and user notifications.
    • Simplified session timeout handling for a more consistent experience.
    • Improved language support by updating the Spanish language code.

Copy link
Contributor

coderabbitai bot commented Feb 14, 2025

Walkthrough

This pull request overhauls several GraphQL mutations and queries along with associated React components and utility interfaces. Mutation signatures are updated to use single input objects with expanded return fields, while queries are revised with new parameter names and additional data. Component logic is adjusted to accommodate these API changes, including simplified deletion checks and updated mock data. Minor utility updates include interface field reordering and a language code correction.

Changes

File(s) Change Summary
src/GraphQl/Mutations/OrganizationMutations.ts Updated mutation signatures for ADD_CUSTOM_FIELD and REMOVE_CUSTOM_FIELD: now using single input objects and returning expanded data (including id and organizationId).
src/GraphQl/Mutations/mutations.ts Revised mutations (UPDATE_ORGANIZATION, UPDATE_CURRENT_USER, DELETE_ORGANIZATION): consolidated parameters into input objects, expanded return fields, and commented out the old ADD_CUSTOM_FIELD variable.
src/GraphQl/Queries/PlugInQueries.ts
src/GraphQl/Queries/Queries.ts
Updated query signatures and parameter names; enhanced returned field sets; added new queries for custom fields and organization events; adjusted ordering parameter naming.
src/components/OrgSettings/General/DeleteOrg/DeleteOrg.tsx
src/components/OrgSettings/General/OrgUpdate/OrgUpdate.tsx
src/components/OrgSettings/General/OrgUpdate/OrgUpdateMocks.ts
src/components/UpdateSession/UpdateSession.tsx
Modified component logic to align with new GraphQL API structures: simplified deletion checks, updated mutation and query calls, adjusted state handling and mock data, and refined session timeout processing.
src/utils/interfaces.ts
src/utils/languages.ts
Updated InterfaceCustomFieldData by adding id and organizationId and repositioning type; corrected Spanish language code from 'sp' to 'es'.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant GraphQLAPI
    Client->>GraphQLAPI: Send CreateCustomField(input: {organizationId, name, type})
    GraphQLAPI-->>Client: Return customField { id, name, type, organizationId }
    Client->>GraphQLAPI: Send DeleteCustomField(input: { id })
    GraphQLAPI-->>Client: Return { success }
Loading
sequenceDiagram
    participant User
    participant Frontend
    participant GraphQLAPI
    User->>Frontend: Initiate organization deletion
    Frontend->>GraphQLAPI: Send DeleteOrganization(input: { id })
    GraphQLAPI-->>Frontend: Return deletion success status
    Frontend-->>User: Notify deletion result
Loading

Possibly related PRs

Suggested labels

ignore-sensitive-files-pr

Suggested reviewers

  • palisadoes

Poem

I'm a little rabbit on a code-filled spree,
Hopping through mutations so smoothly and free.
With input objects snugly wrapped around each field,
My GraphQL garden blooms, beautifully sealed.
A merry toast of carrots and code, hip-hip-hooray! 🐇

Happy coding from the bunny brigade!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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

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

🔭 Outside diff range comments (2)
src/components/OrgSettings/General/OrgUpdate/OrgUpdateMocks.ts (1)

202-202: ⚠️ Potential issue

Fix typo in error key name.

There's a typo in the error key name.

-    erorr: new Error('Mock Graphql Updating Organization Error'),
+    error: new Error('Mock Graphql Updating Organization Error'),
src/components/OrgSettings/General/OrgUpdate/OrgUpdate.tsx (1)

375-375: ⚠️ Potential issue

Remove code coverage disable statement.

Pipeline failure indicates presence of code coverage disable statement. Please remove it and add appropriate tests.

🧹 Nitpick comments (4)
src/GraphQl/Mutations/mutations.ts (1)

762-763: Avoid partial exports scattered across files.
Comment suggests these constants belong in another file. Consider moving all organization-related mutations into OrganizationMutations.ts to avoid confusion and keep the re-export consistent.

src/GraphQl/Queries/Queries.ts (1)

1015-1016: Comment about updating ORGANIZATION_CUSTOM_FIELDS.
You added a note indicating you’re updating a custom fields query. Make sure to remove or update this comment once the new query is finalized and integrated so it doesn’t become stale.

src/GraphQl/Mutations/OrganizationMutations.ts (2)

238-248: LGTM: Updated custom field creation mutation.

The mutation has been correctly updated to use the new input type and return structure for Postgres compatibility.

Update the JSDoc comment above the mutation to reflect the new input structure:

/**
 * GraphQL mutation to add a custom field to an organization.
 *
- * @param organizationId - The ID of the organization where the custom field is being added.
- * @param type - The type of the custom field (e.g., String, Number).
- * @param name - The name of the custom field.
+ * @param input - The input object containing organization ID, field type, and name.
 * @returns The added organization custom field object.
 */

261-264: LGTM: Updated custom field deletion mutation.

The mutation has been correctly simplified to use a single ID parameter and return a success status.

Update the JSDoc comment above the mutation to reflect the new parameter structure:

/**
 * GraphQL mutation to remove a custom field from an organization.
 *
- * @param organizationId - The ID of the organization from which the custom field is being removed.
- * @param customFieldId - The ID of the custom field to be removed.
+ * @param id - The ID of the custom field to be removed.
 * @returns The success status of the operation.
 */
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e609724 and 38b7219.

📒 Files selected for processing (10)
  • src/GraphQl/Mutations/OrganizationMutations.ts (2 hunks)
  • src/GraphQl/Mutations/mutations.ts (4 hunks)
  • src/GraphQl/Queries/PlugInQueries.ts (1 hunks)
  • src/GraphQl/Queries/Queries.ts (7 hunks)
  • src/components/OrgSettings/General/DeleteOrg/DeleteOrg.tsx (3 hunks)
  • src/components/OrgSettings/General/OrgUpdate/OrgUpdate.tsx (4 hunks)
  • src/components/OrgSettings/General/OrgUpdate/OrgUpdateMocks.ts (1 hunks)
  • src/components/UpdateSession/UpdateSession.tsx (1 hunks)
  • src/utils/interfaces.ts (1 hunks)
  • src/utils/languages.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
src/utils/languages.ts (2)
Learnt from: bandhan-majumder
PR: PalisadoesFoundation/talawa-admin#3593
File: src/utils/languages.ts:20-20
Timestamp: 2025-02-14T02:30:04.613Z
Learning: The language code for Spanish must remain as 'sp' (not 'es') to match the language enum defined in talawa-api backend.
Learnt from: bandhan-majumder
PR: PalisadoesFoundation/talawa-admin#3593
File: src/utils/languages.ts:20-20
Timestamp: 2025-02-14T02:30:04.613Z
Learning: The language code for Spanish must be 'sp' (not 'es') to match the schema in talawa-api backend.
🪛 GitHub Actions: PR Workflow
src/GraphQl/Queries/Queries.ts

[warning] 1-1: Code style issues found. Run Prettier with --write to fix.

src/GraphQl/Mutations/mutations.ts

[warning] 1-1: Code style issues found. Run Prettier with --write to fix.

src/components/OrgSettings/General/OrgUpdate/OrgUpdate.tsx

[error] 1-1: File contains code coverage disable statement. Please remove it and add the appropriate tests.

🔇 Additional comments (20)
src/GraphQl/Mutations/mutations.ts (3)

44-59: Consolidate organization update inputs.
Changing from multiple parameters to a single MutationUpdateOrganizationInput! is a clean approach. The expanded return fields look correct. Ensure that all consumers now pass an appropriate input object and handle the richer response in the UI or other layers as needed.


78-106: Verify the breadth of returned user fields.
You've added multiple fields (e.g., birthDate, isEmailAddressVerified). Make sure the user’s privacy settings allow retrieving these fields. Confirm that only authorized clients can access PII like birth date and phone numbers, and that data privacy laws and guidelines are followed.


252-257: Return of name upon deletion.
Returning the organization name alongside its ID here is a user-friendly choice for confirmations. Just confirm that deleteOrganization is only callable by authorized roles, as revealing the name of a deleted org could be sensitive in some edge cases.

src/GraphQl/Queries/Queries.ts (7)

6-35: Expanded CURRENT_USER query.
You’ve added numerous PII fields (e.g., birthDate, mobilePhoneNumber) to the query. Verify that your access controls protect these fields and that you truly need all these fields in the client. Exposing large amounts of user data can introduce privacy/security risks.


498-524: Use of a single input object for ORGANIZATIONS_LIST.
Switching to $input: QueryOrganizationInput! is consistent with a streamlined GraphQL design. Confirm that any existing calls are updated to supply this new input object.


707-724: Refined ORGANIZATION_EVENT_LIST query.
The query now takes $input: QueryOrganizationInput! and yields events with important fields. Ensure the front-end is updated to handle the new structure, particularly the startAt and endAt fields.


936-954: Updated GET_COMMUNITY_DATA with social media URLs.
Including the extended fields (e.g., X for Twitter) is beneficial. Double-check that these fields match your back-end schema naming conventions and that your UI is prepared to handle them (e.g., nulls if any fields are missing).
[approve]


974-980: Renamed query: CommunitySessionTimeout.
Switching from GET_COMMUNITY_SESSION_TIMEOUT_DATA_PG to GET_COMMUNITY_SESSION_TIMEOUT_DATA is clear. Ensure that any references in the client or docs are updated to the new name.


1017-1031: New ORGANIZATION_CUSTOM_FIELDS query.
Retrieving custom fields via organizationCustomFields is a good approach for clarity. Confirm your type definitions, particularly the type field, are aligned with the back end (string constants vs. enum).


1032-1045: New GET_ORGANIZATION_EVENTS query.
Exposing organization events at the top level with $input: QueryOrganizationInput! is consistent with other queries. Verify you handle absent or empty events gracefully in the UI.

src/components/OrgSettings/General/DeleteOrg/DeleteOrg.tsx (2)

59-60: LGTM: Query parameter renamed correctly.

The variable name change from isSampleOrganizationId to id aligns with the Postgres migration changes.


85-85: LGTM: Updated mutation input structure.

The mutation input structure has been updated to use an input object, which aligns with the Postgres migration changes.

src/components/OrgSettings/General/OrgUpdate/OrgUpdateMocks.ts (1)

14-14: LGTM: Updated field name for Postgres compatibility.

The change from _id to id correctly aligns with the Postgres database schema.

src/components/UpdateSession/UpdateSession.tsx (1)

78-85: LGTM: Simplified session timeout data access.

The changes improve code readability by:

  1. Simplifying the data access path
  2. Using clearer null/undefined checks
src/GraphQl/Queries/PlugInQueries.ts (1)

366-376:

❓ Verification inconclusive

Verify the query structure with backend schema.

The query has been updated to match the Postgres schema, but there are a few points to verify:

  1. The change from ID! to String! type
  2. The use of input object pattern input: { id: $id }
  3. The new fields being requested

🏁 Script executed:

#!/bin/bash
# Description: Check if the query structure matches the schema
# Look for other similar queries to verify the pattern
rg -A 5 "query.*\(\$id: String!\)" 

Length of output: 35


Verify Query Structure Consistency with Backend Schema

The update to IS_SAMPLE_ORGANIZATION_QUERY reflects the objectives for the Postgres migration by:

  • Changing the parameter from isSampleOrganizationId: ID! to id: String!
  • Adopting the input object pattern (input: { id: $id })
  • Expanding the requested fields to include id, name, description, and isSampleOrganization

Before merging, please manually verify:

  • That the backend GraphQL schema now expects a String! type for the id argument.
  • The use of the input object (input: { id: $id }) is consistent with similar queries.
  • All requested fields in the query are defined in the backend schema.
src/components/OrgSettings/General/OrgUpdate/OrgUpdate.tsx (4)

46-46: Component name follows React naming convention.

The function name has been updated from orgUpdate to OrgUpdate to follow React component naming convention.


23-34: Interface structure aligns with Postgres schema.

The new MutationUpdateOrganizationInput interface properly defines the structure for the organization update mutation, making all fields optional except id.


159-163: Good addition of form validation.

Added validation ensures that required fields are provided before submitting the update.


389-389: Improved loading state handling.

The save button is now properly disabled during the update operation and shows a loading state.

Also applies to: 392-392

src/utils/interfaces.ts (1)

1276-1281: Interface updated to match Postgres schema.

The InterfaceCustomFieldData has been properly updated with:

  • Added id field
  • Added organizationId field
  • Reordered properties to match schema

@@ -86,7 +108,7 @@ export const ORGANIZATION_CONNECTION_LIST = gql`
where: { name_contains: $filter }
first: $first
skip: $skip
orderBy: $orderBy
orderBy: $order
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential mismatch in variable usage.
This line uses orderBy: $order, but your query arguments define $orderBy: OrganizationOrderByInput. Either rename the variable or adjust the query input to avoid confusion or runtime errors.

-      orderBy: $order
+      orderBy: $orderBy
📝 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
orderBy: $order
orderBy: $orderBy

@@ -17,7 +17,7 @@ const languages = [
country_code: 'in',
},
{
code: 'sp',
code: 'es',
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Revert language code for Spanish.
Per the retrieved learnings, the back end expects 'sp' rather than 'es'. Changing this to 'es' may break the language selection or cause mismatches in the API. Revert to 'sp' per the existing schema.

-    code: 'es',
+    code: 'sp',
📝 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
code: 'es',
code: 'sp',

Comment on lines +43 to +44
// const canDelete = getItem('SuperAdmin');
const canDelete = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: Restore the super admin check for organization deletion.

Removing the super admin check creates a significant security vulnerability by allowing any user to delete organizations.

-// const canDelete = getItem('SuperAdmin');
-const canDelete = true;
+const canDelete = getItem('SuperAdmin');
📝 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
// const canDelete = getItem('SuperAdmin');
const canDelete = true;
const canDelete = getItem('SuperAdmin');

@palisadoes palisadoes changed the title fixed issue #3558 NoMongo: Postgres Migration Support for Settings in orgDashboard Fixes #3558 NoMongo: Postgres Migration Support for Settings in orgDashboard Feb 14, 2025
@gurramkarthiknetha gurramkarthiknetha marked this pull request as draft February 15, 2025 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In review
Development

Successfully merging this pull request may close these issues.

2 participants