✅ 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
Global query filters?
That will allow you to apply, say,
.Where(thing => thing.DeltedAt != null)
to every queryThats 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-deletedAh, masking as in replacing emails with garbage data and what not, gotcha
yes
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).
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 maskedI mean, technically, a library could be looking for some
[ShouldBeMasked]
attribute and use reflections or codegenSure, but thats more or less the same amount of work as writing your own masking method 😛
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.
Sourcegen seems like a good choice if you want an attribute thou
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
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.