From 84067ad8407158b1266106d8eed9d2cbfa1b95c3 Mon Sep 17 00:00:00 2001 From: Neil McErlean Date: Thu, 14 Jul 2011 12:07:27 +0000 Subject: [PATCH] ALF-9441 part of ALF-9151. potentialmembers.get.js now uses new ScriptAuthorityService.getGroups() method for immediately consistent results. Added new test case. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29027 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../site/membership/potentialmembers.get.js | 7 ++-- .../web/scripts/site/SiteServiceTest.java | 42 +++++++++++++++---- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/site/membership/potentialmembers.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/site/membership/potentialmembers.get.js index 3c31d6ef7c..2b2a6e1bfc 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/site/membership/potentialmembers.get.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/site/membership/potentialmembers.get.js @@ -4,7 +4,7 @@ function main() var siteShortName = url.templateArgs.shortname, site = siteService.getSite(siteShortName), filter = (args.filter != null) ? args.filter : (args.shortNameFilter != null) ? args.shortNameFilter : "", - maxResults = (args.maxResults == null) ? 0 : parseInt(args.maxResults, 10), + maxResults = (args.maxResults == null) ? 10 : parseInt(args.maxResults, 10), authorityType = args.authorityType, zone = args.zone; @@ -20,7 +20,7 @@ function main() var peopleFound = [], groupsFound = [], notAllowed = [], - i, ii, name; + i, ii, name, paging; if (authorityType == null || authorityType == "USER") { @@ -58,7 +58,8 @@ function main() // Get the collection of groups if (zone == null) { - groupsFound = groups.searchGroups(filter); + paging = utils.createPaging(maxResults, -1); + groupsFound = groups.getGroups(filter, paging); } else { diff --git a/source/java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java b/source/java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java index 87c6aafdda..2b7f29d328 100644 --- a/source/java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java +++ b/source/java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java @@ -259,8 +259,8 @@ public class SiteServiceTest extends BaseWebScriptTest // Create a site and get it String shortName = GUID.generate(); - JSONObject result = createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200); - Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName), 200); + createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200); + sendRequest(new GetRequest(URL_SITES + "/" + shortName), 200); } @@ -293,20 +293,20 @@ public class SiteServiceTest extends BaseWebScriptTest public void testDeleteSite() throws Exception { // Delete non-existent site - Response response = sendRequest(new DeleteRequest(URL_SITES + "/" + "somerandomshortname"), 404); + sendRequest(new DeleteRequest(URL_SITES + "/" + "somerandomshortname"), 404); // Create a site String shortName = GUID.generate(); - JSONObject result = createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200); + createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200); // Get the site - response = sendRequest(new GetRequest(URL_SITES + "/" + shortName), 200); + sendRequest(new GetRequest(URL_SITES + "/" + shortName), 200); // Delete the site - response = sendRequest(new DeleteRequest(URL_SITES + "/" + shortName), 200); + sendRequest(new DeleteRequest(URL_SITES + "/" + shortName), 200); // Get the site - response = sendRequest(new GetRequest(URL_SITES + "/" + shortName), 404); + sendRequest(new GetRequest(URL_SITES + "/" + shortName), 404); } public void testGetMemberships() throws Exception @@ -340,7 +340,6 @@ public class SiteServiceTest extends BaseWebScriptTest // Post the membership Response response = sendRequest(new PostRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 200); - JSONObject result = new JSONObject(response.getContentAsString()); // Check the result assertEquals(SiteModel.SITE_CONSUMER, membership.get("role")); @@ -572,6 +571,33 @@ public class SiteServiceTest extends BaseWebScriptTest assertEquals(2, result.length()); } + /** + * @since 4.0 + */ + public void testGetPotentialMemberships() throws Exception + { + // Create a site + String shortName = GUID.generate(); + createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200); + + // Check the memberships + String filter = ""; + String authorityType = "GROUP"; + String url = "/api/sites/" + shortName + "/potentialmembers?filter=" + filter + "&maxResults=10&authorityType=" + authorityType; + Response response = sendRequest(new GetRequest(url), 200); + final String contentAsString = response.getContentAsString(); + JSONObject result = new JSONObject(contentAsString); + assertNotNull(result); + JSONArray people = result.getJSONArray("people"); + assertNotNull("people array was null", people); + + JSONArray data = result.getJSONArray("data"); + assertNotNull("data array was null", data); + + // Delete the site + sendRequest(new DeleteRequest(URL_SITES + "/" + shortName), 200); + } + public void testSiteCustomProperties() throws Exception {