We have seen similar requirements many times. How do i find all the sites a particular user is a member of? One way is to write a SQL query with joins on the alf_ tables in the database. But Alfresco advises against hitting the data base directly. Instead we can use webscripts that are provided by Alfresco to get the information we need quickly.
Requisites
- Alfresco 5.x community/enterprise
- Google Chrome/Firefox
Steps
Similar to how you would access share we can access the Alfresco Admin console as shown below.
http://localhost:8080/alfresco/
which would contain the following screen
Note: Alfresco enterprise has an admin console that allows you to manage a host of Alfresco settings, apply licenses, get JMX dump, setup emails, etc. The community edition includes a basic console with very few options. Also most of the webscripts available in the enterprise version are also available in the community version and we would be using one of the webscript.
You can browse the available webscripts and see what works, and i have listed the one webscript that provides the site information we are looking for.
GET /alfresco/s/api/people/<username>/sites
I created 2 sites and added myself as a site member with different permission levels to each site.
The following webscript returns basic site info that i am a member of. The highlighted value is the username input param as defined in the webscript.
http://localhost:8080/alfresco/s/api/people/antony/sites
[ { "url": "\/alfresco\/s\/api\/sites\/moderatedsiteone", "sitePreset": "site-dashboard", "shortName": "moderatedsiteone", "title": "ModeratedSiteOne", "description": "Moderated site number one", "node": "\/alfresco\/s\/api\/node\/workspace\/SpacesStore\/c509777a-c7c9-4cd2-8a9a-2625a6c9e34b", "tagScope": "\/alfresco\/s\/api\/tagscopes\/workspace\/SpacesStore\/c509777a-c7c9-4cd2-8a9a-2625a6c9e34b", "siteManagers": [ "admin", "antony", "userConsumer" ], "isPublic": false, "visibility": "MODERATED" } , { "url": "\/alfresco\/s\/api\/sites\/publicsiteone", "sitePreset": "site-dashboard", "shortName": "publicsiteone", "title": "PublicSiteOne", "description": "Public site one", "node": "\/alfresco\/s\/api\/node\/workspace\/SpacesStore\/a71fee1d-bd11-480b-b044-2def3a7035e7", "tagScope": "\/alfresco\/s\/api\/tagscopes\/workspace\/SpacesStore\/a71fee1d-bd11-480b-b044-2def3a7035e7", "siteManagers": [ "admin", "userConsumer" ], "isPublic": true, "visibility": "PUBLIC" } ]
Notice the highlighted user names for the ‘Public site one’ in the example above.
The following is the permissions set in Share for this site.
As a test i am going to add my self as a manager of ‘Public site one’ in share.
Now when i use the same url to get the list of members of the site i can see ‘Antony’ as a manager in the response.
http://localhost:8080/alfresco/s/api/people/antony/sites
[ { "url": "\/alfresco\/s\/api\/sites\/moderatedsiteone", "sitePreset": "site-dashboard", "shortName": "moderatedsiteone", "title": "ModeratedSiteOne", "description": "Moderated site number one", "node": "\/alfresco\/s\/api\/node\/workspace\/SpacesStore\/c509777a-c7c9-4cd2-8a9a-2625a6c9e34b", "tagScope": "\/alfresco\/s\/api\/tagscopes\/workspace\/SpacesStore\/c509777a-c7c9-4cd2-8a9a-2625a6c9e34b", "siteManagers": [ "admin", "antony", "userConsumer" ], "isPublic": false, "visibility": "MODERATED" } , { "url": "\/alfresco\/s\/api\/sites\/publicsiteone", "sitePreset": "site-dashboard", "shortName": "publicsiteone", "title": "PublicSiteOne", "description": "Public site one", "node": "\/alfresco\/s\/api\/node\/workspace\/SpacesStore\/a71fee1d-bd11-480b-b044-2def3a7035e7", "tagScope": "\/alfresco\/s\/api\/tagscopes\/workspace\/SpacesStore\/a71fee1d-bd11-480b-b044-2def3a7035e7", "siteManagers": [ "admin", "antony", "userConsumer" ], "isPublic": true, "visibility": "PUBLIC" } ]
This webscript would only return the site details and the site manager information. it would not list all the users with other permissions of the site. That information can be retrieved using a SQL query or a combination of other webscripts and would be covered in future posts.