Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

public to private site permission simple fix #13

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ release.properties
*.iws
alf_data_dev
*.log
*.log*
*.log*
**/.settings
**/.project
**/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
<#if shareUrlPath??>
"shareUrlPath" : "${shareUrl + shareUrlPath}",
</#if>


<#if thumbnailBase64??>
"thumbnailBase64" : "${thumbnailBase64}",
</#if>
<#if imgPreviewUrlPath??>
"imgPreviewUrlPath" : "${previewUrlPrefix + imgPreviewUrlPath}",
</#if>

<#assign propNames = properties?keys>
"aspects" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
n.id as id,
n.uuid as uuid,
n.version as version,
n.type_qname_id as type_qname_id,
n.store_id as store_id,
#{storeProtocol} as protocol,
#{storeIdentifier} as identifier,
Expand Down Expand Up @@ -98,6 +99,7 @@
n.id as id,
n.uuid as uuid,
n.version as version,
n.type_qname_id as type_qname_id,
n.store_id as store_id,
#{storeProtocol} as protocol,
#{storeIdentifier} as identifier,
Expand Down Expand Up @@ -174,6 +176,7 @@
node.id as id,
node.uuid as uuid,
node.version as version,
node.type_qname_id as type_qname_id,
node.store_id as store_id,
#{storeProtocol} as protocol,
#{storeIdentifier} as identifier,
Expand All @@ -187,8 +190,9 @@
left outer join alf_namespace ns on qname.ns_id = ns.id

join alf_node_properties np on np.node_id=node.id
join alf_qname qnp on qnp.id=np.qname_id and qnp.local_name='name'
join alf_qname qnp on qnp.id=np.qname_id and qnp.local_name in ('name','originalId')
where
node.store_id = #{storeId} and
node.uuid = #{uuid}
</select>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ indexer.properties.url.prefix = node/details

#Used in NodeDetailsWebScripts
indexer.document.url.prefix = slingshot/node
indexer.share.url = http://${share.host}:${share.port}${share.context}
indexer.share.url = http://${share.host}:${share.port}/${share.context}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also share.context=/share needs to be changed to share.context=share


indexer.changes.nodesperacl=1000
indexer.changes.nodespertxn=1000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@
<property name="previewUrlPrefix" value="${indexer.preview.url.prefix}"/>
<property name="shareUrl" value="${indexer.share.url}"/>
<property name="thumbnailUrlPrefix" value="${indexer.thumbnail.url.prefix}"/>
<property name="sysAdminParams" ref="sysAdminParams" />
<property name="thumbnailService" ref="ThumbnailService" />
<property name="scriptThumbnailService" ref="thumbnailServiceScript" />
<property name="contentService" ref="ContentService" />
</bean>

<bean id="webscript.com.github.maoo.indexer.webscripts.authresolve.get"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.io.InputStream;

import com.github.maoo.indexer.utils.Utils;
import org.alfresco.model.ContentModel;
Expand All @@ -48,6 +49,21 @@
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.ResourceLoader;

import org.alfresco.repo.admin.SysAdminParams;
import org.alfresco.repo.thumbnail.script.ScriptThumbnailService;
import org.alfresco.service.cmr.thumbnail.ThumbnailService;
import org.alfresco.repo.thumbnail.ThumbnailDefinition;
import org.alfresco.repo.thumbnail.ThumbnailRegistry;
import org.alfresco.service.cmr.repository.ContentReader;
import org.apache.commons.io.IOUtils;
import org.apache.commons.codec.binary.Base64;

import org.alfresco.service.cmr.repository.ContentService;

import com.google.gdata.util.common.base.StringUtil;

