Permissions set on Role via Code - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Permissions set on Role via Code

  • Hi,

    I am trying my first steps with Sitefinity coding by wanting to create a custom role and give this role a set of certain permissions. I therefore used the following instructions:

    https://www.progress.com/documentation/sitefinity-cms/for-developers-grant-and-deny-permissions

    However, I am not quite sure: Can I use a role's ID as the principalid instead of a singular user?

    Also: is there a proper code documentation like MSDN to get the full overview of classes and what the method's parameters are? For example, I do not get why I need to do these lines in the blogspermission Getter:

    BlogsPermissions.Sets.Blog.SetName,
    blogsmgr.GetSecurityRoot(false).Id

    As in the documentation

    Many thanks

  • In addition, how do I actually execute my code?

    If, for example I build a generic function to create roles for me, which requires an input (the role name) and has it's own call of  RoleManager.SaveChanges(); - how do I actually trigger Sitefinity to execute this script once, when I use a "main method", that calls the rolecreation function with a specific name?

    My code is:

       public class Sen_CreateSennRole

       {

           public void CreateSenRole(string roleName)

           {

               RoleManager roleManager = RoleManager.GetManager();

               if (roleManager.GetRoles().Where(r => r.Name == roleName).FirstOrDefault() == null)

               {

                   roleManager.CreateRole(roleName);

               }

               else

               {

                   // Handle appropriately when the role already exists

               }

               roleManager.SaveChanges();

           }

    }