Skip to content

Commit

Permalink
PT-10449: Use updated Crud and Search services (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-dudarev authored Jul 26, 2023
1 parent 631db98 commit f97f906
Show file tree
Hide file tree
Showing 26 changed files with 159 additions and 253 deletions.
84 changes: 75 additions & 9 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@ root = true
[*]
charset = utf-8
indent_style = space
indent_size = 4
indent_size = 2
end_of_line = crlf
trim_trailing_whitespace = true
insert_final_newline = true

# Project files
[*.csproj]
indent_size = 2
[*.{csproj,props}]
insert_final_newline = false

# JSON files
[*.json]
indent_size = 2
# HTML files
[*.{html,htm}]
insert_final_newline = false

# Configuration files
[*.config]
indent_size = 2
# Code
[*.{cs,js,ts,ps1,sh,bat,cmd}]
indent_size = 4

# Dotnet code style settings
[*.{cs,vb}]
Expand Down Expand Up @@ -101,3 +100,70 @@ csharp_space_between_parentheses = false

csharp_preserve_single_line_statements = false
csharp_preserve_single_line_blocks = true
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent

[*.{cs,vb}]
#### Naming styles ####

# Naming rules

dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

# Symbol specifications

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_namespace_match_folder = true:suggestion
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
9 changes: 6 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?xml version="1.0" encoding="utf-8"?><Project>
<?xml version="1.0" encoding="utf-8"?>
<Project>
<!-- These properties will be shared for all projects -->
<PropertyGroup>
<VersionPrefix>3.400.0</VersionPrefix>
<VersionSuffix>
</VersionSuffix>
<VersionSuffix></VersionSuffix>
<VersionSuffix Condition=" '$(VersionSuffix)' != '' AND '$(BuildNumber)' != '' ">$(VersionSuffix)-$(BuildNumber)</VersionSuffix>
</PropertyGroup>
<PropertyGroup>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
</Project>
6 changes: 6 additions & 0 deletions VirtoCommerce.GDPR.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=anonymize/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=anonymized/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=gdpr/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=virto/@EntryIndexedValue">True</s:Boolean>
</wpf:ResourceDictionary>
1 change: 1 addition & 0 deletions module.ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TimeZoneConverter.dll
Empty file.
Empty file.
33 changes: 0 additions & 33 deletions src/VirtoCommerce.GDPR.Core/ModuleConstants.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System.Collections.Generic;
using VirtoCommerce.Platform.Core.Settings;

namespace VirtoCommerce.GDPR.Core
{
public static class ModuleConstants
Expand All @@ -16,35 +13,5 @@ public static class Permissions
public static string[] AllPermissions { get; } = { Access, Anonymize, Download };
}
}

public static class Settings
{
public static class General
{
public static SettingDescriptor GDPRPassword { get; } = new SettingDescriptor
{
Name = "GDPR.GDPRPassword",
GroupName = "GDPR|Advanced",
ValueType = SettingValueType.SecureString,
DefaultValue = "qwerty"
};

public static IEnumerable<SettingDescriptor> AllSettings
{
get
{
yield return GDPRPassword;
}
}
}

public static IEnumerable<SettingDescriptor> AllSettings
{
get
{
return General.AllSettings;
}
}
}
}
}
Empty file.
Empty file.
18 changes: 3 additions & 15 deletions src/VirtoCommerce.GDPR.Core/VirtoCommerce.GDPR.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
<!-- Project is not a test project -->
<SonarQubeTestProject>false</SonarQubeTestProject>
<!-- Project is not a test project -->
<SonarQubeTestProject>false</SonarQubeTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="VirtoCommerce.CustomerModule.Core" Version="3.200.0" />
<PackageReference Include="VirtoCommerce.OrdersModule.Core" Version="3.200.0" />
<PackageReference Include="VirtoCommerce.Platform.Core" Version="3.200.0" />
<PackageReference Include="VirtoCommerce.CustomerModule.Core" Version="3.400.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="Events\" />
<Folder Include="Notifications\" />
</ItemGroup>

</Project>

Empty file.
Empty file.
Empty file.
Empty file.

This file was deleted.

25 changes: 0 additions & 25 deletions src/VirtoCommerce.GDPR.Data/Repositories/GDPRModuleDbContext.cs

This file was deleted.

22 changes: 0 additions & 22 deletions src/VirtoCommerce.GDPR.Data/Repositories/GdprDbContext.cs

