cancel
Showing results for 
Search instead for 
Did you mean: 

Restrict the download and copy to privilege

muthukumar
Champ on-the-rise
Champ on-the-rise
Dear Experts,

I am very new to alfresco. I installed 4.2 community version.

I created a site and i have 4 different user have different privilege like our alfresco standard.

1.Manager.
2.collaborator.
3.contributor.
4.consumer.

As per consumer privilege, he/she able to perform the 'download' and 'copy to' options. I want to restrict that privilege too. Let me how to achieve the above.

Thanks in advance

Regards,
Muthu kumar
5 REPLIES 5

yogeshpj
Star Contributor
Star Contributor
You can use evaluator to manage privileges of actions.

Dear Yougesh,

Thank you first,

As I said , I am entiry new even i dont know what is evaluator , can u guide me about evaluator?

Muthu Kumar

Hello Muthu,

Please refer these links :
<li>http://wiki.alfresco.com/wiki/Document_Library_Predefined_Evaluators#Action_Evaluators</li>
<li>http://docs.alfresco.com/4.0/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Fconcepts%2FShare-Docli...</li>

Create a class which extends BaseEvaluator as shown below -
public class IsSiteConsumerEvaluator extends BaseEvaluator{    private static Log logger = LogFactory.getLog(IsSiteConsumerEvaluator.class);    protected static final String SITE = "site";        /**     * Returns the current site id OR null if we aren't in a site     *     * @param context     * @return The current site id OR null if we aren't in a site     */    protected String getSite(RequestContext context)    {        // Look for siteId in url path & parameters        String site = context.getUriTokens().get(SITE);        if (site == null)        {            site = context.getParameter(SITE);        }        if (site == null)        {            String[] pathNames = context.getUri().substring(context.getContextPath().length()).split("/");            for (int i = 0; i < pathNames.length; i++) {                if (pathNames.equals(SITE) && (i + 1 < pathNames.length))                {                    site = pathNames;                    break;                }            }        }        return site;    }        @Override    public boolean evaluate(JSONObject arg0) {   try{      final RequestContext rc = ThreadLocalRequestContext.getRequestContext();      HttpSession session = ServletUtil.getSession();      CredentialVault cv = rc.getCredentialVault();      String currentSite = getSite(rc);            if(cv!=null){         String userName = (String) session.getAttribute(UserFactory.SESSION_ATTRIBUTE_KEY_USER_ID);         Connector connector = rc.getServiceRegistry().getConnectorService().getConnector("alfresco", userName, session);         Response res = connector.call("/api/sites/"+currentSite+"/memberships/" +rc.getUserId());         logger.debug(">> Membership Response :: " + res);         if(res.getStatus().getCode() == Status.STATUS_OK){            String response = res.getResponse();            JSONParser p = new JSONParser();            Object obj = p.parse(response);            logger.debug(">> Object obj value :: " + obj);            if(obj instanceof JSONObject){               JSONObject jsonRes = (JSONObject) obj;               String siteMemberShip = (String) jsonRes.get("role");               logger.debug(">> Object obj value :: " + siteMemberShip);               if("SiteConsumer".equals(siteMemberShip)){                  logger.debug(">> In final if returning TRUE");                  return true;               }            }         }      }   }catch(ConnectorServiceException e){      e.printStackTrace();   } catch (ParseException e) {      e.printStackTrace();   }   return false;    }}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍


Register this bean as you would do for any other class - (say in custom-slingshot-application-context.xml)
     <bean id="evaluator.doclib.action.IsSiteConsumer" class="com.sop.web.evaluator.IsSiteConsumerEvaluator" />‍‍‍


Then override the action in share-config-custom.xml as below -
   <config evaluator="string-compare" condition="DocLibActions">      <actions>          <action id="document-copy-to" type="javascript" label="actions.document.copy-to">                    <param name="function">onActionCopyTo</param>               <evaluator negate="true">evaluator.doclib.action.IsSiteConsumer</evaluator>                    <evaluator negate="true">evaluator.doclib.action.isLocked</evaluator>                    <evaluator negate="true">evaluator.doclib.indicator.IsReadOnly</evaluator>           </action>          <action id="document-download" type="link" label="actions.document.download">                    <param name="href">{downloadUrl}</param>                    <evaluator>evaluator.doclib.action.IsSiteConsumer</evaluator>         </action>      </actions>   </config>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍


Hope so that helps you!!!

It is really helpful sujay, it is a great effort but i can't understand the java as i dont know about anything because i am working in oracle domain. I understood that you have given whole script. I have a query regarding the term "Register".

what should I do with this java code (do you mean that I should compile and get the executable format?).

Muthu kumar

I have uploaded the jar here - https://github.com/sujaypillai/alfcustomevaluators/blob/master/custom-site-evaluators-0.1.jar

Just copy it to your tomcat/share/lib and restart your alfresco server.