- permissions for blog and forum components

- cleanup of taglibrary code

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10400 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Michael Ru
2008-08-18 15:50:09 +00:00
parent 6cd48e1cbf
commit b2418a1eac
24 changed files with 123 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
<#-- <#--
This template renders the blog configuration json data. This template renders the blog data object.
--> -->
<#macro blogJSON item> <#macro blogJSON item>
<#escape x as jsonUtils.encodeJSONString(x)> <#escape x as jsonUtils.encodeJSONString(x)>
@@ -13,7 +13,12 @@
"description" : "${item.properties["blg:description"]!''}", "description" : "${item.properties["blg:description"]!''}",
"url" : "${item.properties["blg:url"]!''}", "url" : "${item.properties["blg:url"]!''}",
"username" : "${item.properties["blg:userName"]!''}", "username" : "${item.properties["blg:userName"]!''}",
"password" : "${item.properties["blg:password"]!''}" "password" : "${item.properties["blg:password"]!''}",
"permissions" : {
"create" : ${item.hasPermission("CreateChildren")?string},
"edit" : ${item.hasPermission("Write")?string},
"delete" : ${item.hasPermission("Delete")?string}
}
} }
</#escape> </#escape>
</#macro> </#macro>

View File

@@ -44,7 +44,10 @@
</#if> </#if>
"createdOn" : "${item.createdDate?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}", "createdOn" : "${item.createdDate?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}",
"modifiedOn" : "${item.modifiedDate?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}", "modifiedOn" : "${item.modifiedDate?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}",
"permissions" : {"edit" : true, "publishExt" : true, "delete" : true}, "permissions" : {
"edit" : ${item.node.hasPermission("Write")?string},
"delete" : ${item.node.hasPermission("Delete")?string}
},
"commentCount" : ${item.commentCount?c}, "commentCount" : ${item.commentCount?c},
"tags" : [<#list item.tags as x>"${x}"<#if x_has_next>, </#if></#list>], "tags" : [<#list item.tags as x>"${x}"<#if x_has_next>, </#if></#list>],

View File

@@ -41,6 +41,9 @@ function main()
// fetch the contentLength param // fetch the contentLength param
var contentLength = args["contentLength"] != undefined ? parseInt(args["contentLength"]) : -1; var contentLength = args["contentLength"] != undefined ? parseInt(args["contentLength"]) : -1;
model.contentLength = isNaN(contentLength) ? -1 : contentLength; model.contentLength = isNaN(contentLength) ? -1 : contentLength;
// assign the blog node
model.blog = node;
} }
main(); main();

View File

@@ -1,5 +1,12 @@
<#import "../blogpost.lib.ftl" as blogpostLib/> <#import "../blogpost.lib.ftl" as blogpostLib/>
<#import "../../generic-paged-results.lib.ftl" as gen/> <#import "../../generic-paged-results.lib.ftl" as gen/>
{
"blogPermissions" : {
"create" : ${blog.hasPermission("CreateChildren")?string},
"edit" : ${blog.hasPermission("Write")?string},
"delete" : ${blog.hasPermission("Delete")?string}
},
<@gen.pagedResults data=data ; item> <@gen.pagedResults data=data ; item>
<@blogpostLib.blogpostJSON item=item /> <@blogpostLib.blogpostJSON item=item />
</@gen.pagedResults> </@gen.pagedResults>
}

View File

@@ -42,6 +42,9 @@ function main()
// fetch the contentLength param // fetch the contentLength param
var contentLength = args["contentLength"] != undefined ? parseInt(args["contentLength"]) : -1; var contentLength = args["contentLength"] != undefined ? parseInt(args["contentLength"]) : -1;
model.contentLength = isNaN(contentLength) ? -1 : contentLength; model.contentLength = isNaN(contentLength) ? -1 : contentLength;
// assign the blog node
model.blog = node;
} }
main(); main();

View File

