mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud)
64429: Merged WAT1 (4.3/Cloud) to HEAD-BUG-FIX (4.3/Cloud) 62555: ACE-493, ACE-503 and ACE-511: Modified sites service APIs to support Manage Sites feature. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@64575 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -11,6 +11,8 @@
|
|||||||
"shortName": "${site.shortName}",
|
"shortName": "${site.shortName}",
|
||||||
"title": "${site.title}",
|
"title": "${site.title}",
|
||||||
"description": "${site.description}",
|
"description": "${site.description}",
|
||||||
|
"createdDate": "${xmldate(site.createdDate)}",
|
||||||
|
"lastModifiedDate": "${xmldate(site.lastModifiedDate)}",
|
||||||
<#if site.node?exists>
|
<#if site.node?exists>
|
||||||
"node": "${url.serviceContext + "/api/node/" + site.node.storeType + "/" + site.node.storeId + "/" + site.node.id}",
|
"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}",
|
"tagScope": "${url.serviceContext + "/api/tagscopes/" + site.node.storeType + "/" + site.node.storeId + "/" + site.node.id}",
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<webscript>
|
<webscript>
|
||||||
<shortname>Get sites</shortname>
|
<shortname>Get sites</shortname>
|
||||||
<description>Get a collection of the sites in the repository. The collection can be filtered by name and/or site preset.</description>
|
<description>Get a collection of the sites in the repository. The collection can be filtered by name and/or site preset.</description>
|
||||||
<url>/api/sites?nf={namefilter?}&spf={sitepresetfilter?}&size={pagesize?}&roles={roles?}</url>
|
<url>/api/sites?nf={namefilter?}&spf={sitepresetfilter?}&size={pagesize?}&roles={roles?}&admin={admin?}</url>
|
||||||
<format default="json">argument</format>
|
<format default="json">argument</format>
|
||||||
<authentication>user</authentication>
|
<authentication>user</authentication>
|
||||||
<transaction allow="readonly">required</transaction>
|
<transaction allow="readonly">required</transaction>
|
||||||
|
@@ -4,9 +4,20 @@ function main()
|
|||||||
var nameFilter = args["nf"];
|
var nameFilter = args["nf"];
|
||||||
var sitePreset = args["spf"];
|
var sitePreset = args["spf"];
|
||||||
var sizeString = args["size"];
|
var sizeString = args["size"];
|
||||||
|
var size = sizeString != null ? parseInt(sizeString) : -1;
|
||||||
|
var asSiteAdmin = (args["admin"] == "true");
|
||||||
|
|
||||||
// Get the list of sites
|
// Get the list of sites
|
||||||
var sites = siteService.getSites(nameFilter, sitePreset, sizeString != null ? parseInt(sizeString) : -1);
|
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.sites = sites;
|
||||||
model.roles = (args["roles"] !== null ? args["roles"] : "managers");
|
model.roles = (args["roles"] !== null ? args["roles"] : "managers");
|
||||||
}
|
}
|
||||||
|
@@ -73,6 +73,7 @@ public class SiteServiceTest extends BaseWebScriptTest
|
|||||||
private static final String USER_TWO = "SiteTestTwo";
|
private static final String USER_TWO = "SiteTestTwo";
|
||||||
private static final String USER_THREE = "SiteTestThree";
|
private static final String USER_THREE = "SiteTestThree";
|
||||||
private static final String USER_NUMERIC = "1234567890";
|
private static final String USER_NUMERIC = "1234567890";
|
||||||
|
private static final String USER_FOUR_AS_SITE_ADMIN = "SiteAdmin";
|
||||||
|
|
||||||
private static final String URL_SITES = "/api/sites";
|
private static final String URL_SITES = "/api/sites";
|
||||||
private static final String URL_SITES_QUERY = URL_SITES + "/query";
|
private static final String URL_SITES_QUERY = URL_SITES + "/query";
|
||||||
@@ -100,6 +101,10 @@ public class SiteServiceTest extends BaseWebScriptTest
|
|||||||
createUser(USER_TWO);
|
createUser(USER_TWO);
|
||||||
createUser(USER_THREE);
|
createUser(USER_THREE);
|
||||||
createUser(USER_NUMERIC);
|
createUser(USER_NUMERIC);
|
||||||
|
createUser(USER_FOUR_AS_SITE_ADMIN);
|
||||||
|
|
||||||
|
// Add user four as a member of the site admins group
|
||||||
|
authorityService.addAuthority("GROUP_SITE_ADMINISTRATORS", USER_FOUR_AS_SITE_ADMIN);
|
||||||
|
|
||||||
// Do tests as user one
|
// Do tests as user one
|
||||||
this.authenticationComponent.setCurrentUser(USER_ONE);
|
this.authenticationComponent.setCurrentUser(USER_ONE);
|
||||||
@@ -141,6 +146,7 @@ public class SiteServiceTest extends BaseWebScriptTest
|
|||||||
deleteUser(USER_TWO);
|
deleteUser(USER_TWO);
|
||||||
deleteUser(USER_THREE);
|
deleteUser(USER_THREE);
|
||||||
deleteUser(USER_NUMERIC);
|
deleteUser(USER_NUMERIC);
|
||||||
|
deleteUser(USER_FOUR_AS_SITE_ADMIN);
|
||||||
|
|
||||||
// Tidy-up any site's create during the execution of the test
|
// Tidy-up any site's create during the execution of the test
|
||||||
for (String shortName : this.createdSites)
|
for (String shortName : this.createdSites)
|
||||||
@@ -1172,4 +1178,213 @@ public class SiteServiceTest extends BaseWebScriptTest
|
|||||||
this.authorityService.deleteAuthority(testGroupName);
|
this.authorityService.deleteAuthority(testGroupName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testChangeSiteVisibilityAsSiteAdmin() throws Exception
|
||||||
|
{
|
||||||
|
// Create a site
|
||||||
|
String shortName = GUID.generate();
|
||||||
|
|
||||||
|
// Create a new site
|
||||||
|
JSONObject result = createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
|
||||||
|
assertEquals(SiteVisibility.PUBLIC.toString(), result.get("visibility"));
|
||||||
|
|
||||||
|
// try to change the site visibility as user2
|
||||||
|
this.authenticationComponent.setCurrentUser(USER_TWO);
|
||||||
|
JSONObject changeVisibility = new JSONObject();
|
||||||
|
changeVisibility.put("shortName", shortName);
|
||||||
|
changeVisibility.put("visibility", "PRIVATE");
|
||||||
|
|
||||||
|
// we should get AccessDeniedException
|
||||||
|
sendRequest(new PutRequest(URL_SITES + "/" + shortName, changeVisibility.toString(), "application/json"), 500);
|
||||||
|
SiteInfo siteInfo = siteService.getSite(shortName);
|
||||||
|
assertEquals("Site visibility should not have been changed.", SiteVisibility.PUBLIC, siteInfo.getVisibility());
|
||||||
|
|
||||||
|
// set the current user as site-admin
|
||||||
|
this.authenticationComponent.setCurrentUser(USER_FOUR_AS_SITE_ADMIN);
|
||||||
|
// Change the visibility to private
|
||||||
|
Response response = sendRequest(new PutRequest(URL_SITES + "/" + shortName, changeVisibility.toString(), "application/json"), 200);
|
||||||
|
JSONObject jsonObj = new JSONObject(response.getContentAsString());
|
||||||
|
assertEquals(SiteVisibility.PRIVATE.toString(), jsonObj.get("visibility"));
|
||||||
|
|
||||||
|
// Change the visibility to moderated. We want to test if we can find
|
||||||
|
// the private site before changing its visibility
|
||||||
|
changeVisibility.put("visibility", "MODERATED");
|
||||||
|
response = sendRequest(new PutRequest(URL_SITES + "/" + shortName, changeVisibility.toString(), "application/json"), 200);
|
||||||
|
jsonObj = new JSONObject(response.getContentAsString());
|
||||||
|
assertEquals(SiteVisibility.MODERATED.toString(), jsonObj.get("visibility"));
|
||||||
|
|
||||||
|
// Remove user4 from the site-admin group
|
||||||
|
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
|
||||||
|
authorityService.removeAuthority("GROUP_SITE_ADMINISTRATORS", USER_FOUR_AS_SITE_ADMIN);
|
||||||
|
|
||||||
|
// set the current user as site-admin
|
||||||
|
this.authenticationComponent.setCurrentUser(USER_FOUR_AS_SITE_ADMIN);
|
||||||
|
// Now that we have removed user4 from the group, try to test if he can still modify the site
|
||||||
|
changeVisibility.put("visibility", "PUBLIC");
|
||||||
|
sendRequest(new PutRequest(URL_SITES + "/" + shortName, changeVisibility.toString(), "application/json"), 500);
|
||||||
|
siteInfo = siteService.getSite(shortName);
|
||||||
|
assertEquals("Site visibility should not have been changed.", SiteVisibility.MODERATED, siteInfo.getVisibility());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testChangeMembershipRoleAsSiteAdmin() throws Exception
|
||||||
|
{
|
||||||
|
// Create a site
|
||||||
|
String shortName = GUID.generate();
|
||||||
|
createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
|
||||||
|
|
||||||
|
// Build the JSON membership object
|
||||||
|
JSONObject membership = new JSONObject();
|
||||||
|
membership.put("role", SiteModel.SITE_CONSUMER);
|
||||||
|
JSONObject person = new JSONObject();
|
||||||
|
person.put("userName", USER_TWO);
|
||||||
|
membership.put("person", person);
|
||||||
|
|
||||||
|
// Post the membership
|
||||||
|
Response response = sendRequest(new PostRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 200);
|
||||||
|
JSONObject jsonObj = new JSONObject(response.getContentAsString());
|
||||||
|
// Check the result
|
||||||
|
assertEquals(SiteModel.SITE_CONSUMER, jsonObj.get("role"));
|
||||||
|
assertEquals(USER_TWO, jsonObj.getJSONObject("authority").get("userName"));
|
||||||
|
|
||||||
|
// try to change the user role as user3
|
||||||
|
this.authenticationComponent.setCurrentUser(USER_THREE);
|
||||||
|
membership.put("role", SiteModel.SITE_COLLABORATOR);
|
||||||
|
sendRequest(new PutRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 500);
|
||||||
|
assertEquals("User's role should not have been changed.", SiteModel.SITE_CONSUMER.toString(), siteService.getMembersRole(shortName, USER_TWO));
|
||||||
|
|
||||||
|
// set the current user as site-admin
|
||||||
|
this.authenticationComponent.setCurrentUser(USER_FOUR_AS_SITE_ADMIN);
|
||||||
|
response = sendRequest(new PutRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 200);
|
||||||
|
jsonObj = new JSONObject(response.getContentAsString());
|
||||||
|
// Check the result
|
||||||
|
assertEquals(SiteModel.SITE_COLLABORATOR, jsonObj.get("role"));
|
||||||
|
assertEquals(USER_TWO, jsonObj.getJSONObject("authority").get("userName"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDeleteMembershipAsSiteAdmin() throws Exception
|
||||||
|
{
|
||||||
|
// Create a site
|
||||||
|
String shortName = GUID.generate();
|
||||||
|
createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
|
||||||
|
|
||||||
|
// Build the JSON membership object
|
||||||
|
JSONObject membership = new JSONObject();
|
||||||
|
membership.put("role", SiteModel.SITE_CONSUMER);
|
||||||
|
JSONObject person = new JSONObject();
|
||||||
|
person.put("userName", USER_TWO);
|
||||||
|
membership.put("person", person);
|
||||||
|
|
||||||
|
// Post the membership
|
||||||
|
Response response = sendRequest(new PostRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 200);
|
||||||
|
JSONObject jsonObj = new JSONObject(response.getContentAsString());
|
||||||
|
// Check the result
|
||||||
|
assertEquals(SiteModel.SITE_CONSUMER, jsonObj.get("role"));
|
||||||
|
assertEquals(USER_TWO, jsonObj.getJSONObject("authority").get("userName"));
|
||||||
|
|
||||||
|
// try to delete user2 from the site
|
||||||
|
this.authenticationComponent.setCurrentUser(USER_THREE);
|
||||||
|
sendRequest(new DeleteRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "/" + USER_TWO), 500);
|
||||||
|
assertTrue(USER_THREE + " doesn’t have permission to delete users from the site", siteService.isMember(shortName, USER_TWO));
|
||||||
|
|
||||||
|
// set the current user as site-admin
|
||||||
|
this.authenticationComponent.setCurrentUser(USER_FOUR_AS_SITE_ADMIN);
|
||||||
|
sendRequest(new DeleteRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "/" + USER_TWO), 200);
|
||||||
|
assertFalse(siteService.isMember(shortName, USER_TWO));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDeleteSiteAsSiteAdmin() throws Exception
|
||||||
|
{
|
||||||
|
// Create a site
|
||||||
|
String shortName = GUID.generate();
|
||||||
|
createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
|
||||||
|
// Get the site
|
||||||
|
sendRequest(new GetRequest(URL_SITES + "/" + shortName), 200);
|
||||||
|
|
||||||
|
// try to delete the site
|
||||||
|
this.authenticationComponent.setCurrentUser(USER_THREE);
|
||||||
|
// Delete the site
|
||||||
|
sendRequest(new DeleteRequest(URL_SITES + "/" + shortName), 500);
|
||||||
|
// Get the site
|
||||||
|
Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName), 200);
|
||||||
|
JSONObject jsonObj = new JSONObject(response.getContentAsString());
|
||||||
|
assertEquals(shortName, jsonObj.get("shortName"));
|
||||||
|
|
||||||
|
// set the current user as site-admin
|
||||||
|
this.authenticationComponent.setCurrentUser(USER_FOUR_AS_SITE_ADMIN);
|
||||||
|
// Delete the site
|
||||||
|
sendRequest(new DeleteRequest(URL_SITES + "/" + shortName), 200);
|
||||||
|
sendRequest(new GetRequest(URL_SITES + "/" + shortName), 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetAllSitesAsSiteAdmin() throws Exception
|
||||||
|
{
|
||||||
|
String user1PublicSiteName = GUID.generate();
|
||||||
|
String user1ModeratedSiteName = GUID.generate();
|
||||||
|
String user1PrivateSiteName = GUID.generate();
|
||||||
|
|
||||||
|
String user2PrivateSiteName = GUID.generate();
|
||||||
|
|
||||||
|
// USER_ONE public site
|
||||||
|
JSONObject result = createSite("myPreset", user1PublicSiteName, "u1PublicSite", "myDescription",
|
||||||
|
SiteVisibility.PUBLIC, 200);
|
||||||
|
assertEquals(SiteVisibility.PUBLIC.toString(), result.get("visibility"));
|
||||||
|
|
||||||
|
// USER_ONE moderated site
|
||||||
|
result = createSite("myPreset", user1ModeratedSiteName, "u1ModeratedSite", "myDescription",
|
||||||
|
SiteVisibility.MODERATED, 200);
|
||||||
|
assertEquals(SiteVisibility.MODERATED.toString(), result.get("visibility"));
|
||||||
|
|
||||||
|
// USER_ONE private site
|
||||||
|
result = createSite("myPreset", user1PrivateSiteName, "u1PrivateSite", "myDescription", SiteVisibility.PRIVATE,
|
||||||
|
200);
|
||||||
|
assertEquals(SiteVisibility.PRIVATE.toString(), result.get("visibility"));
|
||||||
|
|
||||||
|
this.authenticationComponent.setCurrentUser(USER_TWO);
|
||||||
|
// USER_TWO private site
|
||||||
|
result = createSite("myPreset", user2PrivateSiteName, "u2PrivateSite", "myDescription", SiteVisibility.PRIVATE, 200);
|
||||||
|
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));
|
||||||
|
|
||||||
|
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 = 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());
|
||||||
|
assertEquals("SiteAdmin must have access to the same sites as the super Admin.", siteAdminGetSitesSize,
|
||||||
|
jsonArray.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
if (SiteVisibility.PRIVATE.equals(SiteVisibility.valueOf(visibility)))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user