mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
ALF-9923 Wiki webscript tweaks to ensure the correct 404 template is used, and tests for it
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30090 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -144,7 +144,7 @@ public abstract class AbstractWikiWebScript extends DeclarativeWebScript
|
||||
/**
|
||||
* Generates an activity entry for the link
|
||||
*/
|
||||
protected void addActivityEntry(String event, LinkInfo link, SiteInfo site,
|
||||
protected void addActivityEntry(String event, WikiPageInfo wikiPage, SiteInfo site,
|
||||
WebScriptRequest req, JSONObject json)
|
||||
{
|
||||
// What page is this for?
|
||||
@@ -169,8 +169,8 @@ public abstract class AbstractWikiWebScript extends DeclarativeWebScript
|
||||
try
|
||||
{
|
||||
JSONObject activity = new JSONObject();
|
||||
activity.put("title", link.getTitle());
|
||||
activity.put("page", page + "?title=" + link.getTitle());
|
||||
activity.put("title", wikiPage.getTitle());
|
||||
activity.put("page", page + "?title=" + wikiPage.getSystemName());
|
||||
|
||||
activityService.postActivity(
|
||||
"org.alfresco.wiki.page-" + event,
|
||||
|
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.wiki;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.wiki.WikiPageInfo;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
* This class is the controller for the wiki page listing page.delete webscript.
|
||||
*
|
||||
* @author Nick Burch
|
||||
* @since 4.0
|
||||
*/
|
||||
public class WikiPageDelete extends AbstractWikiWebScript
|
||||
{
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(SiteInfo site, String pageName,
|
||||
WebScriptRequest req, JSONObject json, Status status, Cache cache) {
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
|
||||
// Try to find the page
|
||||
WikiPageInfo page = wikiService.getWikiPage(site.getShortName(), pageName);
|
||||
if(page == null)
|
||||
{
|
||||
String message = "The Wiki Page could not be found";
|
||||
throw new WebScriptException(Status.STATUS_NOT_FOUND, message);
|
||||
}
|
||||
|
||||
// Have the page deleted
|
||||
wikiService.deleteWikiPage(page);
|
||||
|
||||
// Generate an activity for this
|
||||
addActivityEntry("deleted", page, site, req, json);
|
||||
|
||||
// Mark it as gone
|
||||
status.setCode(Status.STATUS_NO_CONTENT);
|
||||
return model;
|
||||
}
|
||||
}
|
@@ -59,6 +59,7 @@ public class WikiPageGet extends AbstractWikiWebScript
|
||||
String message = "The Wiki Page could not be found";
|
||||
status.setCode(Status.STATUS_NOT_FOUND);
|
||||
status.setMessage(message);
|
||||
status.setRedirect(true);
|
||||
|
||||
// Grab the container, used in permissions checking
|
||||
NodeRef container = siteService.getContainer(
|
||||
@@ -68,9 +69,7 @@ public class WikiPageGet extends AbstractWikiWebScript
|
||||
model.put("error", message);
|
||||
|
||||
// Bail out
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("result", model);
|
||||
return result;
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -228,6 +228,11 @@ public class WikiRestApiTest extends BaseWebScriptTest
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else if(expectedStatus == Status.STATUS_NOT_FOUND)
|
||||
{
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
@@ -372,7 +377,6 @@ public class WikiRestApiTest extends BaseWebScriptTest
|
||||
// Won't be there to start with
|
||||
page = getPage(PAGE_TITLE_ONE, Status.STATUS_NOT_FOUND);
|
||||
|
||||
|
||||
// Create
|
||||
page = createOrUpdatePage(PAGE_TITLE_ONE, PAGE_CONTENTS_ONE, null, Status.STATUS_OK);
|
||||
name = PAGE_TITLE_ONE.replace(' ', '_');
|
||||
@@ -450,6 +454,13 @@ public class WikiRestApiTest extends BaseWebScriptTest
|
||||
// Fetch, will have gone
|
||||
page = getPage(name, Status.STATUS_NOT_FOUND);
|
||||
|
||||
// On a page that isn't there, you do get permissions
|
||||
assertEquals(true, page.has("permissions"));
|
||||
permissions = page.getJSONObject("permissions");
|
||||
assertEquals(true, permissions.getBoolean("create"));
|
||||
assertEquals(true, permissions.getBoolean("edit"));
|
||||
assertEquals(false, permissions.has("delete")); // No delete for non existing page
|
||||
|
||||
|
||||
// Can't delete again
|
||||
deletePage(name, Status.STATUS_NOT_FOUND);
|
||||
|
Reference in New Issue
Block a user