AnsweredAssumed Answered

Off / Disable Inheritance Permission from Custom folder

Question asked by smayuri on Aug 21, 2018
Latest reply on Sep 11, 2018 by smayuri

Hi,

I am trying to create a custom folder in Create menu of Document Library called 'Confidential Folder' in Alfresco. I've attempted the following procedure,

 

1. I have used the Alfresco Maven SDK to create a project that will package up my customizations in two AMPs (Alfresco Module Packages). One AMP is for the Alfresco web application (the "repo" tier) and the other is for the Alfresco Share web application (the "Share" tier).

2.  Created a new model XML file called "finalizeModel.xml" with the following content:

<type name="fin:conffolder">
     <title>Confidential folder</title>
     <parent>cm:folder</parent>
     <properties>
          <property name="fin:folderId">
          <title>Folder Identification Number</title>
          <type>cm:content</type>
     </property>
     </properties>
</type>

3. I have added the following code in share-config-custom.xml,

<config evaluator="string-compare" condition="DocumentLibrary">
   <content id="confidentialFolder" mimetype="text/plain"
   label="Confidential Folder" itemid="fin:conffolder" icon="folder"
   index="5" type="javascript">
      <param name="function">onNewFolder</param>
      <param name="action">confFolder</param>
   </content>
</config>

 

4. In service-context.xml I registered the bean 

 

 <bean id="finalize-action-platform-jar_confFolder" class="com.finalize.action.executer.ConfidentialFolder" init-method="init">
   <property name="nodeService">
      <ref bean="NodeService" />
   </property>
   <property name="policyComponent">
      <ref bean="policyComponent" />
   </property>
</bean>

 

5. And wrote the Java class for execute the action which will Off the Inheritance Permission,

import java.util.List;
import java.util.Map;
import java.util.Collection;
import java.util.HashMap;

import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.Behaviour;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.namespace.QName;
import org.alfresco.model.ContentModel;

import com.finalize.model.FinalizeModel;

public class ConfidentialFolder implements NodeServicePolicies.OnCreateNodePolicy {

// Dependencies
private NodeService nodeService;
private PolicyComponent policyComponent;

public PermissionService permissionService;
AccessStatus writePermission;

// Behaviours
private Behaviour onCreateNode;

public void init() {
System.out.println("Initializing rateable behaviors");

// Create behaviours
this.onCreateNode = new JavaBehaviour(this, "onCreateNode",Behaviour.NotificationFrequency.EVERY_EVENT);

// Bind behaviours to node policies
this.policyComponent.bindClassBehaviour(
NodeServicePolicies.OnCreateNodePolicy.QNAME,
ContentModel.TYPE_CONTENT,
this.onCreateNode
);
}

public void onCreateNode(ChildAssociationRef childAssocRef) {
System.out.println("Inside onCreateNode");
disableInheritPermission(childAssocRef);
}


public void disableInheritPermission(ChildAssociationRef childAssocRef) {
System.out.println("Inside disableInheritPermission");
// get the parent node
NodeRef parentRef = childAssocRef.getParentRef();

System.out.println("In Execute function");

writePermission = permissionService.hasPermission(parentRef, PermissionService.CHANGE_PERMISSIONS);

System.out.println("Get write permission");

if (writePermission.equals(AccessStatus.ALLOWED))
permissionService.setInheritParentPermissions(parentRef,false);

System.out.println("Off set Inherit permission");
return;
}


public NodeService getNodeService() {
return nodeService;
}


public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
}


public PolicyComponent getPolicyComponent() {
return policyComponent;
}


public void setPolicyComponent(PolicyComponent policyComponent) {
this.policyComponent = policyComponent;
}

}

I wanted to Off or Disable  the Inheritance Permission from Confidential folder menu but I am not able to achieve.

Can you please help me? 

Thanks in advance.

Outcomes