Skip to content

Commit

Permalink
[MNT-24195] Added fix for ags capability issue (#2648)
Browse files Browse the repository at this point in the history
* [MNT-24195] added fix for ags capability issue

* [MNT-24195] Build Issue Resolved

* [MNT-24195] Removed unused import

* [MNT-24195] Build issue changes

* [MNT-24195]  added fix for ags capability issue

* [MNT-24195] Added fix for ags capability issue

* [MNT-24195] Fix for Review Comment

* [MNT-24195] Fix for Review Comment

---------

Co-authored-by: Sathish Kumar <ST28@ford.com>
  • Loading branch information
SathishK-T and Sathish Kumar committed May 17, 2024
1 parent 8b45d19 commit 01a2587
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.util.Map;

import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
import org.alfresco.module.org_alfresco_module_rm.capability.declarative.DeclarativeCapability;
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService;
Expand Down Expand Up @@ -76,7 +75,7 @@ public void setRecordFolderService(RecordFolderService recordFolderService)
@Override
public int evaluate(NodeRef nodeRef)
{
return evaluate(nodeRef, null, null);
return evaluate(nodeRef, null, null, null);
}

/**
Expand All @@ -85,9 +84,10 @@ public int evaluate(NodeRef nodeRef)
* @param destination destination node reference
* @param linkee linkee node reference, can be null
* @param assocType association type, can be null
* @param recordType record type, can be null
* @return
*/
public int evaluate(NodeRef destination, NodeRef linkee, QName assocType)
public int evaluate(NodeRef destination, NodeRef linkee, QName assocType, QName recordType)
{
if (linkee != null)
{
Expand All @@ -105,7 +105,7 @@ public int evaluate(NodeRef destination, NodeRef linkee, QName assocType)
{
if (recordService.isRecord(destination) &&
!recordService.isDeclared(destination) &&
permissionService.hasPermission(destination, RMPermissionModel.FILE_RECORDS) == AccessStatus.ALLOWED)
permissionService.hasPermission(destination, FILE_RECORDS) == AccessStatus.ALLOWED)
{
return AccessDecisionVoter.ACCESS_GRANTED;
}
Expand All @@ -115,7 +115,7 @@ public int evaluate(NodeRef destination, NodeRef linkee, QName assocType)
if (recordService.isRecord(linkee) &&
recordService.isRecord(destination) &&
!recordService.isDeclared(destination) &&
permissionService.hasPermission(destination, RMPermissionModel.FILE_RECORDS) == AccessStatus.ALLOWED)
permissionService.hasPermission(destination, FILE_RECORDS) == AccessStatus.ALLOWED)
{
return AccessDecisionVoter.ACCESS_GRANTED;
}
Expand All @@ -132,22 +132,23 @@ public int evaluate(NodeRef destination, NodeRef linkee, QName assocType)

// if the destination folder is not a record folder and the user has filling capability on it, grant access to create the record
if (checkConditions(destination, conditions) &&
!recordFolderService.isRecordFolder(destination) )
!recordFolderService.isRecordFolder(destination) &&
permissionService.hasPermission(destination, CREATE_MODIFY_DESTROY_FILEPLAN_METADATA) == AccessStatus.ALLOWED)
{
return AccessDecisionVoter.ACCESS_GRANTED;
}

if (checkConditions(destination, conditions) &&
recordFolderService.isRecordFolder(destination) &&
permissionService.hasPermission(destination, RMPermissionModel.FILE_RECORDS) == AccessStatus.ALLOWED)
permissionService.hasPermission(destination, FILE_RECORDS) == AccessStatus.ALLOWED)
{
return AccessDecisionVoter.ACCESS_GRANTED;
}

