Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
My first post/solution seeking.
Short question, how do I programmatically create new user groups and assign a user to that group.
We just upgraded to 7.7.4 from 7.4.2.
We had to change some of our custom code creating or editing users (not members) with existing user types and assigning permissions to users directly, to now assigning permissions to groups.
This is all part of a sync service pushing users into umbraco from another application where users and and categorisation entities called tiers are created.
The architecture of our application requires that we create multiple new groups unique to the user's role and each tier he has access to.
Content also are categorised by these tiers so permissios have to be synced regularly.
We really need to know the best way to create these new user groups in c# and immediately be able to assign users to them.
Thanks in advance
You can use the UserService for this. For example:
// Create a user group
var userGroup = new UserGroup
Alias = "testgroup",
Name = "Test Group"
// Assign user to the group
var user = Services.UserService.GetByEmail("firstname.lastname@example.org");
UserGroup is from Umbraco.Core.Models.Membership
Thank you Matt, that worked. thanks
Hi Matt! Is there a way to do this at 7.7.2? Class UserGroup is internal at this version
Thank you Matt, I'll try this and get back to you.
Did you get anywhere with this? I need to programmatically create new user groups and at the moment my hands are tied on how to do it due to the classes being internal.
I've just upgraded to 7.7.2 and it seems the class is now public so I can do what I need.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted