Search in sources :

Example 11 with PutRequest

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());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) JSONObject(org.json.JSONObject) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)

Example 12 with PutRequest

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");
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)

Example 13 with PutRequest

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);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONTokener(org.json.JSONTokener) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 14 with PutRequest

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");
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)

Example 15 with PutRequest

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");
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)

Aggregations

PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)41 JSONObject (org.json.JSONObject)39 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)37 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)17 JSONArray (org.json.JSONArray)13 PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)10 JSONTokener (org.json.JSONTokener)8 NodeRef (org.alfresco.service.cmr.repository.NodeRef)5 JSONStringer (org.json.JSONStringer)5 IOException (java.io.IOException)3 Serializable (java.io.Serializable)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)3 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)3 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)3 QName (org.alfresco.service.namespace.QName)3 JSONException (org.json.JSONException)3 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)3 ArrayList (java.util.ArrayList)1