3

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

samnaction
  • 1,194
  • 1
  • 17
  • 45

2 Answers2

3

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.

Jeff Potts
  • 10,468
  • 17
  • 40
  • I have gone through the link provide by you and I am able to build the .amp files and install this amp files in alfresco 5.0.c community version but after installing this file I am not able to see create site option. I have create a group with name "GROUP_SITE_CREATORS" and added admin user to this group. But still its not working. Could you please suggest a way how can I achieve it to in alfresco 5.0.c community version? – Ranjitsinh Mar 10 '15 at 12:49
  • I have not tested the add-on with 5.0.c which I do not consider to be a stable version. However, make sure you have deployed the module from the Share module deployment console. If you have deployed it and it still isn't working, create an issue on the git hub project page and I'll look at it. – Jeff Potts Mar 12 '15 at 22:37
  • Thanks for your response. I have done implementation for that in alfresco 5.0.c and its working fine as expected. – Ranjitsinh Mar 13 '15 at 04:37
1

I found a work around for this. First I hided the Create Site from header for everyone except admin. I added the following files.

I created file in shared/classes/alfresco/web-extension/site-data/extension/remove-create-site-extension.xml and typed

<extension>
 <modules>
  <module>
   <id>Remove create site menu option for non admin users</id>
   <version>1.0</version>
   <customizations>
    <customization>
     <targetPackageRoot>org.alfresco.share.header</targetPackageRoot>
     <sourcePackageRoot>ingen.header</sourcePackageRoot>
    </customization>
    <customization>
     <targetPackageRoot>org.alfresco.components.dashlets</targetPackageRoot>
     <sourcePackageRoot>ingen.dashlets</sourcePackageRoot>
    </customization>
   </customizations>
  </module>
 </modules>
</extension>

Then I created file in shared/classes/alfresco/web-extension/site-webscripts/ingen/header/share-header.get.js and added

//Find the "Sites" menu...
var sitesMenu = widgetUtils.findObject(model.jsonModel, "id", "HEADER_SITES_MENU");

if (sitesMenu != null) {
 if (!user.isAdmin) {
  sitesMenu.config.showCreateSite = false;
 }
}

Then I created file shared/classes/alfresco/web-extension/site-webscripts/ingen/dashlets/my-sites.get.js

if (!user.isAdmin) {
 model.showCreateSite = false;
}
samnaction
  • 1,194
  • 1
  • 17
  • 45
  • You just duplicated what the code I pointed to does but used a different package name. With the difference being yours restricts create site to administrators while mine restricts it to a group called Site Creators. – Jeff Potts Mar 16 '15 at 20:27