AnsweredAssumed Answered

How to hide create site link for particular user

Question asked by samnaction on Mar 20, 2014
Latest reply on Mar 21, 2014 by kavilash23
I am able to restrict site creation for a particular group by modifying the following files.

In public-services-security-context.xml

org.alfresco.service.cmr.site.SiteService.createSite=ACL_METHOD.ROLE_ADMINISTRATOR,ACL_METHOD.GROUP_SITECREATORS

In sites.get.js and mysites.get.js I added this

var createSiteVisible = userHasGroup(user.name, 'SITECREATORS');
model.createSiteVisible = createSiteVisible;

function userHasGroup(username, group) {
   var result = remote.call("/api/people/" + stringUtils.urlEncode(username) + "?groups=true");
   if (result.status == 200 && result != "{}")
   {
      var user = eval('(' + result + ')');

      var groups = new Array();
      groups = user.groups;
      var mygroups = "";
      for (i=0; i<groups.length; i++)
      {                  
         if (groups.itemName == "GROUP_"+group || groups.itemName == "GROUP_ALFRESCO_ADMINISTRATORS"){
        return true; // found group
      }else{
        mygroup = mygroups+groups.displayName;
      }
      }

      return false;
   }
   else return false;
}

In my-sites.get.html.ftl and sites.get.html.ftl I modified the condition as

<#if createSiteVisible>
           <span class="align-right yui-button-align">
              <#if showCreateSite>
              <span class="first-child">
                 <a href="#" id="${id}-createSite-button" class="theme-color-1">
                    <img src="${url.context}/res/components/images/site-16.png" style="vertical-align: text-bottom" />
                    ${msg("link.createSite")}</a>
              </span>
              </#if>
           </span>  
</#if>

User is not able to create site now.But still I am getting create site link in header menu. How to hide create site for the users.

!user.isAdmin refers to admin user. What is the java script to refer a group?. Thank you

alfresco-share

Outcomes