@@ -1,5 +1,12 @@
<#import "../blogpost.lib.ftl" as blogpostLib/> <#import "../blogpost.lib.ftl" as blogpostLib/>
<#import "../../generic-paged-results.lib.ftl" as gen/> <#import "../../generic-paged-results.lib.ftl" as gen/>
{
"blogPermissions" : {
"create" : ${blog.hasPermission("CreateChildren")?string},
"edit" : ${blog.hasPermission("Write")?string},
"delete" : ${blog.hasPermission("Delete")?string}
},
<@gen.pagedResults data=data ; item> <@gen.pagedResults data=data ; item>
<@blogpostLib.blogpostJSON item=item /> <@blogpostLib.blogpostJSON item=item />
</@gen.pagedResults> </@gen.pagedResults>
}

View File

@@ -44,6 +44,9 @@ function main()
// fetch the contentLength param // fetch the contentLength param
var contentLength = args["contentLength"] != undefined ? parseInt(args["contentLength"]) : -1; var contentLength = args["contentLength"] != undefined ? parseInt(args["contentLength"]) : -1;
model.contentLength = isNaN(contentLength) ? -1 : contentLength; model.contentLength = isNaN(contentLength) ? -1 : contentLength;
// assign the blog node
model.blog = node;
} }
main(); main();

View File

@@ -1,5 +1,12 @@
<#import "../blogpost.lib.ftl" as blogpostLib/> <#import "../blogpost.lib.ftl" as blogpostLib/>
<#import "../../generic-paged-results.lib.ftl" as gen/> <#import "../../generic-paged-results.lib.ftl" as gen/>
{
"blogPermissions" : {
"create" : ${blog.hasPermission("CreateChildren")?string},
"edit" : ${blog.hasPermission("Write")?string},
"delete" : ${blog.hasPermission("Delete")?string}
},
<@gen.pagedResults data=data ; item> <@gen.pagedResults data=data ; item>
<@blogpostLib.blogpostJSON item=item /> <@blogpostLib.blogpostJSON item=item />
</@gen.pagedResults> </@gen.pagedResults>
}

View File

@@ -40,6 +40,9 @@ function main()
// fetch the contentLength param // fetch the contentLength param
var contentLength = args["contentLength"] != undefined ? parseInt(args["contentLength"]) : -1; var contentLength = args["contentLength"] != undefined ? parseInt(args["contentLength"]) : -1;
model.contentLength = isNaN(contentLength) ? -1 : contentLength; model.contentLength = isNaN(contentLength) ? -1 : contentLength;
// assign the blog node
model.blog = node;
} }
main(); main();

View File

@@ -1,5 +1,12 @@
<#import "../blogpost.lib.ftl" as blogpostLib/> <#import "../blogpost.lib.ftl" as blogpostLib/>
<#import "../../generic-paged-results.lib.ftl" as gen/> <#import "../../generic-paged-results.lib.ftl" as gen/>
{
"blogPermissions" : {
"create" : ${blog.hasPermission("CreateChildren")?string},
"edit" : ${blog.hasPermission("Write")?string},
"delete" : ${blog.hasPermission("Delete")?string}
},
<@gen.pagedResults data=data ; item> <@gen.pagedResults data=data ; item>
<@blogpostLib.blogpostJSON item=item /> <@blogpostLib.blogpostJSON item=item />
</@gen.pagedResults> </@gen.pagedResults>
}

View File

@@ -80,6 +80,9 @@ function main()
// fetch the contentLength param // fetch the contentLength param
var contentLength = args["contentLength"] != undefined ? parseInt(args["contentLength"]) : -1; var contentLength = args["contentLength"] != undefined ? parseInt(args["contentLength"]) : -1;
model.contentLength = isNaN(contentLength) ? -1 : contentLength; model.contentLength = isNaN(contentLength) ? -1 : contentLength;
// assign the blog node
model.blog = node;
} }
main(); main();

View File

