C
C#10mo 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
Angius10mo ago
Global query filters? That will allow you to apply, say, .Where(thing => thing.DeltedAt != null) to every query
Pobiega
Pobiega10mo 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
Angius10mo ago
Ah, masking as in replacing emails with garbage data and what not, gotcha
Pobiega
Pobiega10mo ago
yes
TJacken
TJacken10mo 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
Pobiega10mo 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
Angius10mo ago
I mean, technically, a library could be looking for some [ShouldBeMasked] attribute and use reflections or codegen
Pobiega
Pobiega10mo ago
Sure, but thats more or less the same amount of work as writing your own masking method 😛
TJacken
TJacken10mo 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
Pobiega10mo ago
Sourcegen seems like a good choice if you want an attribute thou
not guilty
not guilty10mo 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
Accord10mo 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.