Umbraco 7.7 user group how to (Not member group or type)
Hey guys
My first post/solution seeking.
C# developer
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.
You can use the UserService for this. For example:
// Create a user group
var userGroup = new UserGroup
{
Alias = "testgroup",
Name = "Test Group"
};
userGroup.AddAllowedSection("content");
userGroup.AddAllowedSection("media");
Services.UserService.Save(userGroup);
// Assign user to the group
var user = Services.UserService.GetByEmail("[email protected]");
user.AddGroup(userGroup);
Services.UserService.Save(user);
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.
Umbraco 7.7 user group how to (Not member group or type)
Hey guys My first post/solution seeking. C# developer 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
Hey Alex,
You can use the
UserService
for this. For example:UserGroup
is fromUmbraco.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.
Trying this code in Umbraco 7.10.3. but user cant find any libraries for
Services.UserService.Save(userGroup);
Any clues?
is working on a reply...