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

ottopodo
Champ in-the-making
Champ in-the-making
To complete the previous post in Alfresco 3.4 you have to extend the new files modules/header/sites.get.js and modules/header/sites.get.html.ftl
The code remains the same.

damiano
Champ in-the-making
Champ in-the-making
Hi!
I've tried with 3.4 the way you described, but every time I access to Share I get a popup with "Could not load module template from '/share/service/modules/header/sites'."
This come out every time I click on a page.

I've followed your steps, maybe some ideas?
Thank you very very much!

ottopodo
Champ in-the-making
Champ in-the-making
Copy the following files :
[YOUR TOMCAT FOLDER]/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/modules/header/sites.get.js
[YOUR TOMCAT FOLDER]/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/modules/header/sites.get.html.ftl
to this folder (create it if it doesn't exists) :
[YOUR TOMCAT FOLDER]/shared/classes/alfresco/web-extension/site-webscripts/org/alfresco/modules/header/

Then add the following function to sites.get.js

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 mygroup;
   }
   else return false;
}
add at the following lines to sites.get.js before
// Prepare the model for the template

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

"CAN_CREATE_SITE" is the name of the group you have to create.

Then change sites.get.html.ftl replacing:

      <ul class="create-site-menuitem">
         <li>
            <span><a href="#" onclick="${jsid}.showCreateSite(); return false;">${msg("label.create-site")}</a></span>
         </li>
      </ul>
with:

     <#if createSiteVisible>
      <ul class="create-site-menuitem">
         <li>
            <span><a href="#" onclick="${jsid}.showCreateSite(); return false;">${msg("label.create-site")}</a></span>
         </li>
      </ul>
     </#if>

It should work.
Marco

marcusmoeller
Champ in-the-making
Champ in-the-making
Hi Marco,

on my 3.4b installation, the folder:

shared/classes/alfresco/web-extension/site-webscripts/org/alfresco/modules/header/

does not exist within the tomcat root. There is only a shared/classes/alfresco/web-extension folder available. Should I place the files in there?

Greets
Marcus

michaelc
Champ on-the-rise
Champ on-the-rise
I think you want
shared\classes\alfresco\web-extension\site-webscripts\org\alfresco\components\header

sjoerdjump
Champ in-the-making
Champ in-the-making
i can confirm the following code to disable the "Create Site" from the header menu for none-admins:
Locate the following file
<TOMCAT ROOT>\webapps\share\WEB-INF\classes\alfresco\site-webscripts\org\alfresco\modules\header\sites.get.html.ftl

and edit the code as follows:


      <#if user.isAdmin>
      <ul class="create-site-menuitem">
         <li>
            <span><a href="#" onclick='Alfresco.util.ComponentManager.get("${id_js}").showCreateSite(); return false;'>${msg("label.create-site")}</a></span>
         </li>
      </ul>
   </#if>
   </div>
remove <#if user.isAdmin> and </#if> to make it again "as is"

(I just spent a some time figuring this out since i missed that this topic was 2 pages instead of 1, so i hope that it might be helpfull to someone Smiley Happy )

nirvanvjain
Champ on-the-rise
Champ on-the-rise
Hi All,

For the methods ( isAdmin and isGuest etc…) inside [size=150]ftl [/size] file , Is there any import required ?

If yes then where ?

If no then which all are implicit objects which we get in ftl files ?

Please Guide me.

Thanks!
-Nirvan

wengm
Champ in-the-making
Champ in-the-making
Here is one possible choice for reference:

Edit configuration file share-config.xml under directory /opt/alfresco-4.0.b/tomcat/webapps/share/WEB-INF/classes/alfresco/:

Add permission="admin" in item sites:
<item type="js" id="sites" permission="admin">Alfresco.module.Sites</item>

Then, only administrator can see "Sites" item on the header. Of course, I guess you can use other allowed permissions instead of "admin".

wengm
Champ in-the-making
Champ in-the-making
Official way to control site creation, please refer to http://wiki.alfresco.com/wiki/Site_Service#Controlling_who_can_create_sites

michaelc
Champ on-the-rise
Champ on-the-rise
wengm - the problem with the official way is the link is still there.
when an unauthorized user clicks the link an ugly error message shows.

this I myself found not acceptable to my users.

So wrap the link in code so that it won't show if your not allowed to do it.