From 8d2f707f486b2523e66e3b37e878e949b94c17a8 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 18 May 2017 11:51:32 +1200 Subject: [PATCH] FIX Ensure after uploading document you are redirected back to the document set --- code/cms/DMSDocumentAddController.php | 8 ++++++-- tests/cms/DMSDocumentAddControllerTest.php | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/code/cms/DMSDocumentAddController.php b/code/cms/DMSDocumentAddController.php index 799e1be..af77a92 100644 --- a/code/cms/DMSDocumentAddController.php +++ b/code/cms/DMSDocumentAddController.php @@ -178,7 +178,7 @@ class DMSDocumentAddController extends LeftAndMain /** * Returns the link to be used to return the user after uploading a document. If a document set ID (dsid) is present - * then it will be redirected back to the page that owns the document set. @todo redirect back to the document set + * then it will be redirected back to that document set in a page. * * If no document set ID is present then we assume that it has been added from the model admin, so redirect back to * that instead. @@ -192,7 +192,11 @@ class DMSDocumentAddController extends LeftAndMain $modelAdmin->init(); return $modelAdmin->Link(); } - return Controller::join_links(singleton('CMSPagesController')->Link(), 'edit/show', $this->currentPageID()); + return Controller::join_links( + singleton('CMSPagesController')->Link(), + 'edit/EditForm/field/Document%20Sets/item', + $this->getRequest()->getVar('dsid') + ); } public function documentautocomplete() diff --git a/tests/cms/DMSDocumentAddControllerTest.php b/tests/cms/DMSDocumentAddControllerTest.php index fadee27..ff3575b 100644 --- a/tests/cms/DMSDocumentAddControllerTest.php +++ b/tests/cms/DMSDocumentAddControllerTest.php @@ -35,4 +35,20 @@ class DMSDocumentAddControllerTest extends FunctionalTest Config::inst()->update('DMSDocumentAddController', 'allowed_extensions', array('php', 'php5')); $this->assertSame(array('jpg', 'gif', 'php', 'php5'), $controller->getAllowedExtensions()); } + + /** + * Test that the back link will be the document set that a file is uploaded into if relevant, otherwise the model + * admin that it was uploaded from + */ + public function testBacklink() + { + $controller = new DMSDocumentAddController; + $controller->init(); + $this->assertContains('admin/documents', $controller->Backlink()); + + $request = new SS_HTTPRequest('GET', '/', array('dsid' => 123)); + $controller->setRequest($request); + $this->assertContains('EditForm', $controller->Backlink()); + $this->assertContains('123', $controller->Backlink()); + } }