Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide create site link for particular user

I am on Alfresco 4.2e Community Edition.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[i].itemName == "GROUP_"+group || groups[i].itemName == "GROUP_ALFRESCO_ADMINISTRATORS"){
        return true; // found group
      }else{
        mygroup = mygroups+groups[i].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

like image 767
samnaction Avatar asked Feb 02 '26 15:02

samnaction


1 Answers

Here is a version that removes the link from the header, the dashlet, AND the welcome dashlet (don't forget about that one). Plus, it changes the underlying permissions to prevent circumventing the UI. In my version I restrict the create site capability to members of a "Site Creators" group.

like image 105
Jeff Potts Avatar answered Feb 05 '26 09:02

Jeff Potts



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!