cancel
Showing results for 
Search instead for 
Did you mean: 

List all site roles of a user

joonas
Champ in-the-making
Champ in-the-making
Hello,

I'm trying to list all site roles (or preferably site groups) of a user.

I'm familiar with
GET /alfresco/s/api/people/{userName}?groups=true
to get the groups the user is a member of, but it doesn't return site groups such as GROUP_site_{sitename}_SiteContributor. Could I somehow modify this request to also get all site groups of the user?

Other request I have tried to use to solve this is
GET /alfresco/s/api/people/{userid}/sites?size={pagesize?}&pos={position?}&roles={roles?}
which lists sites the user is an explicit member of, but this doesn't return the exact member roles/groups of {userid}. Could I perhaps use the roles-parameter to find this out? I have learned that using roles=user I can get the site roles of the user making the request, but I want to find out the site roles of {userid}. 

I can also get the user's role for a site by using
GET /alfresco/s/api/sites/{shortname}/memberships/{authorityname}
, but using this I would have to loop through all the sites to get the list of all site roles of a user, which doesn't seem a nice solution.

Is there a way to solve this problem?

Thanks
5 REPLIES 5

niketapatel
Star Contributor
Star Contributor
I dont think OOB script is availble which can give you all groups including site groups.
Either you can create your custom script OR to get site role group use this script  /alfresco/s/api/people/{userid}/sites?size={pagesize?}&pos={position?}&roles={roles?} and manually create group name with site short name and site role.

But if user is in some normal group and that group is added in site and if you manually create user site group then result wont be accurate. Better to create your custom script!

joonas
Champ in-the-making
Champ in-the-making
thanks for the reply. It would be OK for me to use the script
/alfresco/s/api/people/{userid}/sites?size={pagesize?}&pos={position?}&roles={roles?}
and manually create group name with site short name and site role. However I don't know how to get the site role information of {userid} by using this script. By default the result doesn't include that.

Could you give an example how to do this?

niketapatel
Star Contributor
Star Contributor
You need to pass that userid in script URL. For an example I need to get admin all site role groups then I will execute below script which will give me response as below. So now I have site shortName and admin siteRole for all his/her sites. So merge them manually and create group name for particular user id
I hope I understood your question correctly!

http://localhost:8080/alfresco/s/api/people/admin/sites?roles=user



[
{
   "url": "\/alfresco\/s\/api\/sites\/swsdp",
   "sitePreset": "site-dashboard",
   "shortName": "swsdp",
   "title": "Sample: Web Site Design Project",
   "description": "This is a Sample Alfresco Team site.",
   "node": "\/alfresco\/s\/api\/node\/workspace\/SpacesStore\/b4cff62a-664d-4d45-9302-98723eac1319",
   "tagScope": "\/alfresco\/s\/api\/tagscopes\/workspace\/SpacesStore\/b4cff62a-664d-4d45-9302-98723eac1319",
   "siteRole": "SiteManager",
   "isPublic": true,
   "visibility": "PUBLIC"
}
      ,
{
   "url": "\/alfresco\/s\/api\/sites\/test",
   "sitePreset": "site-dashboard",
   "shortName": "test",
   "title": "test",
   "description": "",
   "node": "\/alfresco\/s\/api\/node\/workspace\/SpacesStore\/ed4aabe5-0682-4367-8fc9-1afac3863ad6",
   "tagScope": "\/alfresco\/s\/api\/tagscopes\/workspace\/SpacesStore\/ed4aabe5-0682-4367-8fc9-1afac3863ad6",
   "siteRole": "SiteManager",
   "isPublic": true,
   "visibility": "PUBLIC"
}
      
]

joonas
Champ in-the-making
Champ in-the-making
According to my testing, adding roles=user actually returns the siteRole value for the user who is executing this script (and NOT for the user defined in the script as {userid}). You get two sites as a result because you have defined admin as the {userid} and admin is a member of these two sites. This is expected. However, you have gotten "siteRole": "SiteManager" because you are signed in as admin to Alfresco and therefore it fetches the siteRole value for the admin user. It is just a coincidence that the same user is defined in the script as {userid}. So according to my testing the script does not work as you described above.

Would you be able to confirm this?

niketapatel
Star Contributor
Star Contributor
Oh Yes, I didnt notice it. I checked script code and found that while retrieving user site role "person.properties.userName" is being taken which is current logged in user rather than one which is passed in script URL. Logically I believe it should be user id that is passed in script URL.

Anyway I would suggest to create simple JAVA backed script and get required user group. Below will get you all groups including site role groups.


      final Set<String> authorities = this.serviceRegistry.getAuthorityService().getContainingAuthoritiesInZone(AuthorityType.GROUP, userid, null, null, 1000);