Skip to content

Commit 57c0eaf

Browse files
author
Marcel Schmidt
committed
Resolves #2190 Customer: Only administrators should be allowed to modify customers who are administrators
1 parent 8fb4b29 commit 57c0eaf

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/Libraries/SmartStore.Data/Migrations/MigrationsConfiguration.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ public void MigrateLocaleResources(LocaleResourcesBuilder builder)
116116

117117
builder.AddOrUpdate("Admin.Configuration.Settings.GeneralCommon.DisplayAllows", "Show items for 'Allow'", "Einträge für 'Allow' anzeigen");
118118
builder.AddOrUpdate("Admin.Configuration.Settings.GeneralCommon.DisplayDisallows", "Show items for 'Disallow'", "Einträge für 'Disallow' anzeigen");
119+
120+
builder.AddOrUpdate("Admin.Customers.CustomerRoles.OnlyAdminsAllowed",
121+
"You do not have administrator rights, therefore you are not allowed to modify administrators.",
122+
"Sie verfügen über keine Administratorenrechte, daher dürfen Sie Administratoren nicht modifzieren.");
119123
}
120124
}
121125
}

src/Presentation/SmartStore.Web/Administration/Controllers/CustomerController.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ protected virtual void PrepareCustomerModelForEdit(CustomerModel model, Customer
261261
model.LastActivityDate = Services.DateTimeHelper.ConvertToUserTime(customer.LastActivityDateUtc, DateTimeKind.Utc);
262262
model.LastIpAddress = model.LastIpAddress;
263263
model.LastVisitedPage = customer.GetAttribute<string>(SystemCustomerAttributeNames.LastVisitedPage);
264-
264+
265265
foreach (var tzi in Services.DateTimeHelper.GetSystemTimeZones())
266266
{
267267
model.AvailableTimeZones.Add(new SelectListItem { Text = tzi.DisplayName, Value = tzi.Id, Selected = tzi.Id == model.TimeZoneId });
@@ -635,6 +635,12 @@ public ActionResult Edit(CustomerModel model, bool continueEditing, FormCollecti
635635
return RedirectToAction("List");
636636
}
637637

638+
if (customer.IsAdmin() && !Services.WorkContext.CurrentCustomer.IsAdmin())
639+
{
640+
NotifyError(T("Admin.Customers.CustomerRoles.OnlyAdminsAllowed"));
641+
return RedirectToAction("Edit", new { customer.Id });
642+
}
643+
638644
// Validate customer roles.
639645
var allowManagingCustomerRoles = Services.Permissions.Authorize(Permissions.Customer.EditRole);
640646

@@ -906,11 +912,11 @@ public ActionResult Impersonate(int id)
906912
if (customer == null)
907913
return RedirectToAction("List");
908914

909-
// ensure that a non-admin user cannot impersonate as an administrator
910-
// otherwise, that user can simply impersonate as an administrator and gain additional administrative privileges
915+
// Ensure that a non-admin user cannot impersonate as an administrator
916+
// Otherwise, that user can simply impersonate as an administrator and gain additional administrative privileges
911917
if (!Services.WorkContext.CurrentCustomer.IsAdmin() && customer.IsAdmin())
912918
{
913-
NotifyError("A non-admin user cannot impersonate as an administrator");
919+
NotifyError(T("Admin.Customers.CustomerRoles.OnlyAdminsAllowed"));
914920
return RedirectToAction("Edit", customer.Id);
915921
}
916922

@@ -1207,7 +1213,7 @@ private void PrepareAddressModel(CustomerAddressModel model, Customer customer,
12071213
model.Address.LastNameRequired = true;
12081214
model.Address.EmailEnabled = true;
12091215
model.Address.EmailRequired = true;
1210-
1216+
12111217
MiniMapper.Map(_addressSettings, model.Address);
12121218

12131219
model.Address.AvailableCountries = _countryService.GetAllCountries(true)

0 commit comments

Comments
 (0)