cancel
Showing results for 
Search instead for 
Did you mean: 

Permission API

spring777
Champ in-the-making
Champ in-the-making
Hi everyone,

Suppose the following code :


<#if user.isAdmin>
<span><a href="${url.context}/proxy/alfresco${version.downloadURL}" class="download">${msg("link.download")}</a></span>
</#if>

I am looking for a similar expression that make display the span only if the user role for the current node is different from a role X (added role) which is supposed to be a consumer without the download ability

I tried all combinations of the userhome and permissions objects but I got always something like this :


Exception: freemarker.core.InvalidReferenceException - Expression userhome is undefined on line 45, column 38 in org/alfresco/components/document-details/document-versions.get.html.ftl.
freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)
….
7 REPLIES 7

kriton
Champ in-the-making
Champ in-the-making
I had a similar question. This is how I solved it:

On the controller file for your webscript (should be a file with the same name as the .ftl one but with a .js extension) do the following:
model.permissions = AlfrescoUtil.getSiteMembership(model.site).role ;

Then on your ftl file of the webscript you can do this check :

<#if permissions!="SiteConsumer" >
<span><a href="${url.context}/proxy/alfresco${version.downloadURL}" class="download">${msg("link.download")}</a></span>
</#if>

You can replace SiteConsumer with any role you like.

spring777
Champ in-the-making
Champ in-the-making
Hello,

Can you post the content of AlfrescoUtil.getSiteMembership function,  it doesnt exist in my Alfresco

Thank you

kriton
Champ in-the-making
Champ in-the-making
Alfresco utils library is located in this fodler: share\WEB-INF\classes\templates\org\alfresco\import\alfrsco-util.js

You should import it in your js controller like this :
<import resource="classpath:/alfresco/templates/org/alfresco/import/alfresco-util.js">

Perhaps thats missing from your code ?

If not, this is the code pasted from that file:
   
   /**
    * Retrieve current user's site membership.
    *
    * @method getSiteMembership
    * @param siteId {string} Site to get details for
    * @return {object} Object literal of the form
    * <pre>
    *    isMember: true|false,
    *    isManager: true|false
    *    role: "SiteManager"|"SiteCollaborator"|"SiteContributor"|"SiteConsumer"
    * </pre>
    */
getSiteMembership: function getSiteMembership(siteId)
   {
      var obj =
      {
         isMember: false,
         isManager: false,
         role: ""
      };

      var json = remote.call("/api/sites/" + encodeURIComponent(siteId) + "/memberships/" + encodeURIComponent(user.name));
      if (json.status == 200)
      {
         response = eval('(' + json + ')');
         if (response)
         {
            obj =
            {
               isMember: true,
               isManager: response.role == "SiteManager",
               role: response.role
            };
         }
      }
      return obj;
   }

However this might not help you, as it calls another webscript within alfresco that return a json response about the current user's site membership status. That webscript might be missing on your version as well ? I have no alfresco experience prior to 4.0 so I may be unable to help you there.
You can test if you have that webscript by running http://yourserver/alfresco/service/api/sites/{siteid}/memberships/{username}
You should see a json response on your browser.

spring777
Champ in-the-making
Champ in-the-making
All that is missing in version 3.4, I will install Alfresco 4 and try to copy stuff in 3.4

before that I want just to ensure something, do this function really return the current user's role for the CURRENT NODE ?

kriton
Champ in-the-making
Champ in-the-making
It returns the user's role for the given site.

spring777
Champ in-the-making
Champ in-the-making
Ok thank you so much Kriton

rudyantolin
Champ in-the-making
Champ in-the-making
How about if I try to extend the download link to be watermark-first-then-download link? Are there any possibilities to add extended permission API to my new watermark-first-then-download link?

Best Regards,
Rudyanto