Set default role to new user - General Discussions - General Discussions - Progress Community
 General Discussions

Set default role to new user

  • Set default role to new user
  • Hi all,

    Is it possible to set a default role when creating a new user through the backend interface?
    I need to have a particular role being checked, by default.

    Best,
    Daniel

  • 7e96c373-9935-4f10-ab64-b22a6ca463b5_UserNew.rar
    Hello Daniel,

    You should map the UserCreate view and manipulate the RolesRepeater which holds the Roles and the Checkbox for each role selection. Using the codebehind of the mapped view, we can iterate the roles collection and find the one we need, then find the underlying checkbox and check it:
    public partial class UserNew : System.Web.UI.UserControl
        
     
            protected void Page_Load(object sender, EventArgs e)
            
                var rolesList = this.FindControl("rptRolesList") as Repeater;
                if (rolesList != null)
                
                    var items = rolesList.DataSource as List<RoleProviderPair>;
                    if (items != null && items.Count > 0)
                    
                        for (int i = 0; i < items.Count; i++)
                        
                            if (items[i].RoleItem.Name == "Authors")
                            
                                var checkBox = rolesList.Items[i].FindControl("role") as CheckBox;
                                if (checkBox != null)
                                
                                    checkBox.Checked = true;
                                    break;
                                
                            
                        
                    
                
            
        

    The view is mapped from Administration -> Settings -> Advanced -> Controls -> ViewMap. Create New and add to HostType: Telerik.Sitefinity.Security.Web.UI.Principals.UserNewDialog, Telerik.Sitefinity, in LayoutTemplatePath set the path to the new template. Example.

    I have attached the mapped view. Hope you find it helpful.

    Regards,
    Nikola Zagorchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items