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.
You need to obtain a reference to the PermissionService and use its API to call setInheritsPermission(nodeRefOfFolder, false);
Also, your action will only work when run by someone who has the ability to manage permissions on that node. If you need it to be successful for people with lesser permissions, you'll have to wrap it in a retrying transaction helper, then execute it with AuthenticationUtil.runAs.
Hi,
I have updated my code according to the answers which you both are given. But I am still not able to disable the Inheritance Permission.
For disable the permission I wanted to call "ConfidentialFolder.java" but currently it is not getting called.
What should I do for calling the java class?
Have I missed anything in "share-config-custom.xml"?
ConfidentialFolder.java is a behavior that runs on the repository tier. It has nothing to do with the Share tier, so the problem is not in share-config-custom.xml. More likely, the problem is that you have not wired your behavior in to Spring in a context file (or have done so incorrectly).
You haven't provided your context file so I cannot tell what the problem is.
You might want to take a look at this tutorial on behaviors for a spring context config example.
You can check my service-context.xml file,
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for additional
information regarding copyright ownership. The ASF licenses this file to
You under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License. -->
<beans>
<!-- A simple class that is initialized by Spring -->
<bean id="com.finalize.Demo"
class="com.finalize.platformsample.Demo" init-method="init" />
<!-- A simple module component that will be executed once. Note. this module
component will only be executed once, and then there will be an entry for
it in the Repo DB. So doing for example $ mvn clean install alfresco:run
twice will only execute this component the first time. You need to remove
/alf_data_dev for it to be executed again. -->
<bean id="com.finalize.DemoComponent"
class="com.finalize.platformsample.DemoComponent"
parent="module.baseComponent">
<property name="moduleId"
value="finalize-content-platform-jar" /> <!-- See module.properties -->
<property name="name" value="DemoComponent" />
<property name="description"
value="A demonstration component" />
<property name="sinceVersion" value="1.0" />
<property name="appliesFromVersion" value="0.99" /> <!-- 1.0 would not work here when using SNAPSHOT version in project -->
<property name="nodeService" ref="NodeService" />
<property name="nodeLocatorService" ref="nodeLocatorService" />
</bean>
<bean id="doc-finalize"
class="com.finalize.action.executer.DocumentFinalizeActionExecuter"
parent="action-executer">
<property name="nodeService">
<ref bean="NodeService" />
</property>
</bean>
<bean id="enable-finalize-flag"
class="com.finalize.action.executer.EnableFinalize"
parent="doc-finalize">
<property name="publicAction">
<value>false</value>
</property>
</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>
</beans>
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.