Skip to content

Middleware to anonymize soft-deleted users#392

Merged
doomlab merged 9 commits intodevfrom
middleware
Feb 4, 2025
Merged

Middleware to anonymize soft-deleted users#392
doomlab merged 9 commits intodevfrom
middleware

Conversation

@marton-balazs-kovacs
Copy link
Contributor

We decided to allow to soft-delete users from projects. In this PR I mainly focused on the backend functionality of the soft-delete feautre, in future PRs the UI should be updated to make it clear to our users that soft-delete (or inactive, suggested by @chartgerink) does not mean that there information is deleted from the db.

To avoid showing the name of soft-deleted users on a project I implemented several safeguards:

  • If the projectmember prisma model is queried without an explicit deleted key defined in the where argument, deleted: false is added by a prisma middleware.
  • I created a recursive function to anonymize User names if the users are returned from nested prisma queries. The anonymization now happens in the query, instead in the component code, which makes it safer if the query is reused across multiple components.
  • The getName function that we use to decide whether the username or firstname and lastname are shown also replaces the returned name if the projectmember is deleted.

Copy link
Member

@chartgerink chartgerink left a comment

Choose a reason for hiding this comment

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

Upon review, the code seems to make sense for what you are doing. It would be helpful to have a few test cases run to showcase things work as expected at this stage. Those tests will also be helpful to add to if bugs pop up.

@doomlab
Copy link
Member

doomlab commented Jan 27, 2025

I think Chris would know more about this than me, so let me know @marton-balazs-kovacs when you update the files, and I'll push it forward.

@doomlab doomlab merged commit 263b193 into dev Feb 4, 2025
1 check passed
@doomlab doomlab deleted the middleware branch May 29, 2025 23:10
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.

3 participants