use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.
the class SiteServiceTest method testChangeSiteVisibilityAsSiteAdmin.
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());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.
the class DiscussionRestApiTest method updateComment.
private JSONObject updateComment(NodeRef nodeRef, String title, String content, int expectedStatus) throws Exception {
JSONObject comment = new JSONObject();
comment.put("title", title);
comment.put("content", content);
Response response = sendRequest(new PutRequest(getPostUrl(nodeRef), comment.toString(), "application/json"), expectedStatus);
if (expectedStatus != Status.STATUS_OK) {
return null;
}
// logger.debug("Comment updated: " + response.getContentAsString());
JSONObject result = new JSONObject(response.getContentAsString());
return result.getJSONObject("item");
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.
the class FacetRestApiTest method testNonSearchAdminUserCannotCreateUpdateSolrFacets.
public void testNonSearchAdminUserCannotCreateUpdateSolrFacets() throws Exception {
// Create a filter
final JSONObject filter = new JSONObject();
final String filterName = "filter" + System.currentTimeMillis();
filters.add(filterName);
filter.put("filterID", filterName);
filter.put("facetQName", "cm:test1");
filter.put("displayName", "facet-menu.facet.test1");
filter.put("displayControl", "alfresco/search/FacetFilters/test1");
filter.put("maxFilters", 5);
filter.put("hitThreshold", 1);
filter.put("minFilterValueLength", 4);
filter.put("sortBy", "ALPHABETICALLY");
// Non-Search-Admin tries to create a filter
AuthenticationUtil.runAs(new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
// Post the filter
sendRequest(new PostRequest(POST_FACETS_URL, filter.toString(), "application/json"), 403);
return null;
}
}, NON_SEARCH_ADMIN_USER);
// Search-Admin creates a filter
AuthenticationUtil.runAs(new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
// Post the filter
sendRequest(new PostRequest(POST_FACETS_URL, filter.toString(), "application/json"), 200);
return null;
}
}, SEARCH_ADMIN_USER);
// Non-Search-Admin tries to modify the filter
AuthenticationUtil.runAs(new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
Response response = sendRequest(new GetRequest(GET_FACETS_URL + "/" + filterName), 200);
JSONObject jsonRsp = new JSONObject(new JSONTokener(response.getContentAsString()));
assertEquals(filterName, jsonRsp.getString("filterID"));
assertEquals(5, jsonRsp.getInt("maxFilters"));
// Now change the maxFilters value and try to update
jsonRsp.put("maxFilters", 10);
sendRequest(new PutRequest(PUT_FACETS_URL, jsonRsp.toString(), "application/json"), 403);
return null;
}
}, NON_SEARCH_ADMIN_USER);
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.
the class BlogServiceTest method updatePost.
private JSONObject updatePost(String name, String title, String content, String[] tags, boolean isDraft, int expectedStatus) throws Exception {
JSONObject post = getRequestObject(title, content, tags, isDraft);
Response response = sendRequest(new PutRequest(URL_BLOG_POST + name, post.toString(), "application/json"), expectedStatus);
if (expectedStatus != 200) {
return null;
}
JSONObject result = new JSONObject(response.getContentAsString());
return result.getJSONObject("item");
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.
the class BlogServiceTest method updateComment.
private JSONObject updateComment(String nodeRef, String title, String content, int expectedStatus) throws Exception {
JSONObject comment = new JSONObject();
comment.put("title", title);
comment.put("content", content);
Response response = sendRequest(new PutRequest(getCommentUrl(nodeRef), comment.toString(), "application/json"), expectedStatus);
if (expectedStatus != 200) {
return null;
}
// logger.debug("Comment updated: " + response.getContentAsString());
JSONObject result = new JSONObject(response.getContentAsString());
return result.getJSONObject("item");
}
Aggregations