cancel
Showing results for 
Search instead for 
Did you mean: 

Disabling 'Create Site' Button

borisstankov
Champ in-the-making
Champ in-the-making
Hello all,

Do anyone of you know, or did anyone tried to disable (hide) the "Create Site" Button for non Admin users (or show it only for specific group of ppl)?
I'm using Alfresco 5.0.c. I found some topic on 4.0, 4.2 and even older versions, but I tried them all and non of them worked as it should.

Regards!
23 REPLIES 23

vincent-kali
Star Contributor
Star Contributor
Do you mean the button on my-sites dashlet ?

vincent-kali
Star Contributor
Star Contributor
try to override files
share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/modules/header/sites.get.html.ftl
share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/modules/header/sites.get.js
its quite 'dirty' but I don't how to do that in any other way…

ex:
in ftp template:

<#if createSiteVisible>
      <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>

in js:
createSiteVisible function returns true/false if user is admin….
(i'll post an example later id needed)

Vincent


Thank you for the notes, I'll try them next week when I'm back in the office. And I'll give you a feedback.
Just a question about code in the .js file, would you please let me know where I need to add it?
I can see  :
model.showCreateSite = true;
I assume that I need to ovewrite it with something like:
  if (user == admin)
     {model.createSiteVisible = true}
  else {model.createSiteVisible = false}

Am I right?

Regards!

Hi i couldn't find the code you mentioned in the provided path, i'm unable to identify the source... i'm sending you a screenshot.. could you help me please??

Thanks for the note. Unfortunatelly I never found this topic. I'll check it next week when I'm i nthe office and I'll give you my feeback. Smiley Happy

Cheers!

vincent-kali
Star Contributor
Star Contributor

you can try to add this code in my-sites.get.js:

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;

for (i = 0; i < groups.length; i++) {
if (groups[i].itemName == "GROUP_" + group || groups[i].itemName == "GROUP_ALFRESCO_ADMINISTRATORS") {
return true; // found group
}
}
return false;
} else {
return false;
}
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Edit: the code had some errors, and there were parts not relevant to the topic, so I fixed it and removed those parts.

HI Vincent,

I just tried the code added to my-sites.get.js. However I still can see the button with all users.
I'm using LDAP - AD authentication, I didn't mentioned, because I do not think it's relevant.

Also should I delete some compiled files before I restart the service? I'm asking because not so long ago I did that when I needed to do some other customizations.

Regards,
Bobi

jpotts
World-Class Innovator
World-Class Innovator
Did you try my add-on?
https://github.com/jpotts/share-site-creators

It restricts the create-site links everywhere they exist to only the members of the Site Creators group. If it doesn't work in 5.0.c create an issue and I'll look at it.

Jeff