Copied to clipboard

Flag this post as spam?

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


  • Sean Håkansson 66 posts 192 karma points
    Feb 11, 2019 @ 11:04
    Sean Håkansson
    0

    uSync Member Groups

    Hi, am I missing something? How can I enable Member Group sync? It seems my coworkers get at least one, but I dont know why?

    Are people using Member Types to set auth permission logic?

    Thanks Sean

  • javafun 17 posts 50 karma points c-trib
    Feb 11, 2019 @ 11:28
    javafun
    1

    Hi Sean

    Apparently, I don't think you can sync either member group nor member. My workaround has to create customer ApplicationEventHandler to initialize default member groups.

    Below is my currently solution plugged in my ApplicationEventHandler. I hope this may help.

    private void InitializeMemberGroups(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            string[] groups = new[] { <your group names> };
    
            var existGroups = applicationContext.Services.MemberGroupService.GetAll().Select(x => x.Name).ToList();
    
            var newGroups = groups.Except(existGroups);
    
            foreach (var newGroup in newGroups)
            {
                applicationContext.Services.MemberGroupService.Save(new MemberGroup { Name = newGroup });
            }
        }
    
  • Sean Håkansson 66 posts 192 karma points
    Feb 11, 2019 @ 15:02
    Sean Håkansson
    0

    Thank you so much, can't get this running with latest umbraco, but hopefully I can figure it out. I get the concept. :)

    Much appreciated!

  • Sean Håkansson 66 posts 192 karma points
    Feb 11, 2019 @ 15:12
    Sean Håkansson
    0

    Btw, my solution was a bit easier. Hopefully I'm not doing anything crazy (c# is not my main language),

    string[] groups = new[] { "Group 1", "Group 2", "Group 3" };
    
    var memberService = applicationContext.Services.MemberService;
        foreach(var group in groups) { 
            memberService.AddRole(group);
        }
    

    It seems that adding roles that already exist is handled by the service (hopefully wont bloat database with multiple groups).

  • javafun 17 posts 50 karma points c-trib
    Feb 12, 2019 @ 02:29
    javafun
    0

    You're welcome. Glad to hear it helps.

    The sample code I provided is to create member groups , I have another function running after this to initiate some default members, and assign them to the member groups created by previous sample code.

    Happy coding :)

Please Sign in or register to post replies

Write your reply to:

Draft