Want to display user's permission on folder under a site

cancel
Showing results for 
Search instead for 
Did you mean: 
Syedjunaid
Active Member II

Want to display user's permission on folder under a site

Jump to solution

Hello Everyone,

I am using Alfresco 6 (dockerized). I have deployed Alfresco in a production enviornment and my clients wants me to create a reporting page (separate surf page for a specific report) , now in that reporting page I want to call a webscript which displays the folders of site and a user's permissions on these folders.

What would be the api or is there any tool that does the same things like my requirement. Any help would be highly appreciated. Looking into that tool will help me to get an idea of what could be done to get my desired outputs.

Thank you.

 

Regards, 

Syed Junaid

1 Solution

Accepted Solutions
sanjaybandhniya
Intermediate

Re: Want to display user's permission on folder under a site

Jump to solution

Check This. You will get idea how to get folder's of site.

private void listSites() {

		List<SiteInfo> sites = siteService.listSites(null, null);
		for (SiteInfo site : sites) {
			System.out.println(site.getShortName());
			listFolder(site.getShortName());

		}

	}

	private void listFolder(String siteName) {

		String str = "PATH:\"/app:company_home/st:sites/cm:" + siteName
				+ "/cm:documentLibrary//*\" AND TYPE:\"cm:folder\"";

		StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
		SearchParameters sp = new SearchParameters();
		sp.addStore(storeRef);
		sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
		sp.setQuery(str);
		ResultSet rs = searchService.query(sp);
		if (rs != null && rs.length() > 0) {
			List<NodeRef> list = rs.getNodeRefs();
			list.forEach(folder -> {
				System.out.println(nodeService.getProperty(folder, ContentModel.PROP_NAME));
				Set<AccessPermission> accessPermission = permissionService.getAllSetPermissions(folder);
				accessPermission.forEach(permission -> {
					System.out.println(permission);
				});

			});
		}

	}
Thanks & Regards,
Sanjay

View solution in original post

7 Replies
sanjaybandhniya
Intermediate

Re: Want to display user's permission on folder under a site

Jump to solution

You can create custom webscript which can return folder's list  with permission and you can use that in surf page.

Thanks & Regards,
Sanjay
Syedjunaid
Active Member II

Re: Want to display user's permission on folder under a site

Jump to solution

Dear @sanjaybandhniya ,

I am doing exactly as you're saying but the problem is to get folders and its permissions, it is essential to have a your folder's node id, which is understandable.But I want my webscript to work in a manner that it should display all sites, it's users, those user's role, specifics Folders in that site and the user's permissions which are listed with sites. I have got the data of all Sites,Users and Their Role in Site... but cannot get the remaining data. As  I have multiple sites im unable to understand that how can I associate a site folder's node id with it's associated site.

Take a look at this picture of my custom report, you may get an idea of my requirement. The "Not Fetched Yet" is hardcoded in my webscript's html.

userreports.png

sanjaybandhniya
Intermediate

Re: Want to display user's permission on folder under a site

Jump to solution

Check This. You will get idea how to get folder's of site.

private void listSites() {

		List<SiteInfo> sites = siteService.listSites(null, null);
		for (SiteInfo site : sites) {
			System.out.println(site.getShortName());
			listFolder(site.getShortName());

		}

	}

	private void listFolder(String siteName) {

		String str = "PATH:\"/app:company_home/st:sites/cm:" + siteName
				+ "/cm:documentLibrary//*\" AND TYPE:\"cm:folder\"";

		StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
		SearchParameters sp = new SearchParameters();
		sp.addStore(storeRef);
		sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
		sp.setQuery(str);
		ResultSet rs = searchService.query(sp);
		if (rs != null && rs.length() > 0) {
			List<NodeRef> list = rs.getNodeRefs();
			list.forEach(folder -> {
				System.out.println(nodeService.getProperty(folder, ContentModel.PROP_NAME));
				Set<AccessPermission> accessPermission = permissionService.getAllSetPermissions(folder);
				accessPermission.forEach(permission -> {
					System.out.println(permission);
				});

			});
		}

	}
Thanks & Regards,
Sanjay

View solution in original post

Syedjunaid
Active Member II

