Copied to clipboard

Flag this post as spam?

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


  • Damion 96 posts 331 karma points
    Apr 17, 2019 @ 15:52
    Damion
    0

    Create user groups and assign users in code

    In v8 is it possible to create user groups and assign users to those groups, the way we can with members and roles using the IMemberService?

    I had a look at the IUserService and can create users just fine but not groups or assignations.

    Is this in another service or is it not possible?

    thanks

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Apr 27, 2019 @ 11:24
    Marc Goodson
    100

    Hi Damion

    I think it is! there is an overload of the Save method of the UserService that accepts a UserGroup object, and an array of ids corresponding to Users to add...

    I am gleaning this by looking at the source for the code here:

    https://github.com/umbraco/Umbraco-CMS/blob/853087a75044b814df458457dc9a1f778cc89749/src/Umbraco.Core/Services/Implement/UserService.cs#L843

    but I think something like this could work...

    UserGroup SuperAdmins = new UserGroup() { Alias = "superAdmins", Name="Super Admin" };
        userService.Save(SuperAdmins, new int[] { 123, 124 });
    

    regards

    Marc

  • Damion 96 posts 331 karma points
    Apr 29, 2019 @ 09:10
    Damion
    0

    Hi Marc,

    thanks for the reply, I'll give this a go and mark as accepted as soon as

    cheers

Please Sign in or register to post replies

Write your reply to:

Draft