cancel
Showing results for 
Search instead for 
Did you mean: 

[How To] Handle Share roles into FTL

gric
Champ in-the-making
Champ in-the-making
This piece of code was very useful to me. I think it worth a post.
It was retrieved from the official RSS feed dashlet.

The idea is to display a Dashlet configuration link only for Site Managers. Your dashlet contains usual Model, Controller and View files.
In your JS (ie mydashlet.get.js), add the following to your logic :
var userIsSiteManager = true;
   //Check whether we are within the context of a site
   if (url.templateArgs.site)
   {
           //If we are, call the repository to see if the user is site manager or not
           userIsSiteManager = false;
      var obj = context.properties["memberships"];
      if (!obj)
      {
           var json = remote.call("/api/sites/" + page.url.templateArgs.site + "/memberships/" + stringUtils.urlEncode(user.name));
           if (json.status == 200)
           {
              obj = eval('(' + json + ')');
           }
        }
        if (obj)
        {
              userIsSiteManager = (obj.role == "SiteManager");
        }
   }
model.userIsSiteManager = userIsSiteManager;

(We basically store a boolean - is current user a SiteManager ? - into userIsSiteManager.)
Then, just use it into your FTL (mydashlet.get.html.ftl) as follows :

<div class="dashlet myDashlet">
    <div class="title">
        <a id="${args.htmlid}-title-link"
           class="title-link theme-color-5">${msg('label.header')}</a>
        <#if userIsSiteManager>
            <a id="${args.htmlid}-myDashletConfig-link" class="configure theme-color-5" href="#">${msg("label.configure")}</a>
        </#if>
        <span> </span>
    </div>
    […]
</div>

Should be useful to some of you :mrgreen: !
2 REPLIES 2

wabson
Star Contributor
Star Contributor
Good thinking, I am sure it will be useful to others. I use the same bit of code quite a bit in my Share Extras dashlets - http://code.google.com/p/share-extras/

Given that this is needed by any dashlets that display a configuration dialogue and possibly others as well, it would be even better if this was available as a function (or possibly a macro) from an include FTL file, to save duplicating the code in every single dashlet that needs it.

Cheers,
Will.

wabson
Star Contributor
Star Contributor
Raised as an enhancement in JIRA (thanks Mike)

https://issues.alfresco.com/jira/browse/ALF-6042