cancel
Showing results for 
Search instead for 
Did you mean: 

Hos to get full list of users & their belonging groups ?

msevestre
Champ in-the-making
Champ in-the-making
Hello

I'm trying to generate a file with a JS script to help me to administrate users & group: I'd like to obtain a list with full clear test of user names & groups which they are attaached to ?

I tried to create a Javascript script that is nearly working, but I am not able to display "readable" user names & groups.

Here is the current source code:

var gens = people.getPeople(null);

var logFile = space.childByNamePath("log_users.txt");
if (logFile == null) {
   logFile = space.createFile("log_users.txt");
}
logFile.content = "";

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

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

  for (var j=0; j<groupes.length;j++) {
    logFile.content += "\t"+groupes[j].name+"\n";
  }

}

I currently have an output of this kind :

workspace://SpacesStore/71a950d8-f26b-40ee-a496-51133147c345
   GROUP_ALFRESCO_ADMINISTRATORS
   d60ba031-128f-408e-aaa4-de69ce7ddd95
   e7252aad-8ef9-4986-90bd-7664e86384ab
workspace://SpacesStore/a0f6862c-ebb3-432f-b36e-4ba7076a2dc2
workspace://SpacesStore/8cb10f0a-eb91-4e12-96c8-c9321c6d8a08
workspace://SpacesStore/b019d0ee-c45d-44ea-b750-e0aeedf85abb
   GROUP_ALFRESCO_ADMINISTRATORS
   d60ba031-128f-408e-aaa4-de69ce7ddd95
   e7252aad-8ef9-4986-90bd-7664e86384ab

as you can see, user names have a "workspace://" type (using .name property give me "undefined" for all users). Groups are with a reference, except for basic groups (GROUP_ALFRESCO_ADMINISTRATORS, EMAIL, etc.) that are displayed clearly.

Note: if any other script exists, no problem to froget mine to use another one Smiley Happy

Thanks for any help
Matt
17 REPLIES 17

jayjayecl
Confirmed Champ
Confirmed Champ
Try that one


var gens = people.getPeople(null);

var logFile = space.childByNamePath("log_users.txt");
if (logFile == null) {
   logFile = space.createFile("log_users.txt");
}
logFile.content = "";

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

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

  for (var j=0; j<groupes.length;j++) {
    var groupName = groupes[j].properties["authorityDisplayName"];
    logFile.content += "\t"+ groupName +"\n";
  }

}

msevestre
Champ in-the-making
Champ in-the-making
Hi !

No luck, the log file have the followiong result:

undefined
   null
   null
   null
undefined
undefined
undefined
   null
   null
   null
undefined
   null
   null

Matt

jayjayecl
Confirmed Champ
Confirmed Champ
Again,


    var gens = people.getPeople(null);

    var logFile = space.childByNamePath("log_users.txt");
    if (logFile == null) {
       logFile = space.createFile("log_users.txt");
    }
    logFile.content = "";

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

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

      for (var j=0; j<groupes.length;j++) {
        var groupName = groupes[j].properties["cm:authorityDisplayName"];
        logFile.content += "\t"+ groupName +"\n";
      }

    }

msevestre
Champ in-the-making
Champ in-the-making
Hi….

still not working:

Failed to execute script 'workspace://SpacesStore/95602fd0-2b70-4929-a0ae-de0066726a60': TypeError: Cannot read property "cm:userName" from undefined (AlfrescoScript#10)

If i comment line #10, then the script is executed but I only have "null" disaplyed on each line of the log file…

Perhaps there's another way to do this ? (maybe the base of my script is not a good idea)

Matt

jayjayecl
Confirmed Champ
Confirmed Champ
What if you change this line :


var gens = people.getPeople(null);

by


var gens = search.luceneSearch("TYPE:{http://www.alfresco.org/model/content/1.0}person");

msevestre
Champ in-the-making
Champ in-the-making
Hi !

Then I get this error:

Failed to execute script 'workspace://SpacesStore/95602fd0-2b70-4929-a0ae-de0066726a60': Failed to execute search: TYPE:{http://www.alfresco.org/model/content/1.0}person

Matt

jayjayecl
Confirmed Champ
Confirmed Champ
All right, here it is (I had to test it on my environment to be sure)


    //var gens = people.getPeople(null);

var gens = search.luceneSearch("TYPE:\"{http://www.alfresco.org/model/content/1.0}person\"");
    var logFile = space.childByNamePath("log_users.csv");
    if (logFile == null) {
       logFile = space.createFile("log_users.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["usr:authorityDisplayName"]+"\n";
      }

    }


Hope this will be valuable to you 😄

msevestre
Champ in-the-making
Champ in-the-making
Hi !

Well… username are now correctly displayed (thanks  :mrgreen: !)… but I still get "null" as groups names…  :?

Matt

jayjayecl
Confirmed Champ
Confirmed Champ
this is due to the way you built your groups.
Then replace usr:authorityDisplayName by usr:authorityName