Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Carlos Casalicchio 104 posts 444 karma points
    May 28, 2019 @ 15:20
    Carlos Casalicchio
    0

    Default User Group Permissions

    This is not so much as a question, but just something I wanted to share, since it took some work for me to figure it out.

    When creating new groups programmatically, one can set the default permissions, but they are somewhat cryptic, and not that intuitive.

    Here is the list of default permissions for Groups (these will give access to specific features)

    User Group Permissions

    Cultures and Hostnames (I)
    Public Access (P)
    Rollback (K)
    Browse Node (F)
    Create Content Template (ï)
    Delete (D)
    Create (C)
    Publish (U)
    Permissions (R)
    Send To Publish (H)
    Unpublish (Z)
    Update (A)
    Copy (O)
    Move (M)
    Sort (S)
    

    so, in order to use these in your code, do something like this:

    First create the IUserGroup

    UserGroup group = new UserGroup
            {
                Alias = "mycustomgroup",
                Name = "My Custom Group",
                Icon = "icon-umb-members",
                Permissions = new List<string> { "I", "P", "K", "F", "ï", "D", "C", "U", "A", "O", "S" },
                StartContentId = 1080,
                StartMediaId = 1081,
                Key = Guid.NewGuid()
            };
            group.AddAllowedSection("content");
            group.AddAllowedSection("media");
    

    Then create the group in Umbraco

    public UserGroup CreateUserGroup(IUserGroup group)
            {
                UserGroup newGroup = (UserGroup)userService.GetUserGroupByAlias(group.Alias);
                if (newGroup != null) throw new Exception("Group already exists");
    
                try
                {
                    userService.Save(newGroup);
                    ConnectorContext.AuditService.Add(AuditType.New, -1, newGroup.Id, "User Group", $"User Group {newGroup.Name} has been created");
                    return newGroup;
                }
                catch (Exception ex)
                {
                    logger.Error(typeof(UserGroupHelper), ex.Message);
                    logger.Error(typeof(UserGroupHelper), ex.StackTrace);
                    throw;
                }
            }
    
Please Sign in or register to post replies

Write your reply to:

Draft