Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesCreating roles upon module installCreating roles upon module install
Previous
 
Next
New Post
6/18/2010 6:49 PM
 
Is there a way to add roles to the portal upon module installation (e.g. through manifest file)?

Alternatively, I would have to check whether ten different roles exist in the portal every time the page with module is opened. That would be fine on the initial module start, but kinda waste of resources after that. If I have to go this route, what is the function to check for the role presence?

Thanks,

Val
 
New Post
6/18/2010 8:56 PM
 
This cannot be done with a DNN 5 extension manifest. You could check for the existance of the roles and add them as necessary in an implementation of the IUpgradable interface in the module's business controller class. However, in a multi-portal site, you would have to either check and add the roles to all portals (currently) belonging to the installation or have some means of determining which portal will need to have roles checked/added. Until an installed module is added to a page of a particular portal, you cannot determine the PortalID to associate with the roles to be created. Also, as additional portals are added to the installation there would be no way to add the roles required by your module.

That brings us back to the other alternative you mentioned of checking/adding roles each time a page containing the module is opened. Rather than checking/adding roles each time, you could define a boolean flag in the Module Settings - for example RolesInitialized and test that setting value to see if further role checking adding was necessary. Even better would be to define this flag portal wide (stored in the PortalSettings table) using the PortalController class' shared UpdatePortalSetting and GetPortalSetting methods.

Finally, and I think the best approach is not to create roles but rather create custom module permissions which can easily be done via the DNN 5 manifest at the time of installation of the module. For example, rather than creating a Moderators role, create a CanModerate custom permission. Just like the standard edit and view permissions, the CanModerate permission will appear in the permissions grid on your module settings page. The admin user can then assign whatever role(s) he/she desires to be granted the CanModerate permission. Individual users can also be granted a standard or custom permission making this approach even more flexible.

Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
New Post
6/18/2010 9:21 PM
 
Thanks, William!

the reason I need multiple roles is that they could be added to certain users with a scheduler on a monthly basis so the user can access the page, update information and submit it, upon which the role is removed. Also there are multiple custom profiles that will be accessed based on assigned role. I do not see how I could accomplish that with the module permissions. But that's something I'll keep in mind since that might be a good solution in the future projects.

How would I define boolean flag in the Portal Settings? Should I check for the RolesInitialized, whether it exists, if not - create it, execute role creation function, and set RolesInitialized to true, if it exists then check whether it's true and proceed. I just need to figure out how to accomplish that.

In the meantime I came up with the folowing code to put in the main view page:

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //roles
                string strRole1 = "Role One";
                string strRole2 = "Role Two";
                string strRole3 = "Role Three";
                string strRole4 = "Role Four";
                string strRole5 = "Role Five";
                
                //check for roles existance and assign to bool
                bool bRole1 = Convert.ToBoolean(RoleProvider.Instance().GetRole(PortalId, strRole1));
                bool bRole2 = Convert.ToBoolean(RoleProvider.Instance().GetRole(PortalId, strRole2));
                bool bRole3 = Convert.ToBoolean(RoleProvider.Instance().GetRole(PortalId, strRole3));
                bool bRole4 = Convert.ToBoolean(RoleProvider.Instance().GetRole(PortalId, strRole4));
                bool bRole5 = Convert.ToBoolean(RoleProvider.Instance().GetRole(PortalId, strRole5));

                // If Roles do not exist, create and add them to the portal
                if (!bRole1)
                {
                    CreateRole(strRole1);
                }
                if (!bRole2)
                {
                    CreateRole(strRole2);
                }
                if (!bRole3)
                {
                    CreateRole(strRole3);
                }
                if (!bRole4)
                {
                    CreateRole(strRole4);
                }
                if (!bRole5)
                {
                    CreateRole(strRole5);
                }
            }
        }

        //Create a new role and add it to the portal
        protected void CreateRole(string strRoleName)
        {
            RoleController objDnnRoleController = new RoleController();
            RoleInfo objRole = new RoleInfo();
            objRole.AutoAssignment = false;
            objRole.IsPublic = false;
            objRole.PortalID = this.PortalId;
            objRole.RoleName = strRoleName;
            objRole.RoleGroupID = Null.NullInteger;
            objDnnRoleController.AddRole(objRole);
        }
 
New Post
6/19/2010 4:35 AM
 
I'm trying to figure out what's the purpose of a function if it returns a string that I feed into it...

public static string GetPortalSetting(string settingName, int portalID, string defaultValue);

What is defaultValue in this function? If I enter "true" for it, I get back the same string "true"

PortalController.GetPortalSetting("RolesInitialized", this.PortalId, "true")

and it won't let me to omit it. There is no entry in the PortalSettings table. And I cannot find anything else about this function, like what is it doing, what's inside its tummy so to speak...

There is also a function

public static bool GetPortalSettingAsBoolean(string key, int portalID, bool defaultValue);

which seems to be what I need, but again that defaultValue is there, and most likely it'll just feed me back whatever I enter there.

What I need is for me to pass SettingName, PortalID, and get back SettingValue.

So I'm lost again...
 
New Post
6/19/2010 6:13 AM
 
Well, the previous code was faulty, this one works great:

protected void Page_Load(System.Object sender, System.EventArgs e)
        {
            if (!IsPostBack)
            {
                AddRolesToPortal();
            }
        }

        //Add Roles to Portal
        private void AddRolesToPortal()
        {
            //role names
            string strRole1 = "Role One";
            string strRole2 = "Role Two";
            string strRole3 = "Role Three";
            string strRole4 = "Role Four";
            string strRole5 = "Role Five";

            CheckRole(strRole1);
            CheckRole(strRole2);
            CheckRole(strRole3);
            CheckRole(strRole4);
            CheckRole(strRole5);
        }

        //check role and create if not present
        protected void CheckRole(string strRoleName)
        {
            try
            {
                bool bExists = false;
                if (RoleProvider.Instance().GetRole(PortalId, strRoleName) != null)
                {
                    bExists = true;
                }

                if (!bExists)
                {
                    CreateRole(strRoleName);
                }
            }
            catch (System.Exception exc) //Something didn't work right
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

        //Create a new role and add it to the portal
        protected void CreateRole(string strRoleName)
        {
            RoleController objDnnRoleController = new RoleController();
            RoleInfo objRole = new RoleInfo();
            objRole.AutoAssignment = false;
            objRole.IsPublic = false;
            objRole.PortalID = this.PortalId;
            objRole.RoleName = strRoleName;
            objRole.RoleGroupID = Null.NullInteger;
            objDnnRoleController.AddRole(objRole);
        }

I'm sticking with this for now and move forward.

 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesCreating roles upon module installCreating roles upon module install


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out