Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cmlewis/0a395d31afda276f6f75 to your computer and use it in GitHub Desktop.
Save cmlewis/0a395d31afda276f6f75 to your computer and use it in GitHub Desktop.
Alfresco Share action to view any object in Alfresco repository in the Share node browser. Admins can click this action to automatically bring up the node in the Share node browser instead of having to copy, paste, and search the noderef in the node browser.
Alfresco Share action that creates an action in the document library and document/folder details pages called 'View in Node Browser.' Admins can click this action to automatically bring up the node in the Share node browser instead of having to copy, paste, and search the noderef in the node browser.
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<!-- ... -->
<!-- Action Evaluators -->
<bean id="com.someco.doclib.action.UserIsAdminEvaluator" class="com.someco.web.evaluator.UserIsAdminEvaluator" />
</beans>
<alfresco-config>
<!-- ... -->
<!-- Actions -->
<config evaluator="string-compare" condition="DocLibActions">
<actions>
<!-- View object in node browser -->
<action id="someco-view-in-node-browser" type="pagelink" label="View in Node Browser" icon="view-in-explorer">
<param name="page">console/admin-console/node-browser?#state=panel%3Dview%26nodeRef%3D{node.nodeRef}</param>
<evaluator>com.someco.doclib.action.UserIsAdminEvaluator</evaluator>
</action>
</actions>
<actionGroups>
<actionGroup id="document-browse">
<action index="500" id="someco-view-in-node-browser"/>
</actionGroup>
<actionGroup id="document-details">
<action index="500" id="someco-view-in-node-browser"/>
</actionGroup>
<actionGroup id="folder-browse">
<action index="500" id="someco-view-in-node-browser"/>
</actionGroup>
<actionGroup id="folder-details">
<action index="500" id="someco-view-in-node-browser"/>
</actionGroup>
</actionGroups>
</config>
<!-- ... -->
</alfresco-config>
package com.someco.web.evaluator;
import org.alfresco.web.evaluator.BaseEvaluator;
import org.apache.log4j.Logger;
import org.json.simple.JSONObject;
import org.springframework.extensions.surf.RequestContext;
import org.springframework.extensions.surf.support.ThreadLocalRequestContext;
import org.springframework.extensions.webscripts.connector.User;
/**
* Action evaluator to determine if user is an admin. Used to show/hide Share actions
* in the doclib and potentially other locations.
*
* Deploy this file in your Share amp.
*
* @author Christy Lewis
* @version 1.0
*
* <h2>Modification History</h2>
* <ul>
* <li>Jul 21, 2014 (Christy Lewis) Created.
* </ul>
*/
public class UserIsAdminEvaluator extends BaseEvaluator {
private Logger logger = Logger.getLogger(UserIsAdminEvaluator.class);
/**
* Evaluate the given node to determine if the action should be displayed.
*
* @param jsonObject The json object representation of the node
* @return A flag that specifies if the action should be shown for the node or not
*/
@Override
public boolean evaluate(JSONObject jsonObject) {
logger.debug("Evaluating if the user is an admin to determine if this action should display.");
RequestContext rc = ThreadLocalRequestContext.getRequestContext();
User user = rc.getUser();
logger.debug("User " + user.getName() + " is an admin: " + user.isAdmin());
return user.isAdmin();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment