public boolean canLock(Contentlet contentlet, User user, boolean respectFrontendRoles) throws DotLockException {
if(contentlet ==null || !UtilMethods.isSet(contentlet.getIdentifier())){
return true;
}
if(user ==null){
throw new DotLockException("null User cannot lock content");
}
try{
if(APILocator.getRoleAPI().doesUserHaveRole(user, APILocator.getRoleAPI().loadCMSAdminRole())){
return true;
}
else if(!APILocator.getPermissionAPI().doesUserHavePermission(contentlet, PermissionAPI.PERMISSION_EDIT, user, respectFrontendRoles)){
throw new DotLockException("User: "+ (user != null ? user.getUserId() : "Unknown")
+" does not have Edit Permissions to lock content: " + (contentlet != null ? contentlet.getIdentifier() : "Unknown"));
}
}catch(DotDataException dde){
throw new DotLockException("User: "+ (user != null ? user.getUserId() : "Unknown")
+" does not have Edit Permissions to lock content: " + (contentlet != null ? contentlet.getIdentifier() : "Unknown"));
}
String lockedBy =null;
try{
lockedBy=APILocator.getVersionableAPI().getLockedBy(contentlet);
}
catch(Exception e){
}
if(lockedBy != null && !user.getUserId().equals(lockedBy)){
throw new DotLockException(CANT_GET_LOCK_ON_CONTENT);
}
return true;
}