5

I am trying to implement a GUI extension where I want the extension to be accessible only to the Users who are part of a certain user Group. How do I achieve this using the Anguilla framework?

1
  • Pl. indicate if this is for 2013 or 2011. It would help the readers. The difference is highlighted below, if you want to play with the XML The response from the API: var xml = Tridion.UI.UserSettings.getInstance().getXmlDocument(); is different between the two versions. To recurse through grpmemberships: var grpMemShip = xml.getElementsByTagName("tcm:GroupMemberships"); For 2011 we need to use the property childnodes but in 2013 its children. Commented Aug 29, 2013 at 15:52

1 Answer 1

6

You do this in the _isAvailable method you implemented in your command Javascript, optionally you can also do this in the _isEnabled method.

In there you will have to check what Group the User belongs to. To get the current User and its Groups you can use the following:

var settings = Tridion.UI.UserSettings.getJsonUserSettings(true);
if (settings)
{
    var groups = settings.User.Data.GroupMemberships;
}

Now the groups parameter will be be an object array containing the Groups the current User belongs to, they are formatted as JSON with a type, title and href (the TCMURI).

Now please note that Administrator users are usually not assigned to any Groups specifically (because they have all rights coming from their Administrator status already). Such a user will also not have an array of Groups in its GroupMemberships, but that will just contain one object (the Group "Everyone" for an Administrator).

To identify if a user is an Administrator, you can check out settings.User.Data.Privileges, that will have the value 1 (for an Administrator).

5
  • Tried accessing groups as an array, not able to iterate through the array. tried getting length using alert(groups.length); values comes up as 'undefined'
    – user677
    Commented Aug 23, 2013 at 9:38
  • Try settings.User.Data.GroupMemberships in your browser Console (after you have set the settings variable) and you will see what it contains. The browser developer tools and its Console window are really your best friend when developing UI extensions. When I request settings.User.Data.GroupMemberships.length it returns 3 but my user is part of 3 groups, if your user is a standard Administrator it might just be part of the group Everyone only, which will not show as an array indeed, but just the info of that Group (which might be a problem for your check of course). Commented Aug 23, 2013 at 9:57
  • +1. I think this type of setup may also need to check for (or intentionally ignore) "subgroup" scenarios (e.g. user belongs to "Global Author" which belongs to "Author"). Does GroupMemberships include parents of the user's immediate group? Commented Aug 26, 2013 at 20:40
  • @AlvinReyes I'm pretty sure that only the actual memberships are listed, so I'm expecting if rights are set using groups and subgroups, then the code in this extension will become a lot more complicated. On the other hand, there must be a way to check rights against groups, as that is what the UI does. So next to determining which group memberships the user has, there might also be some functions around that in the API. Commented Aug 27, 2013 at 7:50
  • Good point, we see the UI check rights/scope/permissions in the list of publications, how tabs display, schema and template drop-downs, etc. :-) Commented Aug 27, 2013 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.