AnsweredAssumed Answered

[How To] Handle Share roles into FTL

Question asked by gric on Dec 6, 2010
Latest reply on Dec 6, 2010 by wabson
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 (
           //If we are, call the repository to see if the user is site manager or not
           userIsSiteManager = false;
      var obj =["memberships"];
      if (!obj)
           var json ="/api/sites/" + + "/memberships/" + stringUtils.urlEncode(;
           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>
        <span> </span>

Should be useful to some of you :mrgreen: !