Skip to content

Commit

Permalink
Merge branch 'issue-5312-Import-customers' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Libraries/Nop.Core/Domain/Security/SecuritySettings.cs
#	src/Libraries/Nop.Services/ExportImport/ExportManager.cs
#	src/Libraries/Nop.Services/ExportImport/ImportManager.cs
#	src/Libraries/Nop.Services/Installation/InstallationService.cs
#	src/Presentation/Nop.Web.Framework/Migrations/UpgradeTo470/LocalizationMigration.cs
#	src/Presentation/Nop.Web.Framework/Migrations/UpgradeTo470/SettingMigration.cs
#	src/Presentation/Nop.Web/Areas/Admin/Controllers/CustomerController.cs
  • Loading branch information
skoshelev committed Mar 28, 2023
2 parents 965b27d + a50b663 commit 440348e
Show file tree
Hide file tree
Showing 11 changed files with 453 additions and 11 deletions.
5 changes: 5 additions & 0 deletions src/Libraries/Nop.Core/Domain/Security/SecuritySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,10 @@ public partial class SecuritySettings : ISettings
/// Gets or sets a value indicating whether the Advanced Encryption Standard (AES) is used
/// </summary>
public bool UseAesEncryptionAlgorithm { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to allow export and import customers with hashed password
/// </summary>
public bool AllowStoreOwnerExportImportCustomersWithHashedPassword { get; set; }
}
}
40 changes: 40 additions & 0 deletions src/Libraries/Nop.Data/Migrations/UpgradeTo470/DataMigration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using FluentMigrator;
using Nop.Core.Domain.Logging;

namespace Nop.Data.Migrations.UpgradeTo470
{
[NopMigration("2023-01-01 00:00:00", "4.70.0", UpdateMigrationType.Data, MigrationProcessType.Update)]
public class DataMigration : Migration
{
private readonly INopDataProvider _dataProvider;

public DataMigration(INopDataProvider dataProvider)
{
_dataProvider = dataProvider;
}

/// <summary>
/// Collect the UP migration expressions
/// </summary>
public override void Up()
{
//#5312 new activity log type
var activityLogTypeTable = _dataProvider.GetTable<ActivityLogType>();

if (!activityLogTypeTable.Any(alt => string.Compare(alt.SystemKeyword, "ImportCustomers", StringComparison.InvariantCultureIgnoreCase) == 0))
_dataProvider.InsertEntity(
new ActivityLogType
{
SystemKeyword = "ImportCustomers",
Enabled = true,
Name = "Customers were imported"
}
);
}

public override void Down()
{
//add the downgrade logic if necessary
}
}
}
40 changes: 35 additions & 5 deletions src/Libraries/Nop.Services/ExportImport/ExportManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Nop.Core.Domain.Messages;
using Nop.Core.Domain.Orders;
using Nop.Core.Domain.Payments;
using Nop.Core.Domain.Security;
using Nop.Core.Domain.Seo;
using Nop.Core.Domain.Shipping;
using Nop.Core.Domain.Tax;
Expand Down Expand Up @@ -52,15 +53,16 @@ public partial class ExportManager : IExportManager

protected readonly AddressSettings _addressSettings;
protected readonly CatalogSettings _catalogSettings;
protected readonly SecuritySettings _securitySettings;
protected readonly ICustomerActivityService _customerActivityService;
protected readonly CustomerSettings _customerSettings;
protected readonly DateTimeSettings _dateTimeSettings;
protected readonly ForumSettings _forumSettings;
protected readonly IAddressService _addressService;
protected readonly IAttributeFormatter<CustomerAttribute, CustomerAttributeValue> _customerAttributeFormatter;
protected readonly ICategoryService _categoryService;
protected readonly ICountryService _countryService;
protected readonly ICurrencyService _currencyService;
protected readonly ICustomerActivityService _customerActivityService;
protected readonly IAttributeFormatter<CustomerAttribute, CustomerAttributeValue> _customerAttributeFormatter;
protected readonly ICustomerService _customerService;
protected readonly IDateRangeService _dateRangeService;
protected readonly IDateTimeHelper _dateTimeHelper;
Expand Down Expand Up @@ -99,6 +101,7 @@ public partial class ExportManager : IExportManager

