diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/site/site.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/site/site.lib.ftl index 18ce5e8493..3e74d71bcb 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/site/site.lib.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/site/site.lib.ftl @@ -11,8 +11,6 @@ "shortName": "${site.shortName}", "title": "${site.title}", "description": "${site.description}", - "createdDate": "${xmldate(site.createdDate)}", - "lastModifiedDate": "${xmldate(site.lastModifiedDate)}", <#if site.node?exists> "node": "${url.serviceContext + "/api/node/" + site.node.storeType + "/" + site.node.storeId + "/" + site.node.id}", "tagScope": "${url.serviceContext + "/api/tagscopes/" + site.node.storeType + "/" + site.node.storeId + "/" + site.node.id}", diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/site/sites.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/site/sites.get.desc.xml index bef1269b12..7b2ac18195 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/site/sites.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/site/sites.get.desc.xml @@ -1,7 +1,7 @@ Get sites Get a collection of the sites in the repository. The collection can be filtered by name and/or site preset. - /api/sites?nf={namefilter?}&spf={sitepresetfilter?}&size={pagesize?}&roles={roles?}&admin={admin?} + /api/sites?nf={namefilter?}&spf={sitepresetfilter?}&size={pagesize?}&roles={roles?} argument user required diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/site/sites.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/site/sites.get.js index 82979a5110..bd993c10ad 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/site/sites.get.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/site/sites.get.js @@ -1,25 +1,14 @@ function main() { - // Get the filter parameters - var nameFilter = args["nf"]; - var sitePreset = args["spf"]; - var sizeString = args["size"]; - var size = sizeString != null ? parseInt(sizeString) : -1; - var asSiteAdmin = (args["admin"] == "true"); - - // Get the list of sites - var sites; - if (asSiteAdmin) - { - // The user's access right is checked within the getSitesAsSiteAdmin method. - sites = siteService.getSitesAsSiteAdmin(nameFilter, sitePreset, size); - } - else - { - sites = siteService.getSites(nameFilter, sitePreset, size); - } - model.sites = sites; - model.roles = (args["roles"] !== null ? args["roles"] : "managers"); + // Get the filter parameters + var nameFilter = args["nf"]; + var sitePreset = args["spf"]; + var sizeString = args["size"]; + + // Get the list of sites + var sites = siteService.getSites(nameFilter, sitePreset, sizeString != null ? parseInt(sizeString) : -1); + model.sites = sites; + model.roles = (args["roles"] !== null ? args["roles"] : "managers"); } main(); \ No newline at end of file diff --git a/source/test-java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java b/source/test-java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java index dc91ab68ea..4abdf2ff7d 100644 --- a/source/test-java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java +++ b/source/test-java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java @@ -78,6 +78,7 @@ public class SiteServiceTest extends BaseWebScriptTest private static final String URL_SITES = "/api/sites"; private static final String URL_SITES_QUERY = URL_SITES + "/query"; private static final String URL_MEMBERSHIPS = "/memberships"; + private static final String URL_SITES_ADMIN = "/api/admin-sites"; private List createdSites = new ArrayList(5); @@ -1345,41 +1346,72 @@ public class SiteServiceTest extends BaseWebScriptTest assertEquals(SiteVisibility.PRIVATE.toString(), result.get("visibility")); this.authenticationComponent.setCurrentUser(USER_THREE); - Response response = sendRequest(new GetRequest(URL_SITES), 200); - JSONArray jsonArray = new JSONArray(response.getContentAsString()); - // USER_THREE can see the public and moderated sites - assertTrue("result too small", jsonArray.length() >= 2); - assertFalse(USER_THREE + " doesn’t have permission to access private sites that he is not member of.", - canSeePrivateSites(jsonArray)); + // Note: we'll get 404 rather than 403 + sendRequest(new GetRequest(URL_SITES_ADMIN), 404); this.authenticationComponent.setCurrentUser(USER_FOUR_AS_SITE_ADMIN); - // Even though user4 is a siteAdmin, if a request doesn’t specify - // the 'admin=true' query param, the result will be based on his access rights. - response = sendRequest(new GetRequest(URL_SITES), 200); - assertFalse(USER_FOUR_AS_SITE_ADMIN - + " doesn’t have permission to access private sites that he is not member of.", - canSeePrivateSites(jsonArray)); + Response response = sendRequest(new GetRequest(URL_SITES_ADMIN), 200); + JSONObject jsonObject = new JSONObject(response.getContentAsString()); + JSONArray jsonArray = jsonObject.getJSONObject("list").getJSONArray("entries"); - response = sendRequest(new GetRequest(URL_SITES+"?admin=true"), 200); - jsonArray = new JSONArray(response.getContentAsString()); int siteAdminGetSitesSize = jsonArray.length(); // SiteAdmin can see the public, moderated and private sites assertTrue("result too small", siteAdminGetSitesSize >= 4); assertTrue("Site admin can access all the sites (PUBLIC | MODERATED | PRIVATE).", canSeePrivateSites(jsonArray)); this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); - response = sendRequest(new GetRequest(URL_SITES), 200); - jsonArray = new JSONArray(response.getContentAsString()); + response = sendRequest(new GetRequest(URL_SITES_ADMIN), 200); + jsonObject = new JSONObject(response.getContentAsString()); + jsonArray = jsonObject.getJSONObject("list").getJSONArray("entries");; assertEquals("SiteAdmin must have access to the same sites as the super Admin.", siteAdminGetSitesSize, jsonArray.length()); } + + public void testGetAllSitesPagedAsSiteAdmin() throws Exception + { + // we use this as a name filter + long siteNamePrefix = System.currentTimeMillis(); + String siteNameSuffix = GUID.generate();; + String user1PublicSiteName = siteNamePrefix + siteNameSuffix.substring(siteNameSuffix.lastIndexOf('-')); + + createSite("myPreset", user1PublicSiteName, "u1PublicSite", "myDescription", + SiteVisibility.PUBLIC, 200); + // Create 5 more sites + for(int i =1; i < 6; i++) + { + createSite("myPreset", GUID.generate(), "u1PublicSite"+i, "myDescription"+i, + SiteVisibility.PUBLIC, 200); + } + + this.authenticationComponent.setCurrentUser(USER_FOUR_AS_SITE_ADMIN); + + Response response = sendRequest(new GetRequest(URL_SITES_ADMIN+"?maxItems=5&skipCount=0"), 200); + JSONObject jsonObject = new JSONObject(response.getContentAsString()); + JSONObject paging = jsonObject.getJSONObject("list").getJSONObject("pagination"); + assertEquals("The skipCount must be 0", 0, paging.getInt("skipCount")); + assertEquals("The maxItems must be 5", 5, paging.getInt("maxItems")); + // There are only 7 sites in total (including the default alfresco site 'swsdp'), + // but in case there are hanging sites that haven't been cleaned, + // or the default alfresco site has been deleted by previous tests, we check for what we have created in this test. + assertTrue("The totalItems must be 6", paging.getInt("totalItems") >= 6 ); + assertTrue(paging.getBoolean("hasMoreItems")); + + response = sendRequest(new GetRequest(URL_SITES_ADMIN+"?nf="+siteNamePrefix+"&maxItems=5&skipCount=0"), 200); + jsonObject = new JSONObject(response.getContentAsString()); + paging = jsonObject.getJSONObject("list").getJSONObject("pagination"); + assertEquals("The count must be 1", 1, paging.getInt("count")); + assertEquals("The maxItems must be 5", 5, paging.getInt("maxItems")); + assertEquals("The totalItems must be 1", 1, paging.getInt("totalItems")); + assertFalse(paging.getBoolean("hasMoreItems")); + + } private boolean canSeePrivateSites(JSONArray jsonArray) throws Exception { for (int i = 0; i < jsonArray.length(); i++) { JSONObject obj = jsonArray.getJSONObject(i); - String visibility = obj.getString("visibility"); + String visibility = obj.getJSONObject("entry").getString("visibility"); if (SiteVisibility.PRIVATE.equals(SiteVisibility.valueOf(visibility))) { return true;