{"record":{"id":"06cd3da71e2059d8","repo":"nopSolutions/nopCommerce","slug":"system-customer-roles-can-t-be-disabled","errorCode":null,"errorMessage":"System customer roles can't be disabled.","messagePattern":"System customer roles can't be disabled\\.","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"warning","filePath":"src/Presentation/Nop.Web/Areas/Admin/Controllers/CustomerRoleController.cs","lineNumber":148,"sourceCode":"        return View(model);\n    }\n\n    [HttpPost, ParameterBasedOnFormName(\"save-continue\", \"continueEditing\")]\n    [CheckPermission(StandardPermission.Customers.CUSTOMER_ROLES_CREATE_EDIT_DELETE)]\n    [CheckPermission(StandardPermission.Configuration.MANAGE_ACL)]\n    public virtual async Task<IActionResult> Edit(CustomerRoleModel model, bool continueEditing)\n    {\n        //try to get a customer role with the specified id\n        var customerRole = await _customerService.GetCustomerRoleByIdAsync(model.Id);\n        if (customerRole == null)\n            return RedirectToAction(\"List\");\n\n        try\n        {\n            if (ModelState.IsValid)\n            {\n                if (customerRole.IsSystemRole && !model.Active)\n                    throw new NopException(await _localizationService.GetResourceAsync(\"Admin.Customers.CustomerRoles.Fields.Active.CantEditSystem\"));\n\n                if (customerRole.IsSystemRole && !customerRole.SystemName.Equals(model.SystemName, StringComparison.InvariantCultureIgnoreCase))\n                    throw new NopException(await _localizationService.GetResourceAsync(\"Admin.Customers.CustomerRoles.Fields.SystemName.CantEditSystem\"));\n\n                if (NopCustomerDefaults.RegisteredRoleName.Equals(customerRole.SystemName, StringComparison.InvariantCultureIgnoreCase) &&\n                    model.PurchasedWithProductId > 0)\n                    throw new NopException(await _localizationService.GetResourceAsync(\"Admin.Customers.CustomerRoles.Fields.PurchasedWithProduct.Registered\"));\n\n                customerRole = model.ToEntity(customerRole);\n                await _customerService.UpdateCustomerRoleAsync(customerRole);\n\n                //activity log\n                await _customerActivityService.InsertActivityAsync(\"EditCustomerRole\",\n                    string.Format(await _localizationService.GetResourceAsync(\"ActivityLog.EditCustomerRole\"), customerRole.Name), customerRole);\n\n                _notificationService.SuccessNotification(await _localizationService.GetResourceAsync(\"Admin.Customers.CustomerRoles.Updated\"));\n\n                return continueEditing ? RedirectToAction(\"Edit\", new { id = customerRole.Id }) : RedirectToAction(\"List\");","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Presentation/Nop.Web/Areas/Admin/Controllers/CustomerRoleController.cs#L130-L166","documentation":"Thrown inside the CustomerRole Edit action when a role with IsSystemRole == true is being saved with Active == false. System roles (e.g. Administrators, Registered, Guests, ForumModerators, Vendors) are foundational to the platform's authorization and must always remain active. It is a NopException thrown inside a try/catch that renders an error notification and re-displays the edit view.","triggerScenarios":"POST to CustomerRole/Edit with a model whose Id resolves to a system role and Active is unchecked (false) in the 'Is active' field.","commonSituations":"An admin mistakenly tries to disable a built-in role; a bulk role-management script toggles all roles inactive; importing role configuration that does not special-case system roles.","solutions":["Leave 'Is active' checked for any role whose IsSystemRole flag is true (the edit form marks these).","If you truly need a role disabled, create a new non-system role instead of modifying the built-in one.","Audit any automation/bulk scripts to skip system roles before flipping the Active flag.","Inspect the role's IsSystemRole value in the admin UI and do not toggle Active for it."],"exampleFix":"// before — submits system role with Active=false -> NopException\n\n// after — keep system role active; disable logic only for non-system roles\nif (model.Active == false && customerRole.IsSystemRole)\n{\n    _notificationService.WarningNotification(\"System roles cannot be disabled.\");\n    return View(model);\n}","handlingStrategy":"validation","validationCode":"// Before saving: skip system roles when toggling Active\nif (model.Active == false)\n{\n    var role = await _customerService.GetCustomerRoleByIdAsync(model.Id);\n    if (role?.IsSystemRole == true)\n    {\n        ModelState.AddModelError(\"Active\", \"System roles cannot be disabled.\");\n        return View(model);\n    }\n}","typeGuard":"bool CanToggleActive(CustomerRole role) => !role?.IsSystemRole ?? false;","tryCatchPattern":"// The action already wraps in try/catch and renders ErrorNotification — rely on it and correct input.","preventionTips":["Render the Active toggle read-only/disabled for system roles in the view.","Audit bulk role scripts to skip IsSystemRole entries before flipping Active.","Never import role configs that disable built-in roles."],"tags":["nopcommerce","admin","customer-roles","business-rule","system-role","immutable"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}