public ExportManager(AddressSettings addressSettings,
CatalogSettings catalogSettings,
SecuritySettings securitySettings,
CustomerSettings customerSettings,
DateTimeSettings dateTimeSettings,
ForumSettings forumSettings,
Expand Down Expand Up @@ -142,6 +145,7 @@ public partial class ExportManager : IExportManager
{
_addressSettings = addressSettings;
_catalogSettings = catalogSettings;
_securitySettings = securitySettings;
_customerSettings = customerSettings;
_dateTimeSettings = dateTimeSettings;
_addressService = addressService;
Expand Down Expand Up @@ -1994,7 +1998,6 @@ async Task<object> getStateProvince(Customer customer)
new PropertyByName<Customer, Language>("Phone", (p, l) => p.Phone, !_customerSettings.PhoneEnabled),
new PropertyByName<Customer, Language>("Fax", (p, l) => p.Fax, !_customerSettings.FaxEnabled),
new PropertyByName<Customer, Language>("VatNumber", (p, l) => p.VatNumber),
new PropertyByName<Customer, Language>("VatNumberStatusId", (p, l) => p.VatNumberStatusId),
new PropertyByName<Customer, Language>("VatNumberStatus", (p, l) => p.VatNumberStatusId)
{
DropDownElements = await VatNumberStatus.Unknown.ToSelectListAsync(useLocalization: false)
Expand All @@ -2003,9 +2006,36 @@ async Task<object> getStateProvince(Customer customer)
new PropertyByName<Customer, Language>("AvatarPictureId", async (p, l) => await _genericAttributeService.GetAttributeAsync<int>(p, NopCustomerDefaults.AvatarPictureIdAttribute), !_customerSettings.AllowCustomersToUploadAvatars),
new PropertyByName<Customer, Language>("ForumPostCount", async (p, l) => await _genericAttributeService.GetAttributeAsync<int>(p, NopCustomerDefaults.ForumPostCountAttribute)),
new PropertyByName<Customer, Language>("Signature", async (p, l) => await _genericAttributeService.GetAttributeAsync<string>(p, NopCustomerDefaults.SignatureAttribute)),
new PropertyByName<Customer, Language>("CustomCustomerAttributes", async (p, l) => await GetCustomCustomerAttributesAsync(p))
}, _catalogSettings);
new PropertyByName<Customer, Language>("CustomCustomerAttributes", async (p, l) => await GetCustomCustomerAttributesAsync(p)),
new PropertyByName<Customer, Language>("CustomCustomerAttributesXml", (p, l) => p.CustomCustomerAttributesXML),
new PropertyByName<Customer, Language>("Password", async (p, l) =>
{
if (!_securitySettings.AllowStoreOwnerExportImportCustomersWithHashedPassword)
return string.Empty;
var password = await _customerService.GetCurrentPasswordAsync(p.Id);
if (password.PasswordFormat == PasswordFormat.Hashed)
return password.Password;
return string.Empty;
}, !_securitySettings.AllowStoreOwnerExportImportCustomersWithHashedPassword),
new PropertyByName<Customer, Language>("PasswordSalt", async (p, l) =>
{
if (!_securitySettings.AllowStoreOwnerExportImportCustomersWithHashedPassword)
return string.Empty;
var password = await _customerService.GetCurrentPasswordAsync(p.Id);
if (password.PasswordFormat == PasswordFormat.Hashed)
return password.PasswordSalt;
return string.Empty;
}, !_securitySettings.AllowStoreOwnerExportImportCustomersWithHashedPassword),

}, _catalogSettings);

//activity log
await _customerActivityService.InsertActivityAsync("ExportCustomers",
string.Format(await _localizationService.GetResourceAsync("ActivityLog.ExportCustomers"), customers.Count));
Expand Down
7 changes: 7 additions & 0 deletions src/Libraries/Nop.Services/ExportImport/IImportManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,12 @@ public partial interface IImportManager
/// <param name="stream">Stream</param>
/// <returns>A task that represents the asynchronous operation</returns>
Task ImportOrdersFromXlsxAsync(Stream stream);

/// <summary>
/// Import customers from XLSX file
/// </summary>
/// <param name="stream">Stream</param>
/// <returns>A task that represents the asynchronous operation</returns>
Task ImportCustomersFromXlsxAsync(Stream stream);
}
}

0 comments on commit 440348e

Please sign in to comment.