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

Fix access to properties of the folder quota #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,20 @@ public NodeRef doWork() throws Exception {

if(quotaParent != null) {

Long quotaSize = (Long) nodeService.getProperty(quotaParent, FolderQuotaModel.PROP_FQ_SIZE_QUOTA);
Long currentSize = (Long) nodeService.getProperty(quotaParent, FolderQuotaModel.PROP_FQ_SIZE_CURRENT);
Long quotaSize = getFolderQuotaSizeDefined(quotaParent);
Long currentSize = getFolderQuotaSizeCurrent(quotaParent);

String owner = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_OWNER);
if ((owner == null) || (owner.equals(OwnableService.NO_OWNER))) {
owner = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_CREATOR);
}
String owner = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_OWNER);
if ((owner == null) || (owner.equals(OwnableService.NO_OWNER))) {
owner = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_CREATOR);
}

if (quotaSize != null) {

if (currentSize + contentSize > quotaSize) {
throw new ContentQuotaException("User (" + owner + ") quota exceeded: content=" + contentSize +
", usage=" + currentSize +
", quota=" + quotaSize);
", usage=" + currentSize +
", quota=" + quotaSize);
} else {
updateSize(quotaParent, contentSize);
}
Expand Down Expand Up @@ -184,10 +184,11 @@ public NodeRef doWork() throws Exception {
}

if (quotaParentAfter != null) {
Long quotaSize = (Long) nodeService.getProperty(quotaParentAfter, FolderQuotaModel.PROP_FQ_SIZE_QUOTA);
Long currentSize = (Long) nodeService.getProperty(quotaParentAfter, FolderQuotaModel.PROP_FQ_SIZE_CURRENT);

Long quotaSize = getFolderQuotaSizeDefined(quotaParentAfter);
Long currentSize = getFolderQuotaSizeCurrent(quotaParentAfter);
if (currentSize + change > quotaSize) {
String folderName = (String) nodeService.getProperty(quotaParentAfter, ContentModel.PROP_NAME);
String folderName = getFolderQuotaName(quotaParentAfter);
throw new ContentQuotaException("Folder (" + folderName + ") quota exceeded: content=" + change +
", usage=" + currentSize +
", quota=" + quotaSize);
Expand All @@ -208,10 +209,10 @@ public NodeRef doWork() throws Exception {
});
if (quotaParent != null) {
long change = usage.getChangeSize(childAssocRef.getChildRef());
Long quotaSize = (Long) nodeService.getProperty(quotaParent, FolderQuotaModel.PROP_FQ_SIZE_QUOTA);
Long currentSize = (Long) nodeService.getProperty(quotaParent, FolderQuotaModel.PROP_FQ_SIZE_CURRENT);
Long quotaSize = getFolderQuotaSizeDefined(quotaParent);
Long currentSize = getFolderQuotaSizeCurrent(quotaParent);
if (currentSize + change > quotaSize) {
String folderName = (String) nodeService.getProperty(quotaParent, ContentModel.PROP_NAME);
String folderName = getFolderQuotaName(quotaParent);
throw new ContentQuotaException("Folder (" + folderName + ") quota exceeded: content=" + change +
", usage=" + currentSize +
", quota=" + quotaSize);
Expand Down Expand Up @@ -259,6 +260,31 @@ public Void doWork() throws Exception {

}

private String getFolderQuotaName(final NodeRef nodeRef) {
return (String) getFolderQuotaProperty(nodeRef, ContentModel.PROP_NAME);
}

private Long getFolderQuotaSizeDefined(final NodeRef nodeRef) {
return (Long) getFolderQuotaProperty(nodeRef, FolderQuotaModel.PROP_FQ_SIZE_QUOTA);
}

private Long getFolderQuotaSizeCurrent(final NodeRef nodeRef) {
return (Long) getFolderQuotaProperty(nodeRef, FolderQuotaModel.PROP_FQ_SIZE_CURRENT);
}

private Serializable getFolderQuotaProperty(final NodeRef nodeRef, final QName propertyQName) {

// Accessing folder quota can require system privileges if the current user only has access to a child folder
return AuthenticationUtil.runAsSystem(new AuthenticationUtil.RunAsWork<Serializable>() {

@Override
public Serializable doWork() throws Exception {
return nodeService.getProperty(nodeRef, propertyQName);
}
});
}


private void updateSize(NodeRef quotaFolder, Long sizeChange) {

AlfrescoTransactionSupport.bindListener(transactionListener);
Expand Down