@@ -1,5 +1,12 @@
<#import "../blogpost.lib.ftl" as blogpostLib/> <#import "../blogpost.lib.ftl" as blogpostLib/>
<#import "../../generic-paged-results.lib.ftl" as gen/> <#import "../../generic-paged-results.lib.ftl" as gen/>
{
"blogPermissions" : {
"create" : ${blog.hasPermission("CreateChildren")?string},
"edit" : ${blog.hasPermission("Write")?string},
"delete" : ${blog.hasPermission("Delete")?string}
},
<@gen.pagedResults data=data ; item> <@gen.pagedResults data=data ; item>
<@blogpostLib.blogpostJSON item=item /> <@blogpostLib.blogpostJSON item=item />
</@gen.pagedResults> </@gen.pagedResults>
}

View File

@@ -1,5 +1,7 @@
<#import "comment.lib.ftl" as commentLib/> <#import "comment.lib.ftl" as commentLib/>
<#import "../generic-paged-results.lib.ftl" as gen/> <#import "../generic-paged-results.lib.ftl" as gen/>
{
<@gen.pagedResults data=data ; item> <@gen.pagedResults data=data ; item>
<@commentLib.commentJSON item=item /> <@commentLib.commentJSON item=item />
</@gen.pagedResults> </@gen.pagedResults>
}

View File

@@ -99,6 +99,9 @@ function main()
// fetch the contentLength param // fetch the contentLength param
var contentLength = args["contentLength"] != undefined ? parseInt(args["contentLength"]) : -1; var contentLength = args["contentLength"] != undefined ? parseInt(args["contentLength"]) : -1;
model.contentLength = isNaN(contentLength) ? -1 : contentLength; model.contentLength = isNaN(contentLength) ? -1 : contentLength;
// also set the forum node
model.forum = node;
} }
main(); main();

View File

@@ -1,6 +1,12 @@
<#import "../post.lib.ftl" as postLib/> <#import "../post.lib.ftl" as postLib/>
<#import "../../generic-paged-results.lib.ftl" as gen/> <#import "../../generic-paged-results.lib.ftl" as gen/>
{
"forumPermissions" : {
"create" : ${forum.hasPermission("CreateChildren")?string},
"edit" : ${forum.hasPermission("Write")?string},
"delete" : ${forum.hasPermission("Delete")?string}
},
<@gen.pagedResults data=data ; item> <@gen.pagedResults data=data ; item>
<@postLib.postJSON postData=item /> <@postLib.postJSON postData=item />
</@gen.pagedResults> </@gen.pagedResults>
}

View File

@@ -36,6 +36,9 @@ function main()
// fetch the contentLength param // fetch the contentLength param
var contentLength = args["contentLength"] != undefined ? parseInt(args["contentLength"]) : -1; var contentLength = args["contentLength"] != undefined ? parseInt(args["contentLength"]) : -1;
model.contentLength = isNaN(contentLength) ? -1 : contentLength; model.contentLength = isNaN(contentLength) ? -1 : contentLength;
// also set the forum node
model.forum = node;
} }
main(); main();

View File

@@ -1,5 +1,12 @@
<#import "../post.lib.ftl" as postLib/> <#import "../post.lib.ftl" as postLib/>
<#import "../../generic-paged-results.lib.ftl" as gen/> <#import "../../generic-paged-results.lib.ftl" as gen/>
{
"forumPermissions" : {
"create" : ${forum.hasPermission("CreateChildren")?string},
"edit" : ${forum.hasPermission("Write")?string},
"delete" : ${forum.hasPermission("Delete")?string}
},
<@gen.pagedResults data=data ; item> <@gen.pagedResults data=data ; item>
<@postLib.postJSON postData=item /> <@postLib.postJSON postData=item />
</@gen.pagedResults> </@gen.pagedResults>
}

View File

@@ -42,6 +42,9 @@ function main()
// fetch the contentLength param // fetch the contentLength param
var contentLength = args["contentLength"] != undefined ? parseInt(args["contentLength"]) : -1; var contentLength = args["contentLength"] != undefined ? parseInt(args["contentLength"]) : -1;
model.contentLength = isNaN(contentLength) ? -1 : contentLength; model.contentLength = isNaN(contentLength) ? -1 : contentLength;
// also set the forum node
model.forum = node;
} }
main(); main();

