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
!