C
C#15mo ago
TJacken

✅ Mask data when solft delete is applied

Hi, is there any nuget package or EF Core feature which I can configure to mask data in database when I apply solft delete? When user request delete his data in database, due to the GDPR regulative I need to leave user data in database because of statistics data, but mask user sensitive data like first name, last name, e-mail, gender... Do you know any nuget for this or have idea how I can do this? I know I can manually do this to update every property I need. I suppose if nuget exists it should had custom attribute to mark data for mask after soft delete.
12 Replies
Angius
Angius15mo ago
Global query filters? That will allow you to apply, say, .Where(thing => thing.DeltedAt != null) to every query
Pobiega
Pobiega15mo ago
Thats a good step in the right direction (and there is a way to bypass the global filter for when you calculate statistics), but you'll still need to manually mask the records. But thats easy enough, instead of calling context.Remove(item); just fetch the item and call .Mask() on it, which can both do the masking and flag it as soft-deleted
Angius
Angius15mo ago
Ah, masking as in replacing emails with garbage data and what not, gotcha
Pobiega
Pobiega15mo ago
yes
TJacken
TJackenOP15mo ago
I know for global filter, as @Pobiega said I need some method which would mask data in database from name Lucas it need to rename it to AnonymousUser (for every user who will get IsDeleted flag).
Pobiega
Pobiega15mo ago
Apply a ICanBeMasked interface to all entities that need it, and have a Mask(); method in it you cant just apply a library and it'lll work automatically, as only you know what your entities look like and what info must be masked
Angius
Angius15mo ago
I mean, technically, a library could be looking for some [ShouldBeMasked] attribute and use reflections or codegen
Pobiega
Pobiega15mo ago
Sure, but thats more or less the same amount of work as writing your own masking method 😛
TJacken
TJackenOP15mo ago
Agree with you, I got idea create custom attribute MaskAttribute(string mask = "AnonymousUser") would apply this attribute over properties in User entity class. Override method for delete (custom method) and if soft delete is applied with reflection populate mask on right place and update data in database.
Pobiega
Pobiega15mo ago
Sourcegen seems like a good choice if you want an attribute thou
Omnissiah
Omnissiah15mo ago
i believe abp does it (if you inherit for his audit class), but if you just need that probably you would be better off doing it yourself i think
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server