View File

@@ -1,5 +1,12 @@
<#import "../post.lib.ftl" as postLib/> <#import "../post.lib.ftl" as postLib/>
<#import "../../generic-paged-results.lib.ftl" as gen/> <#import "../../generic-paged-results.lib.ftl" as gen/>
{
"forumPermissions" : {
"create" : ${forum.hasPermission("CreateChildren")?string},
"edit" : ${forum.hasPermission("Write")?string},
"delete" : ${forum.hasPermission("Delete")?string}
},
<@gen.pagedResults data=data ; item> <@gen.pagedResults data=data ; item>
<@postLib.postJSON postData=item /> <@postLib.postJSON postData=item />
</@gen.pagedResults> </@gen.pagedResults>
}

View File

@@ -43,6 +43,9 @@ function main()
// fetch the contentLength param // fetch the contentLength param
var contentLength = args["contentLength"] != undefined ? parseInt(args["contentLength"]) : -1; var contentLength = args["contentLength"] != undefined ? parseInt(args["contentLength"]) : -1;
model.contentLength = isNaN(contentLength) ? -1 : contentLength; model.contentLength = isNaN(contentLength) ? -1 : contentLength;
// also set the forum node
model.forum = node;
} }
main(); main();

View File

@@ -1,6 +1,12 @@
<#import "../post.lib.ftl" as postLib/> <#import "../post.lib.ftl" as postLib/>
<#import "../../generic-paged-results.lib.ftl" as gen/> <#import "../../generic-paged-results.lib.ftl" as gen/>
{
"forumPermissions" : {
"create" : ${forum.hasPermission("CreateChildren")?string},
"edit" : ${forum.hasPermission("Write")?string},
"delete" : ${forum.hasPermission("Delete")?string}
},
<@gen.pagedResults data=data ; item> <@gen.pagedResults data=data ; item>
<@postLib.postJSON postData=item /> <@postLib.postJSON postData=item />
</@gen.pagedResults> </@gen.pagedResults>
}

View File

@@ -57,7 +57,7 @@
"repliesUrl" : "/forum/post/node/${refNode.nodeRef.storeRef.protocol}/${refNode.nodeRef.storeRef.identifier}/${refNode.nodeRef.id}/replies", "repliesUrl" : "/forum/post/node/${refNode.nodeRef.storeRef.protocol}/${refNode.nodeRef.storeRef.identifier}/${refNode.nodeRef.id}/replies",
"nodeRef" : "${refNode.nodeRef}", "nodeRef" : "${refNode.nodeRef}",
<#-- normal data, the post node will used to fetch it --> <#-- data coming from the post node -->
"title" : "${(post.properties.title!"")}", "title" : "${(post.properties.title!"")}",
"createdOn" : "${post.properties.created?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}", "createdOn" : "${post.properties.created?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}",
"modifiedOn" : "${post.properties.modified?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}", "modifiedOn" : "${post.properties.modified?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}",
@@ -74,7 +74,12 @@
</#if> </#if>
<@addContent post=post /> <@addContent post=post />
"replyCount" : <#if post.sourceAssocs["cm:references"]??>${post.sourceAssocs["cm:references"]?size?c}<#else>0</#if>, "replyCount" : <#if post.sourceAssocs["cm:references"]??>${post.sourceAssocs["cm:references"]?size?c}<#else>0</#if>,
"permissions" : { "edit": true, "delete" : true, "reply" : true } "permissions" :
{
"edit": ${post.hasPermission("Write")?string},
"reply" : ${post.parent.hasPermission("CreateChildren")?string},
"delete" : ${post.hasPermission("Delete")?string}
}
</#escape> </#escape>
</#macro> </#macro>

View File

