cancel
Showing results for 
Search instead for 
Did you mean: 

Make options in header 'admin-only' in Alfresco 4.2d

ebogaard
Champ on-the-rise
Champ on-the-rise
In 4.2c and older, I was able to make Header (sub)items admin-only by enclosing items between <#if user.isAdmin> and </#if>.
For example the Create Site-option was editable like that in: tomcat/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/modules/header/sites.get.html.ftl

Also, to make the Repository button admin-accessible only, you could set "permission=admin" to the right option in: tomcat/webapps/share/WEB-INF/classes/alfresco/share-config.xml

In 4.2d, these don't work anymore and I can't find where I can influence this behaviour.
Setting <legacy-mode-enabled> to 'true', which should make the pre-4.2d way work again, but this made things far worse: the Header bar layout was all wrong.

Hope someone can point me in te right direction!
22 REPLIES 22

ddraper
World-Class Innovator
World-Class Innovator
The header bar has been re-written for 4.2d using a new approach that we're going to be using throughout Share going forwards. It is still possible to remove the "Repository" link from the header bar using the following configuration.


<config evaluator="string-compare" condition="RepositoryLibrary" replace="true">
   <visible>false</visible>
</config>


…it should be noted that even if the Repository link is removed, it is still accessible via a direct URL and all users (by default) do have read access to Company Home.


There is also a legacy mode configuration element for building the new header using the old configuration (although as you've pointed out the layout isn't ideal primarily because of the way in which the "Sites" drop-down menu was written using custom JavaScript).

However, the new header menu should be more flexible although perhaps not in your specific example of just wanting to make certain menu items admin only through pure configuration. You can now reconfigure the menu bar via extensions where you identify the widget for each menu item, menu group, menu drop-down or menu bar (and indeed any other widget in the header) and either update it, remove it or add to it. This should make it very easy to customise the menu bar in a way that makes it more resistant to core changes.

Hopefully you won't find making these changes to arduous although I can see in this case it is probably going to be more work than it was before (and I'm sorry that this is the case) but hopefully you'll be able to see the benefits in the approach we've taken. We're already "eating our own dog food" in this regard as we take the same approach in customizing the header menu for our cloud offering.

If you have any issues customizing the header bar then please post to the forums and I'll try to help you with the solution.

Regards,
Dave

Hi Dave,

I have the opposite issue.  I *want* the repository to be available to non-admin users.  This is because some external WS clients access the files in the  user's User Homes/${username} folder and the users want to use /share and view those files.  Am I supposed to set legacy-mode-enabled to true so that non-admin users can see the Repository link?

There's no legacy-mode-enabled or header block in share-config-custom.xml.sample so I tried a few things.  first copy share-config-custom.xml.sample to share-config-custom.xml

1. there's a config/flags block in share-config-custom.xml, so I added legacy-mode-enabled there with setting true.  after alfresco restart, non-admins have no Repository link.
2. I copied the whole share-config.xml into share-config-custom.xml 🙂 and set legacy-mode-enabled to true in the custom file.  no Repository link for non-admins after restart.
3. I edited share-config.xml and set legacy-mode-enabled true there.  after restart, non-admins DO have the Repository link.

I'd much prefer to set that in custom config though.  What am I missing?

Thanks for any pointers,

Gerald Quimpo

ddraper
World-Class Innovator
World-Class Innovator
You should just be able to set the <visible> elememt to true (see earlier comments) then it will be visible for all users (including Admin). You don't need to enable legacy mode.

Regards,
Dave

thanks, that worked.  It has the same issues as enabling legacy mode (Sites is lower than the other links, link text has spaces replaced by %20), but it works from shared/classes/alfresco/web-extension/share-config-custom.xml :-).

ddraper
World-Class Innovator
World-Class Innovator
We've seen those issues with legacy mode, and they're being fixed - but thanks for letting us know.

ebogaard
Champ on-the-rise
Champ on-the-rise
Dave, thanks for your response. That gives a little more insight.
What would really help, is something like an example or some pointers how to edit/modify one of these menu drop-downs (or are it groups?) and replace the original one with it (as I understand that's how it should be done now), using the web-extensions folder.

As I'm not really sure where to look for the new files that are used by the new header, I hope you can help with that as well.
And also: it would be rally nice to be able to hide the Repository and Create Site links for non-admins, but show it for admins. Not completely remove them. I know what URL to use, but probably not all admins in the world do 😉

Also, in "tomcat/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/modules/header/sites.get.html.ftl" I see things like <#if showCreateSite> and <#if showFindSites>. This is what I'd normally use to add an admin-only check. How/where can you configure these switches?

ddraper
World-Class Innovator
World-Class Innovator
You're right that I need to get some examples together and I'm hoping to get some blogs done soon but things are a little busy as we're working hard to close out the 4.2 Enterprise release at the moment. You should be able to piece together the information you need for some of my earlier blogs. Effectively what you need to do is build an extension module that targets the "share-header.get" WebScript and create a JavaScript controller extension (http://blogs.alfresco.com/wp/developer/2011/08/05/customizing-alfresco-share-javascript-controllers/) and use the "widgetUtils.findObject" helper function to locate the widget you want to work with and then either add/remove/modify menu items.

The share-header.get WebScript uses the "share-header.lib.js" file to build the header which you could import and use to build a completely new header if you wanted to completely replace the default "share-header.get" WebScript via the web-extensions folder.

FYI… setting the "visible" element to "false" will only hide the Repository link for non-Admins (which is what you want)… it should actually be like that by default and I've actually committed that fix this morning.

Regards,
Dave

ebogaard
Champ on-the-rise
Champ on-the-rise
Dave, thanks for the additional info.
As I read it, it should be easy to hide the Repository-button for non-admins.
To hide the 'Create Site'-button for non-admins: if I find the time to have a good look at this, I think I can fix myself some extensions/replacements for the Share header.

Regards,
Erwin

ddraper
World-Class Innovator
World-Class Innovator
You've picked the one part of the header menu that is slightly more complicated to customize! 😉

Basically you have to do the following:
1) Create an extension the "share-header.get.js" WebScript JavaScript controller
2) Create a new widget that extends "alfresco/header/AlfSitesMenu"
3) Make the new widget override the "addUsefulGroup" function so that the create site menu item doesn't get added
4) In your extension controller use widgetUtils.findObject to locate the "HEADER_SITES_MENU" widget
5) Modify the definition so that the "name" attribute is set to your custom widget
6) If you create your custom widget in your own package then you'll need to update the surf.xml to add the root location of your module so that it can be picked as an AMD resource.

The reason that this example is slightly more complicated (e.g. than say just finding a menu item and removing it) is because the sites menu does a lot of dynamic generation of menu items (e.g. the recent sites and favourite items). However, I can see that I should have included some boolean configuration so that you could toggle which menu items are shown (e.g. the create sites and site finder, etc). Then this would have been much easier. It's obviously too late for me to commit this change to the 4.2d Community release but I can have it in place for Enterprise and the next Community release.

Regards,
Dave