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:
@@ -1,62 +0,0 @@
|
|||||||
<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/lib/wiki.lib.js">
|
|
||||||
/**
|
|
||||||
* Deletes le page.
|
|
||||||
*
|
|
||||||
* @method DELETE
|
|
||||||
* @param uri {string} /slingshot/wiki/page/{siteid}/{pageTitle}
|
|
||||||
*/
|
|
||||||
deleteEvent();
|
|
||||||
|
|
||||||
function deleteEvent()
|
|
||||||
{
|
|
||||||
var params = getTemplateArgs(["siteId", "pageTitle"]);
|
|
||||||
if (params === null)
|
|
||||||
{
|
|
||||||
status.setCode(status.STATUS_BAD_REQUEST, "Correct parameters not supplied.");
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
|
|
||||||
var site = siteService.getSite(params.siteId);
|
|
||||||
if (site === null)
|
|
||||||
{
|
|
||||||
status.setCode(status.STATUS_NOT_FOUND, "Could not find site.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var wiki = getWikiContainer(site);
|
|
||||||
if (wiki === null)
|
|
||||||
{
|
|
||||||
status.setCode(status.STATUS_NOT_FOUND, "Could not find wiki container.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var page = wiki.childByNamePath(params.pageTitle);
|
|
||||||
if (page === null)
|
|
||||||
{
|
|
||||||
status.setCode(status.STATUS_NOT_FOUND, "Could not find specified page.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var whatPage = page.name;
|
|
||||||
|
|
||||||
if (!page.remove())
|
|
||||||
{
|
|
||||||
status.setCode(status.STATUS_INTERNAL_SERVER_ERROR, "Failed to delete page");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Log to page deletion to activity service
|
|
||||||
var data =
|
|
||||||
{
|
|
||||||
title: params.pageTitle.replace(/_/g, " "),
|
|
||||||
page: decodeURIComponent(args["page"])
|
|
||||||
}
|
|
||||||
|
|
||||||
activities.postActivity("org.alfresco.wiki.page-deleted", params.siteId, "wiki", jsonUtils.toJSONString(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Success
|
|
||||||
status.setCode(status.STATUS_NO_CONTENT); // Nothing to do here yet
|
|
||||||
return;
|
|
||||||
}
|
|
@@ -1547,6 +1547,12 @@
|
|||||||
parent="abstractWikiWebScript">
|
parent="abstractWikiWebScript">
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<!-- Deletes a wiki page -->
|
||||||
|
<bean id="webscript.org.alfresco.slingshot.wiki.page.delete"
|
||||||
|
class="org.alfresco.repo.web.scripts.wiki.WikiPageDelete"
|
||||||
|
parent="abstractWikiWebScript">
|
||||||
|
</bean>
|
||||||
|
|
||||||
<!-- Lists the Wiki Pages for a site -->
|
<!-- Lists the Wiki Pages for a site -->
|
||||||
<bean id="webscript.org.alfresco.slingshot.wiki.pagelist.get"
|
<bean id="webscript.org.alfresco.slingshot.wiki.pagelist.get"
|
||||||
class="org.alfresco.repo.web.scripts.wiki.WikiPageListGet"
|
class="org.alfresco.repo.web.scripts.wiki.WikiPageListGet"
|
||||||
|
@@ -144,7 +144,7 @@ public abstract class AbstractWikiWebScript extends DeclarativeWebScript
|
|||||||
/**
|
/**
|
||||||
* Generates an activity entry for the link
|
* 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)
|
WebScriptRequest req, JSONObject json)
|
||||||
{
|
{
|
||||||
// What page is this for?
|
// What page is this for?
|
||||||
@@ -169,8 +169,8 @@ public abstract class AbstractWikiWebScript extends DeclarativeWebScript
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
JSONObject activity = new JSONObject();
|
JSONObject activity = new JSONObject();
|
||||||
activity.put("title", link.getTitle());
|
activity.put("title", wikiPage.getTitle());
|
||||||
activity.put("page", page + "?title=" + link.getTitle());
|
activity.put("page", page + "?title=" + wikiPage.getSystemName());
|
||||||
|
|
||||||
activityService.postActivity(
|
activityService.postActivity(
|
||||||
"org.alfresco.wiki.page-" + event,
|
"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";
|
String message = "The Wiki Page could not be found";
|
||||||
status.setCode(Status.STATUS_NOT_FOUND);
|
status.setCode(Status.STATUS_NOT_FOUND);
|
||||||
status.setMessage(message);
|
status.setMessage(message);
|
||||||
|
status.setRedirect(true);
|
||||||
|
|
||||||
// Grab the container, used in permissions checking
|
// Grab the container, used in permissions checking
|
||||||
NodeRef container = siteService.getContainer(
|
NodeRef container = siteService.getContainer(
|
||||||
@@ -68,9 +69,7 @@ public class WikiPageGet extends AbstractWikiWebScript
|
|||||||
model.put("error", message);
|
model.put("error", message);
|
||||||
|
|
||||||
// Bail out
|
// Bail out
|
||||||
Map<String, Object> result = new HashMap<String, Object>();
|
return model;
|
||||||
result.put("result", model);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -228,6 +228,11 @@ public class WikiRestApiTest extends BaseWebScriptTest
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
else if(expectedStatus == Status.STATUS_NOT_FOUND)
|
||||||
|
{
|
||||||
|
JSONObject result = new JSONObject(response.getContentAsString());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -372,7 +377,6 @@ public class WikiRestApiTest extends BaseWebScriptTest
|
|||||||
// Won't be there to start with
|
// Won't be there to start with
|
||||||
page = getPage(PAGE_TITLE_ONE, Status.STATUS_NOT_FOUND);
|
page = getPage(PAGE_TITLE_ONE, Status.STATUS_NOT_FOUND);
|
||||||
|
|
||||||
|
|
||||||
// Create
|
// Create
|
||||||
page = createOrUpdatePage(PAGE_TITLE_ONE, PAGE_CONTENTS_ONE, null, Status.STATUS_OK);
|
page = createOrUpdatePage(PAGE_TITLE_ONE, PAGE_CONTENTS_ONE, null, Status.STATUS_OK);
|
||||||
name = PAGE_TITLE_ONE.replace(' ', '_');
|
name = PAGE_TITLE_ONE.replace(' ', '_');
|
||||||
@@ -450,6 +454,13 @@ public class WikiRestApiTest extends BaseWebScriptTest
|
|||||||
// Fetch, will have gone
|
// Fetch, will have gone
|
||||||
page = getPage(name, Status.STATUS_NOT_FOUND);
|
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
|
// Can't delete again
|
||||||
deletePage(name, Status.STATUS_NOT_FOUND);
|
deletePage(name, Status.STATUS_NOT_FOUND);
|
||||||
|
Reference in New Issue
Block a user