/**
Expand All @@ -70,10 +86,11 @@
* libraries (or StringBuffer), render out the payload without passing through
* FreeMarker template
*/
public class NodeDetailsWebScript extends DeclarativeWebScript {
public class NodeDetailsWebScript extends DeclarativeWebScript implements InitializingBean, ResourceLoaderAware {

protected static final Log logger = LogFactory.getLog(NodeDetailsWebScript.class);
protected static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
private static final String BASE_READ_PERMISSIONS = "ReadPermissions";

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
Expand Down Expand Up @@ -120,7 +137,8 @@ protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, C
for (Acl acl : acls) {
List<AccessControlEntry> aces = aclDao.getAccessControlList(acl.getId()).getEntries();
for (AccessControlEntry ace : aces) {
if (ace.getAccessStatus().equals(AccessStatus.ALLOWED)) {
if ((!ace.getPermission().getName().equals(BASE_READ_PERMISSIONS))
&& ace.getAccessStatus().equals(AccessStatus.ALLOWED)) {
if (!readableAuthorities.contains(ace.getAuthority())) {
readableAuthorities.add(ace.getAuthority());
}
Expand All @@ -142,11 +160,13 @@ protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, C
model.put("serviceContextPath", serviceContextPath);
model.put("documentUrlPrefix", documentUrlPrefix);
model.put("shareUrl", shareUrl);
model.put("thumbnailUrlPrefix", thumbnailUrlPrefix);
model.put("previewUrlPrefix", previewUrlPrefix);
model.put("shareUrlPrefix", shareUrlPrefix);
model.put("thumbnailUrlPrefix", thumbnailUrlPrefix);
model.put("previewUrlPrefix", previewUrlPrefix);

String documentUrlPath = String.format("/%s/%s/%s", storeProtocol, storeId, uuid);
model.put("documentUrlPath", documentUrlPath);


// Calculating the contentUrlPath and adding it only if the contentType
// is child of cm:content
Expand All @@ -170,18 +190,86 @@ protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, C
}
}

String previewUrlPath = String.format("/api/node/%s/%s/%s/content/thumbnails/webpreview", storeProtocol,
storeId, uuid);
model.put("previewUrlPath", previewUrlPath);

String thumbnailUrlPath = String.format(
"/api/node/%s/%s/%s/content/thumbnails/doclib?c=queue&ph=true&lastModified=1", storeProtocol, storeId,
uuid);
model.put("thumbnailUrlPath", thumbnailUrlPath);

String previewUrlPath = String.format("/api/node/%s/%s/%s/content/thumbnails/webpreview", storeProtocol,
storeId, uuid);
model.put("previewUrlPath", previewUrlPath);
ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
ThumbnailDefinition details = registry.getThumbnailDefinition("doclib");
try {
NodeRef thumbRef = thumbnailService.getThumbnailByName(nodeRef, ContentModel.PROP_CONTENT, "doclib");
if (thumbRef == null) {
thumbRef = thumbnailService.createThumbnail(nodeRef, ContentModel.PROP_CONTENT, details.getMimetype(),
details.getTransformationOptions(), details.getName());
}

ContentReader thumbReader = contentService.getReader(thumbRef, ContentModel.PROP_CONTENT);
InputStream thumbsIs = thumbReader.getContentInputStream();
String thumbBase64 = Base64.encodeBase64String(IOUtils.toByteArray(thumbsIs));
model.put("thumbnailBase64", thumbBase64);
IOUtils.closeQuietly(thumbsIs);
} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("It was not possible to get/build thumbnail doclib for nodeRef: " + nodeRef + ". Message: "
+ e.getMessage());
}

// thumbnail placeholder
String phPath = scriptThumbnailService.getMimeAwarePlaceHolderResourcePath("doclib", details.getMimetype());

StringBuilder sb = new StringBuilder("classpath:").append(phPath);
final String classpathResource = sb.toString();

InputStream is = null;
try {
is = resourceLoader.getResource(classpathResource).getInputStream();
String thumbBase64 = Base64.encodeBase64String(IOUtils.toByteArray(is));
model.put("thumbnailBase64", thumbBase64);
} catch (Exception e2) {
if (logger.isWarnEnabled()) {
logger.warn("It was not possible to get/build placeholder thumbnail doclib for nodeRef: " + nodeRef
+ ". Message: " + e2.getMessage());
}
} finally {
IOUtils.closeQuietly(is);
}

}

model.put("contentUrlPrefix", contentUrlPrefix);

return model;
}

@Override
public void afterPropertiesSet() throws Exception {
boolean alfrescoWithPort = true;
if ((sysAdminParams.getAlfrescoProtocol() == "https" && sysAdminParams.getAlfrescoPort() == 443)
|| (sysAdminParams.getAlfrescoProtocol() == "http" && sysAdminParams.getAlfrescoPort() == 80)) {
alfrescoWithPort = false;
}
String alfrescoPrefix = sysAdminParams.getAlfrescoProtocol() + "://" + sysAdminParams.getAlfrescoHost()
+ (alfrescoWithPort ? ":" + sysAdminParams.getAlfrescoPort() : "") + "/"
+ sysAdminParams.getAlfrescoContext();
contentUrlPrefix = alfrescoPrefix + "/service";
previewUrlPrefix = alfrescoPrefix + "/service";
thumbnailUrlPrefix = alfrescoPrefix + "/service";

boolean shareWithPort = true;
if ((sysAdminParams.getShareProtocol() == "https" && sysAdminParams.getSharePort() == 443)
|| (sysAdminParams.getShareProtocol() == "http" && sysAdminParams.getSharePort() == 80)) {
shareWithPort = false;
}
shareUrlPrefix = sysAdminParams.getShareProtocol() + "://" + sysAdminParams.getShareHost()
+ (shareWithPort ? ":" + sysAdminParams.getSharePort() : "") + "/" + sysAdminParams.getShareContext();

}

private boolean isContentAware(NodeRef nodeRef) {
QName contentType = nodeService.getType(nodeRef);
return dictionaryService.isSubClass(contentType, ContentModel.TYPE_CONTENT);
Expand Down Expand Up @@ -229,15 +317,38 @@ private List<Acl> getAllAcls(Long nodeAclId) {
}
}

public List<String> getThumbnailDefinitions(NodeRef nodeRef) {
List<String> result = new ArrayList<String>(7);

ContentReader contentReader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
if (contentReader != null) {
String mimetype = contentReader.getMimetype();
List<ThumbnailDefinition> thumbnailDefinitions = thumbnailService.getThumbnailRegistry()
.getThumbnailDefinitions(mimetype, contentReader.getSize());
for (ThumbnailDefinition thumbnailDefinition : thumbnailDefinitions) {
result.add(thumbnailDefinition.getName());
}
}

return result;
}

private DictionaryService dictionaryService;
private NamespaceService namespaceService;
private NodeService nodeService;
private NodeDAO nodeDao;
private AclDAO aclDao;
private String documentUrlPrefix;
private String shareUrl;
private String shareUrlPrefix;
private String thumbnailUrlPrefix;
private String previewUrlPrefix;
private SysAdminParams sysAdminParams;
private ResourceLoader resourceLoader;
private ScriptThumbnailService scriptThumbnailService;
private ThumbnailService thumbnailService;
private ContentService contentService;
private String contentUrlPrefix;

public void setDictionaryService(DictionaryService dictionaryService) {
this.dictionaryService = dictionaryService;
Expand Down Expand Up @@ -274,4 +385,34 @@ public void setThumbnailUrlPrefix(String thumbnailUrlPrefix) {
public void setPreviewUrlPrefix(String previewUrlPrefix) {
this.previewUrlPrefix = previewUrlPrefix;
}

public void setShareUrlPrefix(String shareUrlPrefix) {
this.shareUrlPrefix = shareUrlPrefix;
}

public void setSysAdminParams(SysAdminParams sysAdminParams) {
this.sysAdminParams = sysAdminParams;
}

public void setThumbnailService(ThumbnailService thumbnailService) {
this.thumbnailService = thumbnailService;
}

@Override
public void setResourceLoader(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}

public void setScriptThumbnailService(ScriptThumbnailService scriptThumbnailService) {
this.scriptThumbnailService = scriptThumbnailService;
}

public void setContentService(ContentService contentService) {
this.contentService = contentService;
}

public void setContentUrlPrefix(String contentUrlPrefix) {
this.contentUrlPrefix = contentUrlPrefix;
}

}