Skip to content

Commit

Permalink
Do not allow edit/delete system accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofPajak committed Dec 6, 2021
1 parent b4fbd3f commit 41726ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,7 @@ Task UpdateCustomerField<T>(Customer customer,
/// <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>
Expand Down
25 changes: 7 additions & 18 deletions src/Business/Grand.Business.Customers/Services/CustomerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public virtual async Task UpdateCustomerField<T>(string customerId,
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);

Expand All @@ -355,6 +355,9 @@ public virtual async Task UpdateCustomer(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.Email, string.IsNullOrEmpty(customer.Email) ? "" : customer.Email.ToLowerInvariant())
.Set(x => x.PasswordFormatId, customer.PasswordFormatId)
Expand Down Expand Up @@ -431,32 +434,18 @@ public virtual async Task UpdateCustomerLastLoginDate(Customer customer)

}

/// <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)
Expand Down

0 comments on commit 41726ab

Please sign in to comment.