cancel
Showing results for 
Search instead for 
Did you mean: 

Disable 'Create site' link

lees
Champ in-the-making
Champ in-the-making
Hi all,

I want to disable  the 'Create Site' link from the 'My sites' dashlet in case the user is not belong to admin group.

let me know any pointers as to how to implement..

-thx
41 REPLIES 41

wengm
Champ in-the-making
Champ in-the-making
Correctly, with official solution, the "Create Site" link does not disappear. There is also no dedicated error message to tell you what happened.  Thus, the better solution is to wrap the code just in below way.

Edit file: /opt/alfresco-4.0.b/tomcat/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/dashlets/my-sites.get.html.ftl

        
<#if user.isAdmin>
         <span class="align-right yui-button-align">
            <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>
         </span>
        </#if>


Note: Change takes effect only after restarting alfresco server

michaelc
Champ on-the-rise
Champ on-the-rise
Correctly, with official solution, the "Create Site" link does not disappear. There is also no dedicated error message to tell you what happened.  Thus, the better solution is to wrap the code just in below way.

Edit file: /opt/alfresco-4.0.b/tomcat/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/dashlets/my-sites.get.html.ftl

        
<#if user.isAdmin>
         <span class="align-right yui-button-align">
            <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>
         </span>
        </#if>


Note: Change takes effect only after restarting alfresco server

great minds think alike - only thing I would add is we created a group that we could assign users into vs. allowing only admins.
this allows for you to give this right to some users without giving them the whole admin authority.
then change the if to look for  create site
<#if createSite>

added code in my-sites.get.js

function main()
{
   createSite = false

       var result = remote.call("/api/people/" + stringUtils.urlEncode(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[i].itemName == "GROUP_ALFRESCO_ADMINISTRATORS") createSite = true;
                 }
              }           

          }
   
   // Check for IMAP server status
   var result = remote.call("/imap/servstatus"),
      imapServerEnabled = (result.status == 200 && result == "enabled");

   // Prepare the model for the template
   model.imapServerEnabled = imapServerEnabled;
   model.createSite = createSite;
}

main();

afaust
Legendary Innovator
Legendary Innovator
Hello,

what about simply using the permission on the Sites folder for this? Remove the "Contributor" for "Everyone" and set "Contributor" for the specific users / groups you want to grant that privilege. Check the permission in the web script instead of an arbitrary and hard-coded group.

Regards
Axel

dnallsopp
Champ in-the-making
Champ in-the-making
The permission on the Sites folder is only EVERYONE:Consumer, in Community 4.0.d.

Removing this permission causes an Internal Server Error when a Contributor user logs in (presumably because the MySites dashlet, at least, is trying to access the folder?). Looks OK for an admin though.

But the Contributor can still create a site, even though they can't see the Sites folder. Looks like the code that creates the site runs with higher privileges?

chrisokelly
Champ on-the-rise
Champ on-the-rise
Hi,

In Alfresco Community 4.0.d, the code michaelc referenced above works fine (thanks very much Michael!). just wanted to point out that this does the trick for the my sites dashlet, to do the same fix for the sites drop down in the header, I followed these steps:
(note, for me, in ubuntu, $ALFRESCO_ROOT is /opt/alfresco-4.0.d)
  1. Create the folder structure: $ALFRESCO_ROOT/tomcat/shared/classes/alfresco/web-extension/site-webscripts/org/alfresco/modules/header .

  2. in the newly created 'header' folder, paste the following two files from $ALFRESCO_ROOT/tomcat/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/modules/header : sites.get.html.ftl and sites.get.js

  3. in the new copy of sites.get.html.ftl, make the following change to lines 35-39:
  4.       <#if createSite><ul class="create-site-menuitem">
             <li>
                <a href="#" onclick='Alfresco.util.ComponentManager.get("${id_js}").showCreateSite(); return false;'>${msg("label.create-site")}</a>
             </li>
          </ul></#if>

  5. in the new copy of sites.get.js, add the following code starting after line 99:
  6.         createSite=false;
            var result=remote.call("/api/people/"+stringUtils.urlEncode(user.name)+"?groups=true");
            if (result.status==200)
                    {
                    var i;
                    var userValue=eval('(' + result + ')');
                    if (userValue.groups.length!=0)
                            {
                            for (i=0;i<userValue.groups.length;i++)
                                    {
                                    if (userValue.groups[i].itemName=="GROUP_SITE_CREATORS") createSite=true;
                                    }
                            }
                    }
       model.createSite=createSite;

  7. Restart the server
You'll need to create a group with the ID SITE_CREATORS and add relevant users to it.

jtrammel
Champ in-the-making
Champ in-the-making
For Alfresco Enterprise version 4.1.1 you would change the "my-sites.get.html.ftl" file as shown in an earlier post, but to hide the option on the "Sites" dropdown you need to apply the following code to "sites.get.html.ftl"

      <#if user.isAdmin>
      <ul class="create-site-menuitem">
         <li>
            <a href="#" onclick="Alfresco.util.ComponentManager.get('${id_js}').showCreateSite(); return false;">${msg("label.create-site")}</a>
         </li>
      </ul>
      </#if>

jpotts
World-Class Innovator
World-Class Innovator
This is an old thread, but it is a popular request. I've created an add-on that (1) changes the permissions and (2) removes all of the links. It does this using the new extension points available in 4.2 which minimizes the amount of code necessary.

https://addons.alfresco.com/addons/share-site-creators

Jeff

dhaack
Champ in-the-making
Champ in-the-making
Jeff, works in the community version 5.0.d?

4lfr3d7115
Champ in-the-making
Champ in-the-making
works perfect in the community version 5.0.d, the code is in https://github.com/jpotts/share-site-creators, For Alfresco 5.0.d use the code in the 5.0.d branch.

alahwany
Champ in-the-making
Champ in-the-making
Can you please give me the linke of two files of AMP. becasue i didn't found it and i don't know how to create it from windows