@@ -10,14 +10,15 @@
Usage: Usage:
<#import "generic-paged-results.lib.ftl" as gen/> <#import "generic-paged-results.lib.ftl" as gen/>
{
<@gen.pagedResults data=data ; item> <@gen.pagedResults data=data ; item>
output of the individual item, for example by calling another macro: output of the individual item, for example by calling another macro:
<@yourLib.itemJSON item=item /> <@yourLib.itemJSON item=item />
</@gen.pagedResults> </@gen.pagedResults>
}
--> -->
<#macro pagedResults data> <#macro pagedResults data>
{
"total" : ${data.total?c}, "total" : ${data.total?c},
"pageSize" : ${data.pageSize?c}, "pageSize" : ${data.pageSize?c},
"startIndex" : ${data.startIndex?c}, "startIndex" : ${data.startIndex?c},
@@ -29,5 +30,4 @@ Usage:
<#if item_has_next>,</#if> <#if item_has_next>,</#if>
</#list> </#list>
] ]
}
</#macro> </#macro>

View File

@@ -56,9 +56,9 @@ public class DiscussionServiceTest extends BaseWebScriptTest
private SiteService siteService; private SiteService siteService;
private static final String USER_ADMIN = "admin"; private static final String USER_ADMIN = "admin";
private static final String USER_ONE = "UserOneSecond"; private static final String USER_ONE = "UserOneThird";
private static final String USER_TWO = "UserTwoSecond"; private static final String USER_TWO = "UserTwoThird";
private static final String SITE_SHORT_NAME_DISCUSSION = "DiscussionSiteShortName"; private static final String SITE_SHORT_NAME_DISCUSSION = "DiscussionSiteShortNameTwo";
private static final String COMPONENT_DISCUSSION = "discussion"; private static final String COMPONENT_DISCUSSION = "discussion";
private static final String URL_FORUM_POST = "/api/forum/post/site/" + SITE_SHORT_NAME_DISCUSSION + "/" + COMPONENT_DISCUSSION + "/"; private static final String URL_FORUM_POST = "/api/forum/post/site/" + SITE_SHORT_NAME_DISCUSSION + "/" + COMPONENT_DISCUSSION + "/";
@@ -79,6 +79,9 @@ public class DiscussionServiceTest extends BaseWebScriptTest
this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService"); this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService");
this.siteService = (SiteService)getServer().getApplicationContext().getBean("siteService"); this.siteService = (SiteService)getServer().getApplicationContext().getBean("siteService");
// Authenticate as user
this.authenticationComponent.setCurrentUser(USER_ADMIN);
// Create test site // Create test site
// - only create the site if it doesn't already exist // - only create the site if it doesn't already exist
SiteInfo siteInfo = this.siteService.getSite(SITE_SHORT_NAME_DISCUSSION); SiteInfo siteInfo = this.siteService.getSite(SITE_SHORT_NAME_DISCUSSION);
@@ -105,8 +108,10 @@ public class DiscussionServiceTest extends BaseWebScriptTest
this.authenticationComponent.setCurrentUser(USER_ADMIN); this.authenticationComponent.setCurrentUser(USER_ADMIN);
// delete the inviter user // delete the inviter user
personService.deletePerson(USER_ONE); //personService.deletePerson(USER_ONE);
personService.deletePerson(USER_TWO); //this.authenticationService.deleteAuthentication(USER_ONE);
//personService.deletePerson(USER_TWO);
//this.authenticationService.deleteAuthentication(USER_TWO);
// delete invite site // delete invite site
siteService.deleteSite(SITE_SHORT_NAME_DISCUSSION); siteService.deleteSite(SITE_SHORT_NAME_DISCUSSION);
@@ -134,7 +139,7 @@ public class DiscussionServiceTest extends BaseWebScriptTest
} }
// add the user as a member with the given role // add the user as a member with the given role
this.siteService.setMembership(SITE_SHORT_NAME_DISCUSSION, USER_ONE, role); this.siteService.setMembership(SITE_SHORT_NAME_DISCUSSION, userName, role);
} }