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: add postgres triggers to remove deleted users from user_links #12117

Merged
merged 27 commits into from
Feb 20, 2024

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Feb 13, 2024

What this does

  • Removes ability to un-delete a user. We never exposed this outside the db layer, doing this to make that decision something that takes more thought than just changing an api param.
  • User_links should not longer exist for deleted users.

Copy link
Member Author

Emyrk commented Feb 13, 2024

@Emyrk Emyrk force-pushed the stevenmasley/deleted_user_links branch from 4113828 to b7fd329 Compare February 13, 2024 15:48
@Emyrk Emyrk changed the title fix: add postgres triggers to keep user_links clear of deleted users fix: add postgres triggers to remove deleted users from user_links Feb 13, 2024
@Emyrk Emyrk marked this pull request as ready for review February 13, 2024 17:01
@kylecarbs
Copy link
Member

Why are we removing the ability to undelete a user?

@Emyrk
Copy link
Member Author

Emyrk commented Feb 13, 2024

@kylecarbs

Why are we removing the ability to undelete a user?

We never exposed this via the CLI or the API. It only exists in the DB query.

However, un-deleting a user is more work than just the query that I removed. It can now collide with existing users, their user_links were not correct, and now deleted.

Essentially undeleting a user can cause issues (if it can succeed at all), so we never supported it. And we should remove the query that will very likely fail in prod. I fear someone would just add a query param, use the existing query, merge it (because we do not test deleted users very much in tests). Then almost immediately it'll cause issues in an actual database.

@kylecarbs
Copy link
Member

I know we never supported it, but it feels odd to keep the soft delete and a real delete. Can we change it to completely do one or the other?

@Emyrk
Copy link
Member Author

Emyrk commented Feb 13, 2024

I know we never supported it, but it feels odd to keep the soft delete and a real delete. Can we change it to completely do one or the other?

We do not support hard deletes at all on most resources. For auditing purposes, we need to keep these objects around.

@kylecarbs
Copy link
Member

@Emyrk I'm confused why we should then on users. It seems like a fork in the road. It seems better to either leave this and not permit undeleting a user (e.g. actually blocking it), or making it work instead of allowing it for a single resource type.

@Emyrk
Copy link
Member Author

Emyrk commented Feb 13, 2024

I do not totally follow.

The product feature set is unchanged. We previously only supported soft deleting users from the API. I just made the DB query reflect this, so now you cannot un-delete users even from a DB query. So just trying to prevent developer error.

The user_links cleanup is because a deleted user should not be able to authenticate into Coder anymore. This becomes problematic if this is allowed because then a single github user can have multiple accounts linked to it. Maybe this is ok? Just felt strange from a data POV, so I implemented this to clean it up in the same way we do api keys.

Base automatically changed from stevenmasley/linked_id_fix to main February 13, 2024 19:02
@Emyrk Emyrk force-pushed the stevenmasley/deleted_user_links branch from 56b8a0d to a54b652 Compare February 13, 2024 19:38
@Emyrk Emyrk requested a review from kylecarbs February 16, 2024 14:37
Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

Even though it is idiomatic with our data structure, I'm a bit nervous about having a term "soft delete" in one resource, even though I know we have it in others.

We've coined the term deleted as a soft-delete already. And since we called it UpdateDeleted I feel like it's a bit more confusing to call this SoftDelete now.

A few questions:

  1. Can we just fix this in the Go code? Do we need to have the triggers added? It seems harder to test, and more spread complexity.
  2. Is it alright if we continue to use UpdateDeleted instead of SoftDelete? Does my rationale make sense in this context?

@Emyrk
Copy link
Member Author

Emyrk commented Feb 20, 2024

  1. Is it alright if we continue to use UpdateDeleted instead of SoftDelete? Does my rationale make sense in this context?

How about I return the name to UpdateUserDeletedByID but always make it do deleted = true? So there is no argument to ever revert the deleted state?

@kylecarbs
Copy link
Member

That sounds good to me!

@Emyrk Emyrk merged commit 2dac342 into main Feb 20, 2024
24 checks passed
@Emyrk Emyrk deleted the stevenmasley/deleted_user_links branch February 20, 2024 19:19
@github-actions github-actions bot locked and limited conversation to collaborators Feb 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants