mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)
126661 jvonka: RA-1045: As requested for SFS, allow rendition details (available/created renditions only) for shared link to be listed via no auth. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@126689 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -137,6 +137,7 @@ public class PublicApiDeclarativeRegistry extends DeclarativeRegistry
|
||||
Class resAction = null;
|
||||
|
||||
String entityId = templateVars.get(ResourceLocator.ENTITY_ID);
|
||||
String relationshipId = templateVars.get(ResourceLocator.RELATIONSHIP_ID);
|
||||
|
||||
switch (rwm.getMetaData().getType())
|
||||
{
|
||||
@@ -169,6 +170,22 @@ public class PublicApiDeclarativeRegistry extends DeclarativeRegistry
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RELATIONSHIP:
|
||||
if (StringUtils.isNotBlank(relationshipId))
|
||||
{
|
||||
if (RelationshipResourceAction.ReadById.class.isAssignableFrom(rwm.getResource().getClass()))
|
||||
{
|
||||
resAction = RelationshipResourceAction.ReadById.class;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (RelationshipResourceAction.Read.class.isAssignableFrom(rwm.getResource().getClass()))
|
||||
{
|
||||
resAction = RelationshipResourceAction.Read.class;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ package org.alfresco.rest.api;
|
||||
|
||||
import org.alfresco.rest.api.model.QuickShareLink;
|
||||
import org.alfresco.rest.api.model.QuickShareLinkEmailRequest;
|
||||
import org.alfresco.rest.api.model.Rendition;
|
||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||
import org.alfresco.rest.framework.resource.content.BinaryResource;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
@@ -57,6 +58,16 @@ public interface QuickShareLinks
|
||||
*/
|
||||
BinaryResource readProperty(String sharedId, String renditionId, Parameters parameters) throws EntityNotFoundException;
|
||||
|
||||
/**
|
||||
* List renditions info - note: only returns available (=> created) renditions.
|
||||
*
|
||||
* Note: does *not* require authenticated access for (public) shared link.
|
||||
*
|
||||
* @param sharedId
|
||||
* @return
|
||||
*/
|
||||
CollectionWithPagingInfo<Rendition> getRenditions(String sharedId);
|
||||
|
||||
/**
|
||||
* Delete the shared link.
|
||||
*
|
||||
|
@@ -69,4 +69,6 @@ public interface Renditions
|
||||
* @return the rendition stream
|
||||
*/
|
||||
BinaryResource getContent(String nodeId, String renditionId, Parameters parameters);
|
||||
|
||||
String PARAM_STATUS = "status";
|
||||
}
|
||||
|
@@ -37,18 +37,24 @@ import org.alfresco.rest.api.model.ContentInfo;
|
||||
import org.alfresco.rest.api.model.Node;
|
||||
import org.alfresco.rest.api.model.QuickShareLink;
|
||||
import org.alfresco.rest.api.model.QuickShareLinkEmailRequest;
|
||||
import org.alfresco.rest.api.model.Rendition;
|
||||
import org.alfresco.rest.api.model.UserInfo;
|
||||
import org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException;
|
||||
import org.alfresco.rest.framework.core.exceptions.DisabledServiceException;
|
||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
|
||||
import org.alfresco.rest.framework.jacksonextensions.BeanPropertiesFilter;
|
||||
import org.alfresco.rest.framework.resource.content.BasicContentInfo;
|
||||
import org.alfresco.rest.framework.resource.content.BinaryResource;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
import org.alfresco.rest.framework.resource.parameters.Params;
|
||||
import org.alfresco.rest.framework.resource.parameters.SortColumn;
|
||||
import org.alfresco.rest.framework.resource.parameters.where.Query;
|
||||
import org.alfresco.rest.framework.resource.parameters.where.QueryHelper;
|
||||
import org.alfresco.rest.framework.webscripts.ResourceWebScriptHelper;
|
||||
import org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
@@ -78,8 +84,10 @@ import org.alfresco.util.SearchLanguageConversion;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
@@ -389,6 +397,48 @@ public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionWithPagingInfo<Rendition> getRenditions(String sharedId)
|
||||
{
|
||||
checkEnabled();
|
||||
checkValidShareId(sharedId);
|
||||
|
||||
try
|
||||
{
|
||||
Pair<String, NodeRef> pair = quickShareService.getTenantNodeRefFromSharedId(sharedId);
|
||||
|
||||
String networkTenantDomain = pair.getFirst();
|
||||
final NodeRef nodeRef = pair.getSecond();
|
||||
|
||||
return TenantUtil.runAsSystemTenant(new TenantUtil.TenantRunAsWork<CollectionWithPagingInfo<Rendition>>()
|
||||
{
|
||||
public CollectionWithPagingInfo<Rendition> doWork() throws Exception
|
||||
{
|
||||
String nodeId = nodeRef.getId();
|
||||
|
||||
// hmm ... can we simplify ?
|
||||
String filterStatusCreated = "("+Renditions.PARAM_STATUS+"='"+Rendition.RenditionStatus.CREATED+"')";
|
||||
Query whereQuery = ResourceWebScriptHelper.getWhereClause(filterStatusCreated);
|
||||
Params.RecognizedParams recParams = new Params.RecognizedParams(null, null, null, null, null, null, whereQuery, null, false);
|
||||
Parameters params = Params.valueOf(recParams, null, null, null);
|
||||
|
||||
return renditions.getRenditions(nodeId, params);
|
||||
|
||||
}
|
||||
}, networkTenantDomain);
|
||||
}
|
||||
catch (InvalidSharedIdException ex)
|
||||
{
|
||||
logger.warn("Unable to find: " + sharedId);
|
||||
throw new EntityNotFoundException(sharedId);
|
||||
}
|
||||
catch (InvalidNodeRefException inre)
|
||||
{
|
||||
logger.warn("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
|
||||
throw new EntityNotFoundException(sharedId);
|
||||
}
|
||||
}
|
||||
|
||||
// Helper find (search) method
|
||||
|
||||
private final static Set<String> FIND_SHARED_LINKS_QUERY_PROPERTIES =
|
||||
|
@@ -84,7 +84,6 @@ public class RenditionsImpl implements Renditions, ResourceLoaderAware
|
||||
{
|
||||
private static final Log LOGGER = LogFactory.getLog(RenditionsImpl.class);
|
||||
|
||||
private static final String PARAM_STATUS = "status";
|
||||
private static final Set<String> RENDITION_STATUS_COLLECTION_EQUALS_QUERY_PROPERTIES = Collections.singleton(PARAM_STATUS);
|
||||
|
||||
private Nodes nodes;
|
||||
|
@@ -20,13 +20,16 @@ package org.alfresco.rest.api.quicksharelinks;
|
||||
|
||||
import org.alfresco.rest.api.QuickShareLinks;
|
||||
import org.alfresco.rest.api.Renditions;
|
||||
import org.alfresco.rest.api.model.Rendition;
|
||||
import org.alfresco.rest.api.nodes.NodesEntityResource;
|
||||
import org.alfresco.rest.framework.BinaryProperties;
|
||||
import org.alfresco.rest.framework.WebApiDescription;
|
||||
import org.alfresco.rest.framework.WebApiNoAuth;
|
||||
import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceBinaryAction;
|
||||
import org.alfresco.rest.framework.resource.content.BinaryResource;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@@ -38,6 +41,7 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
*/
|
||||
@RelationshipResource(name = "renditions", entityResource = QuickShareLinkEntityResource.class, title = "Node renditions via shared link")
|
||||
public class QuickShareLinkRenditionsRelation implements
|
||||
RelationshipResourceAction.Read<Rendition>,
|
||||
RelationshipResourceBinaryAction.Read,
|
||||
InitializingBean
|
||||
{
|
||||
@@ -62,4 +66,12 @@ public class QuickShareLinkRenditionsRelation implements
|
||||
{
|
||||
return quickShareLinks.readProperty(sharedId, renditionId, parameters);
|
||||
}
|
||||
|
||||
@WebApiDescription(title = "List renditions", description = "List available (created) renditions")
|
||||
@WebApiNoAuth
|
||||
@Override
|
||||
public CollectionWithPagingInfo<Rendition> readAll(String sharedId, Parameters parameters)
|
||||
{
|
||||
return quickShareLinks.getRenditions(sharedId);
|
||||
}
|
||||
}
|
||||
|
@@ -123,12 +123,15 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
|
||||
* <p>POST:</p>
|
||||
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/shared-links}
|
||||
*
|
||||
* <p>GET:</p>
|
||||
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/shared-links/<sharedId>}
|
||||
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/shared-links/<sharedId>/content}
|
||||
*
|
||||
* <p>DELETE:</p>
|
||||
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/shared-links/<sharedId>}
|
||||
*
|
||||
* <p>GET:</p>
|
||||
* The following do not require authentication
|
||||
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/shared-links/<sharedId>}
|
||||
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/shared-links/<sharedId>/content}
|
||||
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/shared-links/<sharedId>/renditions}
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testSharedLinkCreateGetDelete() throws Exception
|
||||
@@ -320,12 +323,23 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
|
||||
getSingle(QuickShareLinkEntityResource.class, null, shared1Id + "/renditions/dummy/content", null, 404);
|
||||
}
|
||||
|
||||
// unauth access to get shared link renditions info (available => CREATED renditions only)
|
||||
response = getAll(URL_SHARED_LINKS + "/" + shared1Id + "/renditions", null, null, 200);
|
||||
List<Rendition> renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class);
|
||||
assertEquals(0, renditions.size());
|
||||
|
||||
// create rendition of pdf doc - note: for some reason create rendition of txt doc fail on build m/c (TBC) ?
|
||||
Rendition rendition = createAndGetRendition(user2, d1Id, "doclib");
|
||||
assertNotNull(rendition);
|
||||
assertEquals(Rendition.RenditionStatus.CREATED, rendition.getStatus());
|
||||
|
||||
// unauth access to get shared link renditions info (available => CREATED renditions only)
|
||||
response = getAll(URL_SHARED_LINKS + "/" + shared1Id + "/renditions", null, null, 200);
|
||||
renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class);
|
||||
assertEquals(1, renditions.size());
|
||||
assertEquals(Rendition.RenditionStatus.CREATED, renditions.get(0).getStatus());
|
||||
assertEquals("doclib", renditions.get(0).getId());
|
||||
|
||||
// unauth access to get shared link file rendition content
|
||||
response = getSingle(QuickShareLinkEntityResource.class, null, shared1Id + "/renditions/doclib/content", null, 200);
|
||||
assertTrue(response.getResponseAsBytes().length > 0);
|
||||
|
Reference in New Issue
Block a user