Registered Role is not automatically selected when admin creates a user

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 anos atrás
We have a customer service department that will occasionally need to create a user account and enters orders that are placed via phone.  These customer service users are in a custom role that is ACL's to only allow access to orders and customer management.  Right now they must be granted the ability to manage customer roles since they have to manually add the user to the 'Registered' or 'Guest' role.   This also allows them the ability to self promote or accidentally make a customer a global admin(or remove a legit admin).  Anyone know of a way to either prohibit global admin access while maintaining the ability to add the 'registered' role or automatically add the 'registered' role to a new customer account thats been created by an admin?
11 anos atrás
There is not way to do this out of the box.

But you can hack the Presentation\Nop.Web\Administration\Views\Customer\Create.cshtml view and add the Registered role id to the CustomerModel before calling the _CreateOrUpdate partial view.

List<int> selectedCustomerRoleIds = new List<int>(Model.SelectedCustomerRoleIds);
    selectedCustomerRoleIds.Add(3);

    Model.SelectedCustomerRoleIds = selectedCustomerRoleIds.ToArray();


Alternatively you can do this via a plugin and an ActionFilter, which is the proper way to do it. But it might be too much for such a simple requirement.
11 anos atrás
Works perfectly!  Thanks!
8 anos atrás
I'm testing an upgrade from 3.3 to 3.6 and this is no longer working.
When I make the code change now I get the following error.  Any ideas on what has changed?
The only difference I notice is @Html.AntiForgeryToken() in the 3.6 Create.cshtml code (was not in the 3.3 code).


Server Error in '/' Application.
--------------------------------------------------------------------------------


Value cannot be null.
Parameter name: collection
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: collection

Source Error:

Line 17:         </div>
Line 18:     </div>
Line 19:     List<int> selectedCustomerRoleIds = new List<int>(Model.SelectedCustomerRoleIds);    
Line 20:     selectedCustomerRoleIds.Add(3);  
Line 21:

Stack Trace:

[ArgumentNullException: Value cannot be null.
Parameter name: collection]
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +13956755
   ASP._Page_Administration_Views_Customer_Create_cshtml.Execute() in c:\inetpub\shop.wb.com\wwwroot\Administration\Views\Customer\Create.cshtml:19
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +126
   System.Web.WebPages.StartPage.ExecutePageHierarchy() +143
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +110
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +380
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +109
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +890
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +890
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +890
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +890
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +890
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +97
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +241
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +19
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +51
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
8 anos atrás
I think you can change line 19 to just this because if Create, Model.SelectedCustomerRoleIds is always null

List<int> selectedCustomerRoleIds = new List<int>();

but if you want to be safe use this

List<int> selectedCustomerRoleIds;
if  (Model.SelectedCustomerRoleIds == null)
    selectedCustomerRoleIds = new List<int>();
else
    selectedCustomerRoleIds = new List<int>(Model.SelectedCustomerRoleIds);
8 anos atrás
That fixed it.  Thanks as always for the help!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.