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: Remove duplicate org users #10198

Merged
merged 3 commits into from
Sep 16, 2024
Merged

Conversation

Dschoordsch
Copy link
Contributor

@Dschoordsch Dschoordsch commented Sep 9, 2024

Description

Fixes #9302
Add a constraint that forbids duplicate organization users. There is no need to have multiple entries as the join/leave events are already captured in OrganizationUserAudit.

Demo

[If possible, please include a screenshot or gif/video, it'll make it easier for reviewers to understand the scope of the changes and how the change is supposed to work. If you're introducing something new or changing the existing patterns, please share a Loom and explain what decisions you've made and under what circumstances]

Testing scenarios

  • Remove a user Joe from an organization
  • Add Joe again
  • check that Joe can see the org correctly

Final checklist

  • I checked the code review guidelines
  • I have added Metrics Representative as reviewer(s) if my PR invovles metrics/data/analytics related changes
  • I have performed a self-review of my code, the same way I'd do it for any other team member
  • I have tested all cases I listed in the testing scenarios and I haven't found any issues or regressions
  • Whenever I took a non-obvious choice I added a comment explaining why I did it this way
  • I added the label Skip Maintainer Review Indicating the PR only requires reviewer review and can be merged right after it's approved if the PR introduces only minor changes, does not contain any architectural changes or does not introduce any new patterns and I think one review is sufficient'
  • PR title is human readable and could be used in changelog

Add a constraint that forbids duplicate organization users. There is no
need to have multiple entries as the join/leave events are already
captured in OrganizationUserAudit.
@github-actions github-actions bot added the size/s label Sep 9, 2024
When joining an organization, we want to reuse the OrganizationUser and
reset all necessary fields.
Comment on lines +80 to +89
.onConflict((oc) =>
oc.constraint('unique_org_user').doUpdateSet({
joinedAt: sql`CURRENT_TIMESTAMP`,
removedAt: null,
inactive: false,
role: null,
suggestedTier: null,
tier: (eb) => eb.ref('excluded.tier')
})
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm mostly concerned with this part. Previously we just created a new org user when a new user joined, but now we have to reset all the old fields that should be reset.

Copy link
Member

Choose a reason for hiding this comment

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

LGTM! i don't think we use trialStartDate anymore so we can ignore that column.

@Dschoordsch Dschoordsch requested review from mattkrick and removed request for nickoferrall September 12, 2024 08:11
@Dschoordsch Dschoordsch merged commit cafbf32 into master Sep 16, 2024
8 checks passed
@Dschoordsch Dschoordsch deleted the fix/9302/noDuplicateOrgUsers branch September 16, 2024 06:47
@github-actions github-actions bot mentioned this pull request Sep 17, 2024
24 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: duplicate OrganizationUser objects are created in some cases
2 participants