Skip to content

Commit

Permalink
PT-6139: Add payment and shipment addresses for anonymize and downloa…
Browse files Browse the repository at this point in the history
…d data (#7)

* fix: Add payment and shipment addresses for anonymize and download data

* fix: Fix saving CreatedBy, ModifiedBy
  • Loading branch information
einlied753 authored Jan 19, 2022
1 parent 6fe47fa commit 37c82a7
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/VirtoCommerce.GDPR.Core/Models/DownloadData/Address.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace VirtoCommerce.GDPR.Core.Models.DownloadData
/// </summary>
public class Address
{
public string Name { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Country { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions src/VirtoCommerce.GDPR.Core/Models/DownloadData/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ public class Order
public string CreatedBy { get; set; }
public string ModifiedBy { get; set; }
public ICollection<Address> Addresses { get; set; }
public ICollection<Address> InPayments { get; set; }
public ICollection<Address> Shipments { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using EntityFrameworkCore.Triggers;
using Microsoft.AspNetCore.Identity;
using VirtoCommerce.CustomerModule.Core.Model;
using VirtoCommerce.CustomerModule.Core.Services;
Expand Down Expand Up @@ -56,14 +57,14 @@ public async Task<Contact> AnonymizeContactDataAsync(string id)
contact.FirstName = _anonymName;
contact.LastName = _anonymName;
contact.FullName = _anonymName;
contact.CreatedBy = _anonymName;
contact.ModifiedBy = _anonymName;

contact.BirthDate = null;
contact.Emails = new List<string>();
contact.Phones = new List<string>();
contact.IsAnonymized = true;
foreach (var address in contact.Addresses)
{
address.Name = _anonymName;
address.FirstName = _anonymName;
address.LastName = _anonymName;
address.City = _anonymName;
Expand All @@ -78,18 +79,15 @@ public async Task<Contact> AnonymizeContactDataAsync(string id)
{
user.UserName = $"{_anonymName}_{Guid.NewGuid():N}";
user.Email = GetRandomEmail();
user.CreatedBy = _anonymName;
user.ModifiedBy = _anonymName;
}

foreach (var result in customerOrdersSearchResult.Results)
{
result.CustomerName = _anonymName;
result.CreatedBy = _anonymName;
result.ModifiedBy = _anonymName;

foreach (var orderAddress in result.Addresses)
{
orderAddress.Name = _anonymName;
orderAddress.FirstName = _anonymName;
orderAddress.LastName = _anonymName;
orderAddress.City = _anonymName;
Expand All @@ -99,8 +97,46 @@ public async Task<Contact> AnonymizeContactDataAsync(string id)
orderAddress.Email = GetRandomEmail();
orderAddress.Phone = _anonymPhone;
}

foreach (var payment in result.InPayments)
{
if (payment.BillingAddress != null)
{
payment.BillingAddress.Name = _anonymName;
payment.BillingAddress.FirstName = _anonymName;
payment.BillingAddress.LastName = _anonymName;
payment.BillingAddress.City = _anonymName;
payment.BillingAddress.Line1 = _anonymName;
payment.BillingAddress.Line2 = _anonymName;
payment.BillingAddress.PostalCode = _anonymPostalCode;
payment.BillingAddress.Email = GetRandomEmail();
payment.BillingAddress.Phone = _anonymPhone;
}
}

foreach (var shipment in result.Shipments)
{
if (shipment.DeliveryAddress != null)
{
shipment.DeliveryAddress.Name = _anonymName;
shipment.DeliveryAddress.FirstName = _anonymName;
shipment.DeliveryAddress.LastName = _anonymName;
shipment.DeliveryAddress.City = _anonymName;
shipment.DeliveryAddress.Line1 = _anonymName;
shipment.DeliveryAddress.Line2 = _anonymName;
shipment.DeliveryAddress.PostalCode = _anonymPostalCode;
shipment.DeliveryAddress.Email = GetRandomEmail();
shipment.DeliveryAddress.Phone = _anonymPhone;
}
}
}

Triggers<IAuditable>.Updating += entry =>
{
entry.Entity.CreatedBy = _anonymName;
entry.Entity.ModifiedBy = _anonymName;
};

await _memberService.SaveChangesAsync(new[] { contact });
await _customerOrderService.SaveChangesAsync(customerOrdersSearchResult.Results.ToArray());
foreach (var user in contact.SecurityAccounts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public async Task<Customer> GetContactDataAsync(string id)
ModifiedBy = contact.ModifiedBy,
Addresses = contact.Addresses.Select(add => new Core.Models.DownloadData.Address
{
Name = add.Name,
FirstName = add.FirstName,
LastName = add.LastName,
Country = add.CountryName,
Expand Down Expand Up @@ -83,6 +84,7 @@ public async Task<Customer> GetContactDataAsync(string id)
ModifiedBy = o.ModifiedBy,
Addresses = o.Addresses.Select(a => new Core.Models.DownloadData.Address
{
Name = a.Name,
FirstName = a.FirstName,
LastName = a.LastName,
Country = a.CountryName,
Expand All @@ -93,7 +95,35 @@ public async Task<Customer> GetContactDataAsync(string id)
ZipCode = a.PostalCode,
Email = a.Email,
Phone = a.Phone
}).ToList()
}).ToList(),
InPayments = o.InPayments.Select(p => new Core.Models.DownloadData.Address
{
Name = p.BillingAddress?.Name,
FirstName = p.BillingAddress?.FirstName,
LastName = p.BillingAddress?.LastName,
Country = p.BillingAddress?.CountryName,
Region = p.BillingAddress?.RegionName,
City = p.BillingAddress?.City,
Line1 = p.BillingAddress?.Line1,
Line2 = p.BillingAddress?.Line2,
ZipCode = p.BillingAddress?.PostalCode,
Email = p.BillingAddress?.Email,
Phone = p.BillingAddress?.Phone
}).ToList(),
Shipments = o.Shipments.Select(s => new Core.Models.DownloadData.Address
{
Name = s.DeliveryAddress?.Name,
FirstName = s.DeliveryAddress?.FirstName,
LastName = s.DeliveryAddress?.LastName,
Country = s.DeliveryAddress?.CountryName,
Region = s.DeliveryAddress?.RegionName,
City = s.DeliveryAddress?.City,
Line1 = s.DeliveryAddress?.Line1,
Line2 = s.DeliveryAddress?.Line2,
ZipCode = s.DeliveryAddress?.PostalCode,
Email = s.DeliveryAddress?.Email,
Phone = s.DeliveryAddress?.Phone
}).ToList(),
});
}).ToList()
};
Expand Down

0 comments on commit 37c82a7

Please sign in to comment.