cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the user role in a site

svetlingulev
Champ in-the-making
Champ in-the-making
hi
I have this webscript that takes the users data, but i can't get the user role("Conributor","Collaborator" ect.) in a site.
Here is my script

<javascript>
var gens = search.luceneSearch("TYPE:\"{http://www.alfresco.org/model/content/1.0}person\"");
var a = [];
 
for (var i=0; i<gens.length;i++) {
var username = gens.properties["cm:userName"];
var firstname = gens.properties["cm:firstName"];
var lastname = gens.properties["cm:lastName"];
var umail = gens.properties["cm:email"];

var b = [];
var o = [];
var groups = people.getContainerGroups(gens);
for(var j=0; j<groups.length; j++) {
  b.push(""+ groups[j].properties['authorityName']+"");
  o.push(""+ groups[j].properties['authorityType']+"");
}

var sites = siteService.listUserSites(username);
var g=[]
for(var j=0; j<sites.length; j++) {
      g.push( ""+ sites[j]['shortName']+"");
/* o.push(""+ sites[j]['cm:authorityType']+""); */
}

a.push({
   'username' : username,
        'firstname' : firstname,
        'lastname' : lastname,
        'mail' : umail,
   'groups' : b.join(';'),
   'sites' : g.join(';'),
        'athority' : o.join(';')
})
}

model.test = a;

</javascript>

Any help will be appreciated.
Thanks
4 REPLIES 4

kaynezhang
World-Class Innovator
World-Class Innovator
For every site please call listMembers of site object

for(var j=0; j<sites.length; j++) {
      g.push( ""+ sites[j]['shortName']+"");
/* o.push(""+ sites[j]['cm:authorityType']+""); */
   
   var members = sites[j].listMembers(null, null, 0, false);
   for(var x=0; x<members.length; x++){
        ***
   }
   

}

svetlingulev
Champ in-the-making
Champ in-the-making
ok, but this returns every role available in site, not just the role of the user.
I want only the role of the user is the site.

kaynezhang
World-Class Innovator
World-Class Innovator
No ,
listMembers(null, null, 0, false);
method will return an arry whose key is site's member's name and value is member's role.

If you want to get only one  user's role in this site,you can use
getMembersRole (authorityName)
method

svetlingulev
Champ in-the-making
Champ in-the-making
thanks. it works Smiley Happy