Copied to clipboard

Flag this post as spam?

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


  • Craig O'Mahony 364 posts 918 karma points
    Oct 17, 2012 @ 11:12
    Craig O'Mahony
    0

    Importing Multiple Security Groups to one user

    Hi.

    I'm considering purchasing this software to handle nightly imports of users into my umbraco cms from my internal systems but I wonder if you could answer a query that I have please.

    I will have multiple member groups for my website and the users that I'm importing can be a member of one or more of these groups and I can't see a way that I can conditionally assign these permissions on the importing wizard, the only options that I can see are Automatically Assign these groups or not but this seems to apply to every user thats being imported.

    The data that i'm importing is via an SQL server and the current recordset will be something like the following:

    Username                 Password                  Permission

    User A                      PasswordA               Secure Area 1

    User A                      PasswordA               Secure Area 2

    User B                      PasswordB               Secure Area 1

     

    So when I'm importing this data I want to end up with 2 members (user a and user b) where User A has access to both secure areas of the site whereas User B only has access to Secure Area 1.

    Is this doable?

     

    Thanks,

    Craig

  • Richard Soeteman 4036 posts 12863 karma points MVP
    Oct 17, 2012 @ 11:27
    Richard Soeteman
    0

    Hi Craig,

    So you want to assign Member Groups based on the datasource. In the current version this is nout supported out of the box. But I assume you don't want to wait for Version 3 and it is really easy to do this using an event. Basically the same as how you would assign a Template as mentioned in this blogpost Only thing that is different is that you need to use the MemberImport.RecordImported event.

    Then in that eventhandler you can grap the groups from the datasource, and assign those to the current member.Using the Role Provider. From the top of my head it is Roles.AddUserToRole.  It would be handy if the permissions are stored comma seperated, instead of having multiple rows for the same user.

    If you need more info or help please let me know.

    Thanks,

    Richard

     

  • Craig O'Mahony 364 posts 918 karma points
    Oct 17, 2012 @ 11:53
    Craig O'Mahony
    0

    Hi Richard and thanks for your response.

    I will be able to produce a comma seperated list for the permissions. This is a real rookie question but I'm not sure on what page the MemberImport.RecordImported event exists on. Could you advise please?

    Thanks,

    Craig

  • Richard Soeteman 4036 posts 12863 karma points MVP
    Oct 17, 2012 @ 12:14
    Richard Soeteman
    0

    Hi Craig,

    I will write a blogpost about this so you can use it. I'll post a link when finished.

    Thanks,

    Richard

  • Craig O'Mahony 364 posts 918 karma points
    Oct 17, 2012 @ 12:34
    Craig O'Mahony
    0

    Richard,

    You are a superstar :)

    Thanks again,

    Craig

  • Richard Soeteman 4036 posts 12863 karma points MVP
    Oct 17, 2012 @ 23:05
    Richard Soeteman
    0

    Hi Craig,

    Blogging was a bit to much since it will be in the product within a few months. But to help you for now I have created a simple event handler that takes the roles from the Datasource (e.Items.Roles) in the source code below and extract the membergroups from that string. Then it will assign the roles to the member and that's all.

     public class AutoAssignMemberGroups : ApplicationBase
    {
    public AutoAssignMemberGroups()
    {
    MemberImport.RecordImporting += MemberImport_RecordImporting;
    }

    void MemberImport_RecordImporting(object sender, RecordImportingEventArgs e)
    {
    var member = sender as Member;
    if (member != null)
    {
    //Assuming Roles is the column in the datasource
    string rolesCsv = string.Format("{0}", e.Items["Roles"]);

    foreach(string role in rolesCsv.Split(','))
    {
    //You might want to cache this
    var memberGroup = MemberGroup.GetByName(role);
    member.AddGroup(memberGroup.Id);
    }
    }
    }
    }

    Download complete source and dll here 

    Again it will be in CMSImport V3 but hope this helps for now,

    Richard

  • Craig O'Mahony 364 posts 918 karma points
    Oct 18, 2012 @ 11:21
    Craig O'Mahony
    0

    Hi Richard,

    Thanks again for your response and time in helping me. I'm really sorry but I'm still unsure about where to put the code that you've created and how this code gets triggered when a CMS Import is run.

    Thanks again,

    Craig

  • Richard Soeteman 4036 posts 12863 karma points MVP
    Oct 18, 2012 @ 11:23
    Richard Soeteman
    0

    Hi Craig,

    If you give me the name of the column that you will be using I will compile the code for you.

    Thanks,

    Richard

  • Craig O'Mahony 364 posts 918 karma points
    Oct 18, 2012 @ 11:38
    Craig O'Mahony
    0

    I don't know what to say, thanks a million!

    Probably overkill on the information that you require but the steps that I'm taking are as follows.

    I've created four member groups in Umbraco: Basic Users, ICT Student, Diploma in AML, Diploma in DL and I'm using a SQL statement which will return 4 columns these being: Delegate Name, Username, Password and Role. So a row from the resulting recordset look like.

    "Charlize Theron" - "ctheron" - "zpassword" - "Basic Users, ICT Student, Diploma in DL"

    So in this example I'd want her to be assigned 3 of the 4 member groups when the data is imported (Obviously there'll be more than a single row in the recordset all with differing combinations).

    Hope that's what you were after.

    Really, thanks again.

    Craig

  • Richard Soeteman 4036 posts 12863 karma points MVP
    Oct 18, 2012 @ 12:40
    Richard Soeteman
    0

    Hi Craig,

    I've just updated the source and if you download the zip file again. And put AssignMembergroups\AssigneMemberGroups\AssigneMemberGroups\bin\Debug\AssignMemberGroups.dll into the \bin folder of your Umbraco installation all should work.

    Cheers,

    Richard

  • Craig O'Mahony 364 posts 918 karma points
    Oct 18, 2012 @ 13:40
    Craig O'Mahony
    0

    You, my friend, are an international superstar. :)

    I will be buying some licences for this (got about 12 sites to knock up) so I'll be more than happy to fire some moolah in your direction!

    Thanks again,

    Craig

  • Craig O'Mahony 364 posts 918 karma points
    Nov 06, 2012 @ 11:32
    Craig O'Mahony
    0

    Hi Richard,

    Thanks again for the code that you supplied, sadly what I need to do has changed. Bascially what's going to happen is that I'll going to be getting 2 SQL recordsets (one for the user information name, email, etc and the 2nd for the security roles (groups)). So what i need to do is amend, delete, and insert records based upon flagged fields in these recordsets.

    I have asked a question in the general forums as to the best way of coding these events into umbraco but as yet I've had no response and I thought that you know of a way. I don't want or expect you to do this for me as i want to begin to understand exactly how these 'event's hang together inside Umbraco.

    Thanks again,

    Craig

Please Sign in or register to post replies

Write your reply to:

Draft