mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
REPO-1654, REPO-1655: Update one permission field returns 500
- Changed status code and message in case one of the required permission fields is missing. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@133336 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -2244,10 +2244,19 @@ public class NodesImpl implements Nodes
|
|||||||
accessStatus = AccessStatus.valueOf(nodePerm.getAccessStatus());
|
accessStatus = AccessStatus.valueOf(nodePerm.getAccessStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((authorityId == null) ||
|
if (authorityId == null || authorityId.isEmpty())
|
||||||
((! authorityId.equals(PermissionService.ALL_AUTHORITIES) && (! authorityService.authorityExists(authorityId)))))
|
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException("Cannot set permissions on this node - unknown authority: "+authorityId);
|
throw new InvalidArgumentException("Authority Id is expected.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (permName == null || permName.isEmpty())
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException("Permission name is expected.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (((!authorityId.equals(PermissionService.ALL_AUTHORITIES) && (!authorityService.authorityExists(authorityId)))))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException("Cannot set permissions on this node - unknown authority: " + authorityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
AccessPermission existing = null;
|
AccessPermission existing = null;
|
||||||
|
@@ -154,16 +154,17 @@ public class NodePermissions
|
|||||||
|
|
||||||
NodePermission that = (NodePermission) o;
|
NodePermission that = (NodePermission) o;
|
||||||
|
|
||||||
if (!authorityId.equals(that.authorityId))
|
if (authorityId != null ? !authorityId.equals(that.authorityId) : that.authorityId != null)
|
||||||
return false;
|
return false;
|
||||||
return name.equals(that.name);
|
return name != null ? name.equals(that.name) : that.name == null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
int result = authorityId.hashCode();
|
int result = authorityId != null ? authorityId.hashCode() : 0;
|
||||||
result = 31 * result + name.hashCode();
|
result = 31 * result + (name != null ? name.hashCode() : 0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4192,6 +4192,9 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
|||||||
testUpdatePermissionInvalidAccessStatus();
|
testUpdatePermissionInvalidAccessStatus();
|
||||||
testUpdatePermissionAddDuplicate();
|
testUpdatePermissionAddDuplicate();
|
||||||
|
|
||||||
|
// required permission properties missing
|
||||||
|
testUpdatePermissionMissingFields();
|
||||||
|
|
||||||
// 'Permission Denied' tests
|
// 'Permission Denied' tests
|
||||||
testUpdatePermissionsPermissionDeniedUser();
|
testUpdatePermissionsPermissionDeniedUser();
|
||||||
testUpdatePermissionsOnSpecialNodes();
|
testUpdatePermissionsOnSpecialNodes();
|
||||||
@@ -4375,6 +4378,42 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
|||||||
put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 400);
|
put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests updating permissions on a node without providing mandatory
|
||||||
|
* properties
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private void testUpdatePermissionMissingFields() throws Exception
|
||||||
|
{
|
||||||
|
// create folder with an empty document
|
||||||
|
String postUrl = createFolder();
|
||||||
|
String dId = createDocument(postUrl);
|
||||||
|
|
||||||
|
// update permissions
|
||||||
|
Document dUpdate = new Document();
|
||||||
|
// Add same permission with different access status
|
||||||
|
NodePermissions nodePermissions = new NodePermissions();
|
||||||
|
List<NodePermissions.NodePermission> locallySetPermissions = new ArrayList<>();
|
||||||
|
locallySetPermissions.add(new NodePermissions.NodePermission(null, PermissionService.CONSUMER, AccessStatus.ALLOWED.toString()));
|
||||||
|
nodePermissions.setLocallySet(locallySetPermissions);
|
||||||
|
dUpdate.setPermissions(nodePermissions);
|
||||||
|
|
||||||
|
// "Authority Id is expected."
|
||||||
|
put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 400);
|
||||||
|
locallySetPermissions.clear();
|
||||||
|
locallySetPermissions.add(new NodePermissions.NodePermission("", PermissionService.CONSUMER, AccessStatus.ALLOWED.toString()));
|
||||||
|
put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 400);
|
||||||
|
|
||||||
|
locallySetPermissions.clear();
|
||||||
|
locallySetPermissions.add(new NodePermissions.NodePermission(groupA, null, AccessStatus.ALLOWED.toString()));
|
||||||
|
// "Permission name is expected."
|
||||||
|
put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 400);
|
||||||
|
locallySetPermissions.clear();
|
||||||
|
locallySetPermissions.add(new NodePermissions.NodePermission(groupA, "", AccessStatus.ALLOWED.toString()));
|
||||||
|
put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 400);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests updating permissions on a node that user doesn't have permission for
|
* Tests updating permissions on a node that user doesn't have permission for
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user