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: affiliations when work experiences are deleted #2675

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

skwowet
Copy link
Member

@skwowet skwowet commented Nov 5, 2024

Changes proposed ✍️

What

copilot:summary

copilot:poem

Why

How

copilot:walkthrough

Checklist ✅

  • Label appropriately with Feature, Improvement, or Bug.
  • Add screenshots to the PR description for relevant FE changes
  • New backend functionality has been unit-tested.
  • API documentation has been updated (if necessary) (see docs on API documentation).
  • Quality standards are met.

Summary by CodeRabbit

  • New Features

    • Enhanced handling of organization affiliations by allowing the representation of deleted organizations.
    • Updated logic to include conditions for unaffiliating activities associated with deleted organizations.
  • Bug Fixes

    • Adjusted filtering logic to ensure only valid organizations are processed in updates.
  • Refactor

    • Renamed variable for clarity and improved understanding of its purpose.
    • Streamlined approach for assigning organization IDs based on matching conditions.

Copy link

coderabbitai bot commented Nov 5, 2024

Walkthrough

The changes in the pull request modify the runMemberAffiliationsUpdate function within the profiles_worker module. The orgId property in the Condition type is updated to accept a string or null, accommodating deleted organizations. The function now retrieves all member organizations, including deleted ones, and filters them to identify valid organizations. A new variable collects deleted organization IDs, and the logic for handling unaffiliating activities is adjusted accordingly. The variable memberOrganizations is renamed to validMemberOrganizations to better reflect its purpose.

Changes

