开发者

How do I retrieve a list of groups for each user using Alfresco Javascript API

开发者 https://www.devze.com 2023-03-18 02:34 出处:网络
I\'m totally new to Alfresco and their Javascript API so please bear that in mind... I want to be able to view a list of groups for every user in Alfresco repository.

I'm totally new to Alfresco and their Javascript API so please bear that in mind...

I want to be able to view a list of groups for every user in Alfresco repository.

This is the code I have at the moment:

  var gens = search.luceneSearch("TYPE:\"{http://www.alfresco.org/model/content/1.0}person\"");
  var logFile = space.childByNamePath("log_user_groups.csv");
  if (logFile == null) {
      logFile = space.createFile("log_user_groups.csv");
   }
   logFile.content = "";



   for (var i=0; i<gens.length;i++) {
     logFile.content += gens[i].properties["cm:userName"]+"\n";

     var groupes= people.getContainerGroups(gens[i]);

     for (var j=0; j<groupes.length;j++) {
       logFile.content += "\t"+groupes[j].properties.shortN开发者_JS百科ame +"\t";
       logFile.content += "\t"+groupes[j].properties.fullName +"\t";
       logFile.content += "\t"+groupes[j].properties.displayName +"\n";
     }
  }

The file is created with the user name shown correctly. However the group properties 'shortName', 'fullName' and 'displayName' are all null. In fact I printed out all the properties of the 'groupes' object and every field of the object is 'undefined'.

Does any body know what I am doing wrong?

Any help would be greatly appreciated.

Norm.


The easiest way would be to turn it on its head. Instead, for each group ask what groups and what users it contains. At the end, invert it.

You'll want to start with the Root Groups. The groups JS object in Alfresco will give you these, and others. It's implemented by ScriptAuthorityService, so you'll likely want to look at the JavaDocs

First up, get the root groups

var rootGroups = groups.getAllRootGroups() ;

For each group, get all the users in the group (direct and inherited) with getAllUsers(), and store those somewhere. Now, get all the child groups with getChildGroups(). Process each of these in the same way, recursing as needed.


I needed something similar (a complete list of groups) so I did this:

var temp = [];

function addGroups (groups)
  {
    for each (group in groups)
      {
        temp.push(group.getDisplayName());
        addGroups(group.getChildGroups());
      }
  }

addGroups(groups.getAllRootGroups());

This works to a point. The problem is that getDisplayName() returns a very non-pretty group name. Normally when dealing with documents and displaying a group name associated with a user I would do people.getContainerGroups() and use group.properties["cm:authorityName"] to get a displayable name (as mentioned above), however the groups I receive from getAllRootGroups() do not have properties (group.properties is undefined).

Does anyone have any idea why the group list returned this way wouldn't have the same properties as those returned by people.getContainerGroups()?


I guess you're using the wrong properties name.

You need the following:

  • Full Name: groupes[j].properties["usr:authorityName"]
  • Display Name: groupes[j].properties["usr:authorityDisplayName"]
  • Short Name: I don't know :) maybe groupes[j].properties["usr:authorityShortName"]

You can also just get the NodeRef id.

Then login to Alfresco explorer. Then go to the administration console --> Node Browser

Paste the id (it should be something like workspace://spacesStore//biglongUUID).There you can see al the properties related to the group.

Or you could just loop the groupes[k].properties map and print all the properties.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号