Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Wl-1445 Fix for site replacement now working. #2

Merged
merged 1 commit into from

2 participants

@buckett
Owner

The request which pulled the site Id out of the session got lost in the refactor.

@buckett buckett Wl-1445 Fix for site replacement now working.
The request which pulled the site Id out of the session got lost in the refactor.
e7bc4ba
@ColinHebert ColinHebert merged commit 328d6e6 into master
@ColinHebert ColinHebert deleted the WL-1445-2 branch
@ColinHebert

Merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 22, 2013
  1. @buckett

    Wl-1445 Fix for site replacement now working.

    buckett authored
    The request which pulled the site Id out of the session got lost in the refactor.
This page is out of date. Refresh to see the latest.
View
35 hierarchy-tool/tool/src/java/org/sakaiproject/hierarchy/tool/vm/ManagerController.java
@@ -10,6 +10,7 @@
import javax.servlet.http.HttpServletRequest;
import org.sakaiproject.component.api.ServerConfigurationService;
+import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.exception.PermissionException;
import org.sakaiproject.hierarchy.api.PortalHierarchyService;
import org.sakaiproject.hierarchy.api.PortalNodeComparator;
@@ -17,6 +18,7 @@
import org.sakaiproject.hierarchy.api.model.PortalNodeRedirect;
import org.sakaiproject.hierarchy.api.model.PortalNodeSite;
import org.sakaiproject.site.api.Site;
+import org.sakaiproject.site.api.SiteService;
import org.sakaiproject.sitemanage.api.SiteHelper;
import org.sakaiproject.tool.api.Session;
import org.sakaiproject.tool.api.SessionManager;
@@ -49,6 +51,7 @@
private PortalHierarchyService portalHierarchyService;
private ServerConfigurationService serverConfigurationService;
private VelocityControllerUtils velocityControllerUtils;
+ private SiteService siteService;
@Autowired
public void setSessionManager(SessionManager sessionManager) {
@@ -70,6 +73,11 @@ public void setVelocityControllerUtils(VelocityControllerUtils velocityControlle
this.velocityControllerUtils = velocityControllerUtils;
}
+ @Autowired
+ public void setSiteService(SiteService siteService) {
+ this.siteService = siteService;
+ }
+
@ModelAttribute("redirect-add")
public AddRedirectCommand getAddRedirectCommand() {
return new AddRedirectCommand();
@@ -256,7 +264,7 @@ public String deleteRedirect(@ModelAttribute("redirect-remove") DeleteRedirectCo
public ModelAndView changeSite(HttpServletRequest request) {
ToolSession toolSession = sessionManager.getCurrentToolSession();
- toolSession.setAttribute(Tool.HELPER_DONE_URL, buildUrl(request, "/site/save").toString());
+ toolSession.setAttribute(Tool.HELPER_DONE_URL, buildUrl(request, "/site/edit").toString());
toolSession.setAttribute(SiteHelper.SITE_PICKER_PERMISSION,
org.sakaiproject.site.api.SiteService.SelectionType.UPDATE);
@@ -267,11 +275,34 @@ public ModelAndView changeSite(HttpServletRequest request) {
return new ModelAndView(redirectView);
}
+ @RequestMapping(value = "/site/edit", method = RequestMethod.GET)
+ public ModelAndView editSite(HttpServletRequest request, Model model) {
+ ToolSession toolSession = sessionManager.getCurrentToolSession();
+ PortalNodeSite node = portalHierarchyService.getCurrentPortalNode();
+
+ model.addAttribute("old", createSiteMap(node.getSite()));
+ // Check to see if the user has come back from helper.
+ Object siteAttribute = toolSession.getAttribute(SiteHelper.SITE_PICKER_SITE_ID);
+ toolSession.removeAttribute(SiteHelper.SITE_PICKER_SITE_ID);
+ if ( siteAttribute instanceof String)
+ {
+ try
+ {
+ Site site = siteService.getSite((String)siteAttribute);
+ model.addAttribute("new", createSiteMap(site));
+ return new ModelAndView( "replace", model.asMap());
+ } catch (IdUnusedException iue) {
+ // Bail out.
+ }
+ }
+ return new ModelAndView("show", model.asMap());
+ }
+
// We throw an exception (MissingServletRequestParameterException) when
// siteId isn't present
// This is a GET as when returning from the helper you get the data back on
// a redirect.
- @RequestMapping(value = "/site/save", method = RequestMethod.GET)
+ @RequestMapping(value = "/site/save", method = RequestMethod.POST)
public String saveSite(HttpServletRequest request, @RequestParam(REQUEST_SITE) String siteId) {
PortalNode node = portalHierarchyService.getCurrentPortalNode();
View
29 hierarchy-tool/tool/src/test/org/sakaiproject/hierarchy/tool/vm/ManageControllerTest.java
@@ -25,12 +25,14 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.sakaiproject.component.api.ServerConfigurationService;
+import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.exception.PermissionException;
import org.sakaiproject.hierarchy.api.PortalHierarchyService;
import org.sakaiproject.hierarchy.api.model.PortalNode;
import org.sakaiproject.hierarchy.api.model.PortalNodeRedirect;
import org.sakaiproject.hierarchy.api.model.PortalNodeSite;
import org.sakaiproject.site.api.Site;
+import org.sakaiproject.site.api.SiteService;
import org.sakaiproject.sitemanage.api.SiteHelper;
import org.sakaiproject.tool.api.Session;
import org.sakaiproject.tool.api.SessionManager;
@@ -71,6 +73,9 @@
@Autowired
private ServerConfigurationService serverConfigurationService;
+ @Autowired
+ private SiteService siteService;
+
private Session session;
@Before
@@ -250,7 +255,7 @@ public void testChangeSiteHelper() throws ServletException, IOException {
@Test
public void testSaveSite() throws ServletException, IOException, PermissionException {
- MockHttpServletRequest request = UnitTestUtilities.newRequest("GET", "/site/save");
+ MockHttpServletRequest request = UnitTestUtilities.newRequest("POST", "/site/save");
MockHttpServletResponse response = new MockHttpServletResponse();
request.setParameter(ManagerController.REQUEST_SITE, "new-site-id");
servlet.service(request, response);
@@ -263,7 +268,7 @@ public void testSaveSite() throws ServletException, IOException, PermissionExcep
// exception.
@ExpectedException(MissingServletRequestParameterException.class)
public void testSaveSiteBad() throws ServletException, IOException, PermissionException {
- MockHttpServletRequest request = UnitTestUtilities.newRequest("GET", "/site/save");
+ MockHttpServletRequest request = UnitTestUtilities.newRequest("POST", "/site/save");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
}
@@ -295,4 +300,24 @@ public void testPaste() throws PermissionException, ServletException, IOExceptio
verify(portalHierarchyService).moveNode("other-node-id", "id");
}
+
+ @Test
+ public void testEditSite() throws ServletException, IOException, IdUnusedException {
+ // Need a tool session for this.
+ ToolSession toolSession = mock(ToolSession.class);
+ when(sessionManager.getCurrentToolSession()).thenReturn(toolSession);
+ when(toolSession.getAttribute(SiteHelper.SITE_PICKER_SITE_ID)).thenReturn("new-site-id");
+ Site newSite = mock(Site.class);
+ when(newSite.getId()).thenReturn("new-site-id");
+ when(newSite.getTitle()).thenReturn("New Site Title");
+ when(newSite.getShortDescription()).thenReturn("New Short Description");
+ when(siteService.getSite("new-site-id")).thenReturn(newSite);
+
+ MockHttpServletRequest request = UnitTestUtilities.newRequest("GET", "/site/edit");
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ servlet.service(request, response);
+
+ verify(siteService).getSite("new-site-id");
+ assertEquals(200, response.getStatus());
+ }
}
View
5 hierarchy-tool/tool/src/webapp/WEB-INF/velocity/replace.vm
@@ -7,8 +7,7 @@ $old.siteTitle
<p>with the new site</p>
$new.siteTitle
-<form method="post" action="${rootUrl}">
-<input type="hidden" name="_action" value="act_savesite"/>
+<form method="post" action="${rootUrl}/site/save">
<input type="hidden" name="_site" value="$!{new.siteId}" />
<input type="submit" value="#springMessage("button.replace")"/>
</form>
@@ -18,4 +17,4 @@ $new.siteTitle
#chef_portletContentEnd()
#chef_portletContainerEnd()
-#chef_end()
+#chef_end()
Something went wrong with that request. Please try again.