Copied to clipboard

Flag this post as spam?

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


  • Tom 161 posts 322 karma points
    Jun 26, 2018 @ 16:47
    Tom
    0

    How to Add a group to a User

    I have just upgraded from 7.5.9 to 7.7 and see where the umbracoUserType and umbracoUser2app tables have been replaced with umbracoUserGroup and umbracoUser2UserGroup, which is fine.

    But for me, I need to insert/delete into this table based on what the user has in Active Directory.

    I could use Entity Framework to do my work but wanted to make sure I wasn't missing anything by not using the Umbraco UserService object. I did find a userService.AddGroup() but its read only.

    Question: Is there an Umbraco object API call that will allow me to add a group to an existing user?

    Thanks

    Tom

  • Zihadul Azam 26 posts 171 karma points c-trib
    Jul 06, 2018 @ 07:31
    Zihadul Azam
    0

    Hii,

    You can easily add Groups to User with AddGroup function of IUser.

    For example:

    public void MakeAdmin (IUser user)
    {
       IUserService _userService = ApplicationContext.Current.Services.UserService;
    
       // how to remove a group from user
       user.RemoveGroup("writerAlias");
    
       // get Admin group
       var adminGroup = _userService.GetUserGroupByAlias("adminAlias") as IReadOnlyUserGroup;
    
       // how to add a group to user
       user.AddGroup(adminGroup);
    
       // save user
       _userService.Save(user);
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft