cancel
Showing results for 
Search instead for 
Did you mean: 

How to hide create site link for particular user

samnaction
Champ in-the-making
Champ in-the-making
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
1 REPLY 1

kavilash23
Champ on-the-rise
Champ on-the-rise
Hello,

You need to create an extension module and override the Share Header Menu controller (share-header.get.js) with something as follows;

var sitesMenu = widgetUtils.findObject(model.jsonModel, "id", "HEADER_SITES_MENU");
if (sitesMenu != null)
{
      sitesMenu.config.showCreateSite = false;
      var result = remote.call("/api/people/" + encodeURIComponent(user.name) + "?groups=true");
       if (result.status == 200)
          {
           var i;        

          // Create javascript objects from the server response
          // This is the User and it also contains all groups.
           var userValue = eval('(' + result + ')');


           if (userValue.groups.length != 0)
              {

                 for (i = 0; i < userValue.groups.length; i++)
                 {
                      if (userValue.groups.itemName == "GROUP_SITE_CREATORS" || userValue.groups.itemName == "GROUP_ALFRESCO_ADMINISTRATORS" ) {
         
         sitesMenu.config.showCreateSite = true;
         }   
           
                 }
              }          

          }
}

Hope this help!