Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Do not allow edit/delete system accounts

KrzysztofPajak41726abe1652
diff --git a/src/Business/Grand.Business.Customers/Interfaces/ICustomerService.cs b/src/Business/Grand.Business.Customers/Interfaces/ICustomerService.cs
index 642bdc1b2..b2a21b994 100644
--- a/src/Business/Grand.Business.Customers/Interfaces/ICustomerService.cs
+++ b/src/Business/Grand.Business.Customers/Interfaces/ICustomerService.cs
@@ -159,13 +159,7 @@ namespace Grand.Business.Customers.Interfaces
/// <param name="customerId">Customer ident</param>
Task UpdateCustomerField<T>(string customerId,
Expression<Func<Customer, T>> expression, T value);
-
- /// <summary>
- /// Updates the customer
- /// </summary>
- /// <param name="customer">Customer</param>
- Task UpdateCustomerPassword(Customer customer);
-
+
/// <summary>
/// Updates the customer
/// </summary>
diff --git a/src/Business/Grand.Business.Customers/Services/CustomerService.cs b/src/Business/Grand.Business.Customers/Services/CustomerService.cs
index 40bebb4f5..93b8a3adb 100644
--- a/src/Business/Grand.Business.Customers/Services/CustomerService.cs
+++ b/src/Business/Grand.Business.Customers/Services/CustomerService.cs
@@ -341,7 +341,7 @@ namespace Grand.Business.Customers.Services
Expression<Func<Customer, T>> expression, T value)
{
if (string.IsNullOrEmpty(customerId))
- throw new ArgumentNullException("customerId");
+ throw new ArgumentNullException(nameof(customerId));
await _customerRepository.UpdateField<T>(customerId, expression, value);
@@ -355,6 +355,9 @@ namespace Grand.Business.Customers.Services
if (customer == null)
throw new ArgumentNullException(nameof(customer));
+ if (customer.IsSystemAccount)
+ throw new GrandException(string.Format("System customer account ({0}) could not be updated", customer.SystemName));
+
var update = UpdateBuilder<Customer>.Create()
.Set(x => x.Email, string.IsNullOrEmpty(customer.Email) ? "" : customer.Email.ToLowerInvariant())
.Set(x => x.PasswordFormatId, customer.PasswordFormatId)
@@ -431,32 +434,18 @@ namespace Grand.Business.Customers.Services
}
- /// <summary>
- /// Updates the customer - password
- /// </summary>
- /// <param name="customer">Customer</param>
- public virtual async Task UpdateCustomerPassword(Customer customer)
- {
- if (customer == null)
- throw new ArgumentNullException(nameof(customer));
-
- await UpdateCustomerField(customer.Id, x => x.Password, customer.Password);
-
- //event notification
- await _mediator.EntityUpdated(customer);
-
- }
-
public virtual async Task UpdateCustomerinAdminPanel(Customer customer)
{
if (customer == null)
throw new ArgumentNullException(nameof(customer));
+ if (customer.IsSystemAccount)
+ throw new GrandException(string.Format("System customer account ({0}) could not be updated", customer.SystemName));
+
var update = UpdateBuilder<Customer>.Create()
.Set(x => x.Active, customer.Active)
.Set(x => x.AdminComment, customer.AdminComment)
.Set(x => x.AffiliateId, customer.AffiliateId)
- .Set(x => x.IsSystemAccount, customer.IsSystemAccount)
.Set(x => x.Active, customer.Active)
.Set(x => x.Email, string.IsNullOrEmpty(customer.Email) ? "" : customer.Email.ToLowerInvariant())
.Set(x => x.IsTaxExempt, customer.IsTaxExempt)