Re: Want to display user's permission on folder under a site

Jump to solution

Hi @sanjaybandhniya ,

Thank you for the webscript, can you please tell me where should I place this webscript? . I am using docker version of Alfresco 6 and currently I have placed my webscript in my share docker container at this path "/usr/local/tomcat/shared/classes/alfresco/web-extension/site-webscripts/org/alfresco/training".

One more thing I told you that I got  the sites list and I did this through javascript api, didn't call any site Service like you did above. I tried getting the list of sites through siteService but alfresco returned the errror "undefined : siteService", anyways got the site list through site-list api in alfresco api-explorer. 

I think im not placing my webscript at the right path, therefore alfresco returned undefined on siteService.

This is my current webscript which is getting all sites, Site's users and their roles in site.

 

var siteJSON = {}
var connector = remote.connect("alfresco-api");
var result = connector.get("/-default-/public/alfresco/versions/1/sites");
var final_results = [];
if (result.status.code == status.STATUS_OK) {
  var siteJSON = jsonUtils.toObject(result);
  model.sites = siteJSON["list"]["entries"];
  for (var i = 0; i < model.sites.length; i++){
    var output = connector.get("/-default-/public/alfresco/versions/1/sites/" + model.sites[i].entry.id + "/members");
    if (result.status.code == status.STATUS_OK) {
      siteJSON= jsonUtils.toObject(output);
      model.members = siteJSON["list"]["entries"];
      for (var j = 0; j < model.members.length; j++){
         var final_result = {};
         final_result["role"]=model.members[j].entry.role;
         final_result["user"]=model.members[j].entry.person.firstName;
         final_result["site"]=model.sites[i].entry.title;
         final_results.push(final_result);
      }
    }
  }
model.results = final_results;
}

 

 

Want to try your pruposed solution but don't know where to place the webscript.

Thank you.

sanjaybandhniya
Intermediate

Re: Want to display user's permission on folder under a site

Jump to solution

You need to use sdk for this.

For Java backed Webscript you need to register it.

 

Thanks & Regards,
Sanjay
Syedjunaid
Active Member II

Re: Want to display user's permission on folder under a site

Jump to solution

Dear @sanjaybandhniya ,

Thank you for proving your java code, it helped me alot for getting sites,users,roles and site's folder.

Can you pleaase tell me how can I get the permissions on those folders? like whose the Site 's Manager/Collaborator/Contributor/Consumer on these folders that I got through your webscript. What would be the change in your webscript that will get me these permissions I mentioned.

 

4535992
Established Member II

Re: Want to display user's permission on folder under a site

Jump to solution

If you find useful you can use this piece of code i found on https://github.com/loftuxab/permission-label/blob/master/src/main/amp/web/components/documentlibrary... :

function getRolefromNodeRecord(record) {
    //CancelCheckOut	ChangePermissions	CreateChildren	Delete	Unlock	Write
    //Collaborator     0	0	1	0	0	1
    //Contributor	   0	0	1	0	0	0
    //Consumer	       0	0	0	0	0	0
    //Manager	       0	1	1	1	0	1
    var decisionRow = "";
    decisionRow += record.jsNode.permissions.user.CancelCheckOut ? "1" : "0";
    decisionRow += record.jsNode.permissions.user.ChangePermissions ? "1" : "0";
    decisionRow += record.jsNode.permissions.user.CreateChildren ? "1" : "0";
    decisionRow += record.jsNode.permissions.user.Delete ? "1" : "0";
    decisionRow += record.jsNode.permissions.user.Unlock ? "1" : "0";
    decisionRow += record.jsNode.permissions.user.Write ? "1" : "0";

    var roleKey = "";

    switch (decisionRow) {
        case "001001":
            roleKey = "role.SiteCollaborator";
            break;
        case "001000":
            roleKey = "role.SiteContributor";
            break;
        case "000000":
            roleKey = "role.SiteConsumer";
            break;
        case "011101":
            roleKey = "role.SiteManager";
            break;
        //below are almost never available.
        case "111111":
            roleKey = "role.SiteOwner";
            break;
        default:
            roleKey = "role.SiteOther";
            break;
    }
    return Alfresco.util.message(roleKey);
}