File Path Change Summary
.../profiles_worker/index.ts - Modified orgId in Condition type from string to `string

Possibly related PRs

  • Org and member view updates (LFX-1664) #2660: This PR modifies the handling of organizations and members in the backend, which is related to the changes in the runMemberAffiliationsUpdate function that enhance organization ID handling and include deleted organizations.

Suggested labels

Improvement

Suggested reviewers

  • themarolt

Poem

In the meadow where we play,
Organizations come and sway.
Some may leave, but that's just fine,
We’ll track them all, in a line.
With valid friends, we hop and cheer,
For every change, we hold so dear! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6790878 and 834c4b6.

📒 Files selected for processing (1)
  • services/libs/data-access-layer/src/old/apps/profiles_worker/index.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • services/libs/data-access-layer/src/old/apps/profiles_worker/index.ts

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

@skwowet skwowet self-assigned this Nov 5, 2024
Copy link

@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: 0

🧹 Outside diff range and nitpick comments (2)
services/libs/data-access-layer/src/old/apps/profiles_worker/index.ts (2)

70-78: Consider more descriptive variable names.

While the logic is correct, consider renaming variables for better clarity:

  • allMemberOrganizationsmemberOrganizationsWithDeleted
  • deletedOrganizationIdsuniqueDeletedOrganizationIds
-  const allMemberOrganizations = await qx.select(
+  const memberOrganizationsWithDeleted = await qx.select(
     // ...
   )
-  const validMemberOrganizations = allMemberOrganizations.filter(org => !org.deletedAt)
+  const validMemberOrganizations = memberOrganizationsWithDeleted.filter(org => !org.deletedAt)

-  const deletedOrganizationIds = _.uniq(
+  const uniqueDeletedOrganizationIds = _.uniq(
-    allMemberOrganizations
+    memberOrganizationsWithDeleted
       .filter(org => org.deletedAt)
       .map(org => org.organizationId)
   )
🧰 Tools
🪛 GitHub Check: lint-format-services

[failure] 71-71:
Replace org with (org)


[failure] 75-75:
Replace ⏎······.filter(org·=>·org.deletedAt)⏎······.map(org·=>·org.organizationId) with .filter((org)·=>·org.deletedAt).map((org)·=>·org.organizationId),


81-89: LGTM: Proper handling of unaffiliation for deleted organizations.

The implementation correctly creates conditions to unaffiliate activities associated with deleted organizations. Consider applying the suggested formatting for consistency:

     ..._.chain(deletedOrganizationIds)
-      .map(orgId => ({
+      .map((orgId) => ({
         when: [`'organizationId'::text = '${orgId}'`],
-        matches: (activity) => activity.organizationId === orgId,
+        matches: (activity) => activity.organizationId === orgId,
         orgId: null,
       }))
       .value(),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d228e2c and 98c4d0d.

📒 Files selected for processing (1)
  • services/libs/data-access-layer/src/old/apps/profiles_worker/index.ts (5 hunks)
🧰 Additional context used
🪛 GitHub Check: lint-format-services
services/libs/data-access-layer/src/old/apps/profiles_worker/index.ts

[failure] 71-71:
Replace org with (org)


[failure] 75-75:
Replace ⏎······.filter(org·=>·org.deletedAt)⏎······.map(org·=>·org.organizationId) with .filter((org)·=>·org.deletedAt).map((org)·=>·org.organizationId),

🔇 Additional comments (3)
services/libs/data-access-layer/src/old/apps/profiles_worker/index.ts (3)

43-43: LGTM: Type modification enables proper handling of deleted organizations.

The change to allow null values for orgId in the Condition type is appropriate for supporting the unaffiliation of activities when organizations are deleted.


55-69: LGTM: Query modification properly retrieves deletion status.

The addition of deletedAt and createdAt columns enables proper filtering of organizations based on their deletion status while maintaining the existing ordering.


Line range hint 145-150: LGTM: Fallback organization logic properly handles valid organizations.

The change correctly uses filtered valid organizations for fallback selection. Let's verify that this change doesn't affect existing fallback behavior.

✅ Verification successful

Based on the search results, I can see that the fallback organization logic is unique to this specific file and there are no other implementations or direct dependencies on this logic in the codebase. The change from memberOrganizations to validMemberOrganizations is localized to this function and doesn't affect other parts of the codebase.

Let me verify if there are any other references to this fallback logic:


LGTM: Fallback organization logic is self-contained and correctly implemented.

The change from memberOrganizations to validMemberOrganizations is localized to this function, and the fallback selection logic is only used within this file. The implementation maintains the same filtering, sorting, and selection behavior, ensuring backward compatibility. The search results confirm that there are no other similar patterns or dependencies on this logic elsewhere in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the fallback organization selection behavior
# Test: Check for any direct usage of memberOrganizations for fallback logic
rg -A 5 "memberOrganizations.*fallback" 

# Test: Check for any other implementations of fallback organization selection
ast-grep --pattern 'const fallbackOrganizationId = $_'

Length of output: 49292


Script:

#!/bin/bash
# Check for any references to fallbackOrganizationId
rg -A 3 "fallbackOrganizationId"

# Check for any similar patterns of organization selection
ast-grep --pattern 'chain($_)
  .filter((row) => !row.dateStart && !row.dateEnd)
  .sortBy($$$)
  .map($$$)
  .head()'

Length of output: 1407

Copy link
Contributor

@sausage-todd sausage-todd left a comment

Choose a reason for hiding this comment

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

Other than that, lgtm

Copy link

@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 UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 98c4d0d and 6790878.

📒 Files selected for processing (1)
  • services/libs/data-access-layer/src/old/apps/profiles_worker/index.ts (3 hunks)
🔇 Additional comments (1)
services/libs/data-access-layer/src/old/apps/profiles_worker/index.ts (1)

43-43: Ensure all usages of Condition handle orgId as nullable

Changing the orgId property in the Condition type from string to string | null means that orgId can now be null. Verify that all parts of the code that use Condition are updated to handle a null orgId to prevent potential runtime errors.

Run the following script to identify all usages of Condition:

✅ Verification successful

Let me search for the actual usage of the Condition type and its implementation to verify how orgId is handled.


Let me modify the search to handle the special characters properly.


After analyzing the code, I can now provide the final response:

The nullable orgId is already properly handled throughout the codebase

The Condition type is only used locally within the runMemberAffiliationsUpdate function, and all its usages properly handle the nullable orgId:

  • The condition function uses nullableOrg helper which explicitly handles null cases
  • The insertIfMatches function initializes activity.organizationId as null by default
  • The SQL query uses COALESCE to handle null organization IDs
  • The orgCases array construction properly passes the potentially null organizationId values
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all usages of 'Condition' type to ensure they handle 'orgId' being nullable.

# Search for usages of 'Condition' type in the codebase.
rg 'Condition'

Length of output: 6438


Script:

#!/bin/bash
# Search for the implementation and usage of the Condition type specifically in the profiles_worker
rg -A 10 'type Condition = {' services/libs/data-access-layer/src/old/apps/profiles_worker/index.ts

Length of output: 201


Script:

#!/bin/bash
# Search for the implementation and usage of the Condition type in profiles_worker
cat services/libs/data-access-layer/src/old/apps/profiles_worker/index.ts

Length of output: 7776

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