RM-1827 ("Declare" actions become available for user only after re-login)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@98379 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2015-03-02 21:58:14 +00:00
parent 737926abd6
commit 4ac32d51a6
2 changed files with 104 additions and 23 deletions

View File

@@ -17,6 +17,7 @@
<property name="capabilityService" ref="CapabilityService"/> <property name="capabilityService" ref="CapabilityService"/>
<property name="dictionaryService" ref="DictionaryService" /> <property name="dictionaryService" ref="DictionaryService" />
<property name="siteService" ref="SiteService" /> <property name="siteService" ref="SiteService" />
<property name="authorityService" ref="AuthorityService" />
<property name="policyComponent" ref="policyComponent" /> <property name="policyComponent" ref="policyComponent" />
<property name="jsonConversionComponentCache" ref="jsonConversionComponentCache" /> <property name="jsonConversionComponentCache" ref="jsonConversionComponentCache" />
</bean> </bean>

View File

@@ -18,10 +18,13 @@
*/ */
package org.alfresco.module.org_alfresco_module_rm.jscript.app; package org.alfresco.module.org_alfresco_module_rm.jscript.app;
import static org.alfresco.model.ContentModel.PROP_USERNAME;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService; import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
@@ -41,6 +44,8 @@ import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.cmr.site.SiteInfo; import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteService; import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
@@ -57,14 +62,15 @@ import org.json.simple.JSONObject;
*/ */
public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JSONConversionComponent public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JSONConversionComponent
implements NodeServicePolicies.OnDeleteNodePolicy, implements NodeServicePolicies.OnDeleteNodePolicy,
NodeServicePolicies.OnCreateNodePolicy NodeServicePolicies.OnCreateNodePolicy,
NodeServicePolicies.OnCreateChildAssociationPolicy,
NodeServicePolicies.OnDeleteChildAssociationPolicy
{ {
/** JSON values */ /** JSON values */
private static final String IS_RM_NODE = "isRmNode"; private static final String IS_RM_NODE = "isRmNode";
private static final String RM_NODE = "rmNode"; private static final String RM_NODE = "rmNode";
private static final String IS_RM_SITE_CREATED = "isRmSiteCreated"; private static final String IS_RM_SITE_CREATED = "isRmSiteCreated";
private static final String IS_RECORD_CONTRIBUTOR_GROUP_ENABLED = "isRecordContributorGroupEnabled"; private static final String IS_RECORD_CONTRIBUTOR_GROUP_ENABLED = "isRecordContributorGroupEnabled";
private static final String RECORD_CONTRIBUTOR_GROUP_NAME = "recordContributorGroupName";
/** true if record contributor group is enabled, false otherwise */ /** true if record contributor group is enabled, false otherwise */
private boolean isRecordContributorsGroupEnabled = false; private boolean isRecordContributorsGroupEnabled = false;
@@ -87,6 +93,9 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JS
/** site service */ /** site service */
private SiteService siteService; private SiteService siteService;
/** Authority service */
private AuthorityService authorityService;
/** Indicators */ /** Indicators */
private List<BaseEvaluator> indicators = new ArrayList<BaseEvaluator>(); private List<BaseEvaluator> indicators = new ArrayList<BaseEvaluator>();
@@ -97,10 +106,12 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JS
private PolicyComponent policyComponent; private PolicyComponent policyComponent;
/** JSON conversion component cache */ /** JSON conversion component cache */
private SimpleCache<String, Boolean> jsonConversionComponentCache; private SimpleCache<String, Object> jsonConversionComponentCache;
/** Constant for checking the cache */ /** Constants for checking the cache */
private static final String RM_SITE_EXISTS = "rmSiteExists"; private static final String RM_SITE_EXISTS = "rmSiteExists";
private static final String RM_RECORD_CONTRIBUTORS_GROUP_MEMBERS = "rmRecordContributorsGroupMembers";
private static final String RM_SHOW_ACTIONS = "rmShowActions";
/** /**
* @param enabled true if enabled, false otherwise * @param enabled true if enabled, false otherwise
@@ -158,6 +169,14 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JS
this.siteService = siteService; this.siteService = siteService;
} }
/**
* @param authorityService authority service
*/
public void setAuthorityService(AuthorityService authorityService)
{
this.authorityService = authorityService;
}
/** /**
* @param indicator registered indicator * @param indicator registered indicator
*/ */
@@ -187,7 +206,7 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JS
* *
* @return The json conversion component cache * @return The json conversion component cache
*/ */
protected SimpleCache<String, Boolean> getJsonConversionComponentCache() protected SimpleCache<String, Object> getJsonConversionComponentCache()
{ {
return this.jsonConversionComponentCache; return this.jsonConversionComponentCache;
} }
@@ -197,7 +216,7 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JS
* *
* @param jsonConversionComponentCache The json conversion component cache * @param jsonConversionComponentCache The json conversion component cache
*/ */
public void setJsonConversionComponentCache(SimpleCache<String, Boolean> jsonConversionComponentCache) public void setJsonConversionComponentCache(SimpleCache<String, Object> jsonConversionComponentCache)
{ {
this.jsonConversionComponentCache = jsonConversionComponentCache; this.jsonConversionComponentCache = jsonConversionComponentCache;
} }
@@ -216,6 +235,16 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JS
QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"), QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"),
RecordsManagementModel.TYPE_RM_SITE, RecordsManagementModel.TYPE_RM_SITE,
new JavaBehaviour(this, "onCreateNode")); new JavaBehaviour(this, "onCreateNode"));
policyComponent.bindAssociationBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateChildAssociation"),
ContentModel.TYPE_AUTHORITY,
new JavaBehaviour(this, "onCreateChildAssociation"));
policyComponent.bindAssociationBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "onDeleteChildAssociation"),
ContentModel.TYPE_AUTHORITY,
new JavaBehaviour(this, "onDeleteChildAssociation"));
} }
/** /**
@@ -236,7 +265,10 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JS
// get the record contributor information // get the record contributor information
rootJSONObject.put(IS_RECORD_CONTRIBUTOR_GROUP_ENABLED, isRecordContributorsGroupEnabled); rootJSONObject.put(IS_RECORD_CONTRIBUTOR_GROUP_ENABLED, isRecordContributorsGroupEnabled);
rootJSONObject.put(RECORD_CONTRIBUTOR_GROUP_NAME, recordContributorsGroupName); if (isRecordContributorsGroupEnabled)
{
rootJSONObject.put(RM_SHOW_ACTIONS, showRmActions());
}
// Get the node reference for convenience // Get the node reference for convenience
NodeRef nodeRef = nodeInfo.getNodeRef(); NodeRef nodeRef = nodeInfo.getNodeRef();
@@ -258,6 +290,20 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JS
} }
} }
private boolean showRmActions()
{
if (!getJsonConversionComponentCache().contains(RM_RECORD_CONTRIBUTORS_GROUP_MEMBERS))
{
Set<String> groupMembers = authorityService.getContainedAuthorities(AuthorityType.USER, AuthorityType.GROUP.getPrefixString() + recordContributorsGroupName, false);
getJsonConversionComponentCache().put(RM_RECORD_CONTRIBUTORS_GROUP_MEMBERS, groupMembers);
}
@SuppressWarnings("unchecked")
Set<String> recordContributorsMembers = (Set<String>) getJsonConversionComponentCache().get(RM_RECORD_CONTRIBUTORS_GROUP_MEMBERS);
return recordContributorsMembers.contains(AuthenticationUtil.getFullyAuthenticatedUser());
}
/** /**
* Checks for the existance of the RM site * Checks for the existance of the RM site
* *
@@ -576,4 +622,38 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JS
{ {
getJsonConversionComponentCache().put(RM_SITE_EXISTS, true); getJsonConversionComponentCache().put(RM_SITE_EXISTS, true);
} }
/**
* @see org.alfresco.repo.node.NodeServicePolicies.OnCreateChildAssociationPolicy#onCreateChildAssociation(org.alfresco.service.cmr.repository.ChildAssociationRef, boolean)
*/
@Override
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNewNode)
{
if (isRecordContributorsGroupEnabled)
{
if (!getJsonConversionComponentCache().contains(RM_RECORD_CONTRIBUTORS_GROUP_MEMBERS))
{
Set<String> groupMembers = authorityService.getContainedAuthorities(AuthorityType.USER, AuthorityType.GROUP.getPrefixString() + recordContributorsGroupName, false);
getJsonConversionComponentCache().put(RM_RECORD_CONTRIBUTORS_GROUP_MEMBERS, groupMembers);
}
@SuppressWarnings("unchecked")
Set<String> recordContributorsMembers = (Set<String>) getJsonConversionComponentCache().get(RM_RECORD_CONTRIBUTORS_GROUP_MEMBERS);
recordContributorsMembers.add((String) nodeService.getProperty(childAssocRef.getChildRef(), PROP_USERNAME));
}
}
/**
* @see org.alfresco.repo.node.NodeServicePolicies.OnDeleteChildAssociationPolicy#onDeleteChildAssociation(org.alfresco.service.cmr.repository.ChildAssociationRef)
*/
@Override
public void onDeleteChildAssociation(ChildAssociationRef childAssocRef)
{
if (isRecordContributorsGroupEnabled && getJsonConversionComponentCache().contains(RM_RECORD_CONTRIBUTORS_GROUP_MEMBERS))
{
@SuppressWarnings("unchecked")
Set<String> groupMembers = (Set<String>) getJsonConversionComponentCache().get(RM_RECORD_CONTRIBUTORS_GROUP_MEMBERS);
groupMembers.remove((String) nodeService.getProperty(childAssocRef.getChildRef(), PROP_USERNAME));
}
}
} }