conditions.put("capabilityCondition.closed", Boolean.TRUE);
if (checkConditions(destination, conditions) &&
recordFolderService.isRecordFolder(destination) &&
permissionService.hasPermission(getFilePlanService().getFilePlan(destination), RMPermissionModel.DECLARE_RECORDS_IN_CLOSED_FOLDERS) == AccessStatus.ALLOWED)
permissionService.hasPermission(getFilePlanService().getFilePlan(destination), DECLARE_RECORDS_IN_CLOSED_FOLDERS) == AccessStatus.ALLOWED)
{
return AccessDecisionVoter.ACCESS_GRANTED;
}
Expand All @@ -156,32 +157,32 @@ public int evaluate(NodeRef destination, NodeRef linkee, QName assocType)
conditions.put("capabilityCondition.cutoff", Boolean.TRUE);
if (checkConditions(destination, conditions) &&
recordFolderService.isRecordFolder(destination) &&
permissionService.hasPermission(getFilePlanService().getFilePlan(destination), RMPermissionModel.CREATE_MODIFY_RECORDS_IN_CUTOFF_FOLDERS) == AccessStatus.ALLOWED)
permissionService.hasPermission(getFilePlanService().getFilePlan(destination), CREATE_MODIFY_RECORDS_IN_CUTOFF_FOLDERS) == AccessStatus.ALLOWED)
{
return AccessDecisionVoter.ACCESS_GRANTED;
}
}
if (capabilityService.getCapability(RMPermissionModel.CREATE_MODIFY_DESTROY_FOLDERS).evaluate(destination) == AccessDecisionVoter.ACCESS_GRANTED)
if (null != recordType && recordType.equals(TYPE_RECORD_FOLDER) && capabilityService.getCapability(CREATE_MODIFY_DESTROY_FOLDERS).evaluate(destination) == AccessDecisionVoter.ACCESS_GRANTED)
{
return AccessDecisionVoter.ACCESS_GRANTED;
}
if (capabilityService.getCapability(RMPermissionModel.DECLARE_RECORDS_IN_CLOSED_FOLDERS).evaluate(destination) == AccessDecisionVoter.ACCESS_GRANTED)
if (capabilityService.getCapability(DECLARE_RECORDS_IN_CLOSED_FOLDERS).evaluate(destination) == AccessDecisionVoter.ACCESS_GRANTED)
{
return AccessDecisionVoter.ACCESS_GRANTED;
}
if (capabilityService.getCapability(RMPermissionModel.CREATE_MODIFY_RECORDS_IN_CUTOFF_FOLDERS).evaluate(destination) == AccessDecisionVoter.ACCESS_GRANTED)
if (capabilityService.getCapability(CREATE_MODIFY_RECORDS_IN_CUTOFF_FOLDERS).evaluate(destination) == AccessDecisionVoter.ACCESS_GRANTED)
{
return AccessDecisionVoter.ACCESS_GRANTED;
}
if (capabilityService.getCapability(RMPermissionModel.CREATE_MODIFY_DESTROY_FILEPLAN_METADATA).evaluate(destination) == AccessDecisionVoter.ACCESS_GRANTED)
if (capabilityService.getCapability(CREATE_MODIFY_DESTROY_FILEPLAN_METADATA).evaluate(destination) == AccessDecisionVoter.ACCESS_GRANTED)
{
return AccessDecisionVoter.ACCESS_GRANTED;
}
if (capabilityService.getCapability(RMPermissionModel.CREATE_HOLD).evaluate(destination) == AccessDecisionVoter.ACCESS_GRANTED)
if (capabilityService.getCapability(CREATE_HOLD).evaluate(destination) == AccessDecisionVoter.ACCESS_GRANTED)
{
return AccessDecisionVoter.ACCESS_GRANTED;
}
if (((ChangeOrDeleteReferencesCapability)capabilityService.getCapability(RMPermissionModel.CHANGE_OR_DELETE_REFERENCES)).evaluate(destination, linkee) == AccessDecisionVoter.ACCESS_GRANTED)
if (((ChangeOrDeleteReferencesCapability)capabilityService.getCapability(CHANGE_OR_DELETE_REFERENCES)).evaluate(destination, linkee) == AccessDecisionVoter.ACCESS_GRANTED)
{
return AccessDecisionVoter.ACCESS_GRANTED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
package org.alfresco.module.org_alfresco_module_rm.capability.policy;

import org.alfresco.module.org_alfresco_module_rm.capability.impl.CreateCapability;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.aopalliance.intercept.MethodInvocation;
Expand All @@ -42,10 +43,18 @@ public int evaluate(
{
NodeRef linkee = null;
QName assocType = null;
QName recordType = null;

// get the destination node
NodeRef destination = getTestNode(invocation, params, cad.getParameters().get(0), cad.isParent());

//get the recordType
for (Object qname : invocation.getArguments()) {
if (qname != null && (qname.equals(RecordsManagementModel.TYPE_RECORD_FOLDER) || qname.equals(RecordsManagementModel.TYPE_RECORD_CATEGORY))) {
recordType = (QName) qname;
}
}

if (cad.getParameters().size() > 1)
{
// get the linkee when present
Expand All @@ -58,7 +67,7 @@ public int evaluate(
}
}

return ((CreateCapability) getCapabilityService().getCapability("Create")).evaluate(destination, linkee, assocType);
return ((CreateCapability) getCapabilityService().getCapability("Create")).evaluate(destination, linkee, assocType, recordType);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public void given()
Set<Capability> capabilities = new HashSet<>(2);
capabilities.add(capabilityService.getCapability("ViewRecords"));
capabilities.add(capabilityService.getCapability("CreateRecords"));
capabilities.add(capabilityService.getCapability("CreateModifyDestroyFileplanMetadata"));
filePlanRoleService.createRole(filePlan, roleName, roleName, capabilities);


Expand All @@ -189,6 +190,7 @@ public void given()

//give read and file permission to user on unfiled records container
filePlanPermissionService.setPermission(unfiledContainer , user, RMPermissionModel.FILING);
filePlanPermissionService.setPermission(unfiledContainer , user, RMPermissionModel.CREATE_MODIFY_DESTROY_FILEPLAN_METADATA);
}

public void when()
Expand Down

0 comments on commit 01a2587

Please sign in to comment.