This file was deleted.

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,35 @@
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;
using VirtoCommerce.GDPR.Core.Services;
using VirtoCommerce.OrdersModule.Core.Model;
using VirtoCommerce.OrdersModule.Core.Model.Search;
using VirtoCommerce.OrdersModule.Core.Services;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.Platform.Core.GenericCrud;
using VirtoCommerce.Platform.Core.Security;

namespace VirtoCommerce.GDPR.Data.Services
{
public class AnonymizeContactDataService : IAnonymizeContactDataService
{
private readonly IMemberService _memberService;
private readonly ISearchService<CustomerOrderSearchCriteria, CustomerOrderSearchResult, CustomerOrder> _customerOrderSearchService;
private readonly ICustomerOrderSearchService _customerOrderSearchService;
private readonly ICustomerOrderService _customerOrderService;
private readonly Func<UserManager<ApplicationUser>> _userManagerFactory;
private readonly string _anonymName = "Anonymized";
private readonly string _anonymPostalCode = "000000";
private readonly string _anonymPhone = "+00000000000";

/// <summary>
/// Max count of customer order donload data
/// Max count of customer order download data
/// </summary>
protected virtual int DefaultTake => int.MaxValue;

public AnonymizeContactDataService(IMemberService memberService,
ISearchService<CustomerOrderSearchCriteria, CustomerOrderSearchResult, CustomerOrder> customerOrderSearchService,
public AnonymizeContactDataService(
IMemberService memberService,
ICustomerOrderSearchService customerOrderSearchService,
ICustomerOrderService customerOrderService,
Func<UserManager<ApplicationUser>> userManager)
{
Expand All @@ -48,7 +46,7 @@ public async Task<Contact> AnonymizeContactDataAsync(string id)

var orderSearchCriteria = AbstractTypeFactory<CustomerOrderSearchCriteria>.TryCreateInstance();

var accountIds = contact.SecurityAccounts.Select(x => x.Id).Concat(new string[] { contact.Id });
var accountIds = contact.SecurityAccounts.Select(x => x.Id).Concat(new[] { contact.Id });
orderSearchCriteria.CustomerIds = accountIds.ToArray();
orderSearchCriteria.Take = DefaultTake;

Expand Down Expand Up @@ -133,7 +131,7 @@ public async Task<Contact> AnonymizeContactDataAsync(string id)

// TODO need update CreatedBy, ModifiedBy for Contact, CustomerOrder, User. Need to create UseDbTriggers for anonymized entities

await _memberService.SaveChangesAsync(new[] { contact });
await _memberService.SaveChangesAsync(new Member[] { 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 @@ -4,24 +4,23 @@
using VirtoCommerce.CustomerModule.Core.Services;
using VirtoCommerce.GDPR.Core.Models.DownloadData;
using VirtoCommerce.GDPR.Core.Services;
using VirtoCommerce.OrdersModule.Core.Model;
using VirtoCommerce.OrdersModule.Core.Model.Search;
using VirtoCommerce.OrdersModule.Core.Services;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.Platform.Core.GenericCrud;

namespace VirtoCommerce.GDPR.Data.Services
{
public class DownloadContactDataService : IDownloadContactDataService
{
private readonly IMemberService _memberService;
private readonly ISearchService<CustomerOrderSearchCriteria, CustomerOrderSearchResult, CustomerOrder> _customerOrderSearchService;
private readonly ICustomerOrderSearchService _customerOrderSearchService;

/// <summary>
/// Max count of customer order donload data
/// Max count of customer order download data
/// </summary>
protected virtual int DefaultTake => 9999;

public DownloadContactDataService(IMemberService memberService, ISearchService<CustomerOrderSearchCriteria, CustomerOrderSearchResult, CustomerOrder> customerOrderSearchService)
public DownloadContactDataService(IMemberService memberService, ICustomerOrderSearchService customerOrderSearchService)
{
_memberService = memberService;
_customerOrderSearchService = customerOrderSearchService;
Expand All @@ -38,7 +37,7 @@ public async Task<Customer> GetContactDataAsync(string id)

var orderSearchCriteria = AbstractTypeFactory<CustomerOrderSearchCriteria>.TryCreateInstance();
// in old version: CustomerOrder.CustomerId = Member.Id, but in new version: CustomerOrder.CustomerId = AspNetUsers.Id, so we return both variants in here
var accountIds = contact.SecurityAccounts.Select(x => x.Id).Concat(new string[] { contact.Id });
var accountIds = contact.SecurityAccounts.Select(x => x.Id).Concat(new[] { contact.Id });
orderSearchCriteria.CustomerIds = accountIds.ToArray();
orderSearchCriteria.Take = DefaultTake;

Expand Down
Loading

0 comments on commit f97f906

Please sign in to comment.