diff --git a/code/controller/AssetAdmin.php b/code/controller/AssetAdmin.php index ca671a5c..b23388a8 100755 --- a/code/controller/AssetAdmin.php +++ b/code/controller/AssetAdmin.php @@ -358,7 +358,7 @@ JS return $record->ID; } else if($this->isAjax()) { $form = $this->getEditForm($record->ID); - return $form->formHtmlContent(); + return $form->forTemplate(); } else { return $this->redirect(Controller::join_links($this->Link('show'), $record->ID)); } diff --git a/code/controller/CMSMain.php b/code/controller/CMSMain.php index 8293ec21..5de891fc 100755 --- a/code/controller/CMSMain.php +++ b/code/controller/CMSMain.php @@ -345,7 +345,7 @@ JS; $this->response->addHeader('X-Status', _t('LeftAndMain.SAVEDUP')); - return $form->formHtmlContent(); + return $form->forTemplate(); } /** * Get a database record to be managed by the CMS @@ -438,14 +438,6 @@ JS; $actions = $record->getCMSActions(); } - // Add a default or custom validator. - // @todo Currently the default Validator.js implementation - // adds javascript to the document body, meaning it won't - // be included properly if the associated fields are loaded - // through ajax. This means only serverside validation - // will kick in for pages+validation loaded through ajax. - // This will be solved by using less obtrusive javascript validation - // in the future, see http://open.silverstripe.com/ticket/2915 and http://open.silverstripe.com/ticket/3386 if($record->hasMethod('getCMSValidator')) { $validator = $record->getCMSValidator(); } else { @@ -464,7 +456,7 @@ JS; $form->addExtraClass('cms-edit-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // TODO Can't merge $FormAttributes in template at the moment - $form->addExtraClass('cms-content center ss-tabset'); + $form->addExtraClass('cms-content center ss-tabset ' . $this->BaseCSSClasses()); if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); if(!$record->canEdit() || $record->IsDeletedFromStage) { @@ -505,6 +497,19 @@ JS; return $form; } + + public function currentPageID() { + $id = parent::currentPageID(); + + // Fall back to homepage record + if(!$id) { + $homepageSegment = RootURLController::get_homepage_link(); + $homepageRecord = DataObject::get_one('SiteTree', sprintf('"URLSegment" = \'%s\'', $homepageSegment)); + if($homepageRecord) $id = $homepageRecord->ID; + } + + return $id; + } //------------------------------------------------------------------------------------------// // Data saving handlers @@ -578,7 +583,7 @@ JS; $form = $this->getEditForm($record->ID); } - return $form->formHtmlContent(); + return $form->forTemplate(); } @@ -615,7 +620,7 @@ JS; return $record->ID; } else if(Director::is_ajax()) { $form = $this->getEditForm($record->ID); - return $form->formHtmlContent(); + return $form->forTemplate(); } else { return $this->redirect(Controller::join_links($this->Link('show'), $record->ID)); } @@ -757,7 +762,7 @@ JS; $form = $this->getEditForm($record->ID); - return $form->formHtmlContent(); + return $form->forTemplate(); } /** @@ -791,7 +796,7 @@ JS; 'Live', "\"SiteTree_Live\".\"ID\" = $recordID" ); - return ($liveRecord) ? $form->formHtmlContent() : ""; + return ($liveRecord) ? $form->forTemplate() : ""; } else { $this->redirectBack(); } @@ -988,7 +993,7 @@ JS; $form = $this->getEditForm($record->ID); - return $form->formHtmlContent(); + return $form->forTemplate(); } function publish($data, $form) { @@ -1013,7 +1018,7 @@ JS; // Reload form, data and actions might have changed $form = $this->getEditForm($record->ID); - return $form->formHtmlContent(); + return $form->forTemplate(); } function performRollback($id, $version) { @@ -1187,7 +1192,7 @@ JS; } if($this->isAjax()) { - return $form->formHtmlContent(); + return $form->forTemplate(); } else { $templateData = $this->customise(array( "EditForm" => $form @@ -1426,7 +1431,7 @@ JS; // Reload form, data and actions might have changed $form = $this->getEditForm($restoredPage->ID); - return $form->formHtmlContent(); + return $form->forTemplate(); } function duplicate($request) { @@ -1450,7 +1455,7 @@ JS; // Reload form, data and actions might have changed $form = $this->getEditForm($newPage->ID); - return $form->formHtmlContent(); + return $form->forTemplate(); } else { user_error("CMSMain::duplicate() Bad ID: '$id'", E_USER_WARNING); } @@ -1471,7 +1476,7 @@ JS; // Reload form, data and actions might have changed $form = $this->getEditForm($newPage->ID); - return $form->formHtmlContent(); + return $form->forTemplate(); } else { user_error("CMSMain::duplicate() Bad ID: '$id'", E_USER_WARNING); } diff --git a/code/controller/CMSPagesController.php b/code/controller/CMSPagesController.php index 98a6f74e..db7e66b0 100644 --- a/code/controller/CMSPagesController.php +++ b/code/controller/CMSPagesController.php @@ -13,8 +13,21 @@ class CMSPagesController extends CMSMain { } function show($request) { - $c = new CMSPageEditController(); - return $this->redirect(Controller::join_links($c->Link('show'), $request->param('ID'))); + if($request->param('ID')) { + $c = new CMSPageEditController(); + return $this->redirect(Controller::join_links($c->Link('show'), $request->param('ID'))); + } else { + return parent::show($request); + } + } + + function Link($action = null) { + // Special case: All show links should redirect to the page edit interface instead (mostly from tree nodes) + if(preg_match('/^show/', $action)) { + return singleton('CMSPageEditController')->Link($action); + } else { + return parent::Link($action); + } } } \ No newline at end of file diff --git a/code/controller/CMSSettingsController.php b/code/controller/CMSSettingsController.php new file mode 100644 index 00000000..93bcac8f --- /dev/null +++ b/code/controller/CMSSettingsController.php @@ -0,0 +1,13 @@ +RootForm(); + } + +} \ No newline at end of file diff --git a/code/controller/ContentController.php b/code/controller/ContentController.php index ea3f2f18..de7c3652 100755 --- a/code/controller/ContentController.php +++ b/code/controller/ContentController.php @@ -120,6 +120,12 @@ class ContentController extends Controller { return Security::permissionFailure($this, sprintf($message, Controller::join_links($link, "?stage=Live"))); } } + + // Redirect to admin UI if user is logged in + if($this->URLSegment != 'Security' && Permission::check('CMS_ACCESS_CMSMain') && !$this->request->getVar('cms-preview-disabled')) { + $cmsController = singleton('CMSPageEditController'); + return Director::redirect(Controller::join_links($cmsController->Link('show'), $this->dataRecord->ID, '?cms-preview-expanded=1')); + } // Use theme from the site config if(($config = SiteConfig::current_site_config()) && $config->Theme) { diff --git a/code/model/SiteTree.php b/code/model/SiteTree.php index dd57482a..d2b61b8c 100755 --- a/code/model/SiteTree.php +++ b/code/model/SiteTree.php @@ -1987,7 +1987,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid // "unpublish" $unpublish = FormAction::create('unpublish', _t('SiteTree.BUTTONUNPUBLISH', 'Unpublish'), 'delete'); $unpublish->describe(_t('SiteTree.BUTTONUNPUBLISHDESC', 'Remove this page from the published site')); - $unpublish->addExtraClass('delete'); + $unpublish->addExtraClass('unpublish'); $unpublish->addExtraClass('ss-ui-action-destructive'); $actions->push($unpublish); } @@ -2025,7 +2025,8 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid } // "save" - $actions->push(new FormAction('save',_t('CMSMain.SAVE','Save'))); + $actions->push($saveDraftAction = new FormAction('save',_t('CMSMain.SAVE','Save Draft'))); + $saveDraftAction->addExtraClass('save-draft'); } } @@ -2411,13 +2412,13 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid } elseif($this->IsAddedToStage) { $tag = "ins title=\"" . _t('SiteTree.ADDEDTODRAFT', 'Added to draft site') . "\""; } elseif($this->IsModifiedOnStage) { - $tag = "span title=\"" . _t('SiteTree.MODIFIEDONDRAFT', 'Modified on draft site') . "\" class=\"modified\""; + $tag = "span title=\"" . _t('SiteTree.MODIFIEDONDRAFT', 'Modified on draft site') . "\" class=\"status modified\""; } else { $tag = ''; } $text = Convert::raw2xml(str_replace(array("\n","\r"),"",$this->MenuTitle)); - return ($tag) ? "<$tag>" . $text . "" : $text; + return ($tag) ? ""."<$tag>" . $text . "" : "". $text; } /** diff --git a/javascript/AssetAdmin.js b/javascript/AssetAdmin.js index 805f5f2d..74127f5a 100755 --- a/javascript/AssetAdmin.js +++ b/javascript/AssetAdmin.js @@ -47,7 +47,7 @@ var currNode = $('.cms-tree')[0].firstSelected(); if(currNode) { var url = $(currNode).find('a').attr('href'); - $('.cms-edit-form').loadForm(url); + $('.cms-content').loadForm(url); } $('.cms-tree')[0].setCustomURL('admin/assets/getsubtree'); $('.cms-tree')[0].reload({onSuccess: function() { diff --git a/javascript/CMSMain.js b/javascript/CMSMain.js index 77c5c3e5..5e048d6a 100644 --- a/javascript/CMSMain.js +++ b/javascript/CMSMain.js @@ -201,8 +201,9 @@ if (e.button!=2) { var $link = $(this); $link.addClass('loading'); - jQuery('.cms-edit-form').entwine('ss').loadForm( + jQuery('.cms-content').entwine('ss').loadForm( $(this).attr('href'), + null, function(e) { $link.removeClass('loading'); } @@ -263,8 +264,9 @@ var link = $(this).siblings('.versionlink').find('a').attr('href'); td.addClass('loading'); - jQuery('.cms-edit-form').entwine('ss').loadForm( + jQuery('.cms-content').entwine('ss').loadForm( link, + null, function(e) { td.removeClass('loading'); } @@ -314,8 +316,9 @@ data.push({name:$button.attr('name'), value: $button.val()}); if(loadEditForm) { - jQuery('.cms-edit-form').entwine('ss').loadForm( + jQuery('.cms-content').entwine('ss').loadForm( this.attr('action'), + null, function(e) { $button.removeClass('loading'); }, diff --git a/javascript/CMSPagesController.Tree.js b/javascript/CMSPagesController.Tree.js index 3aeca1d9..e69de29b 100644 --- a/javascript/CMSPagesController.Tree.js +++ b/javascript/CMSPagesController.Tree.js @@ -1,7 +0,0 @@ -(function($) { - $('.cms-tree').bind('select_node.jstree', function(e, data) { - var node = data.rslt.obj, url = $(node).find('a:first').attr('href'); - if(url && url != '#') document.location.href = url; - return false; - }); -}(jQuery)); \ No newline at end of file diff --git a/templates/Includes/AssetAdmin_Content.ss b/templates/Includes/AssetAdmin_Content.ss index 638f7239..d1ec94a3 100644 --- a/templates/Includes/AssetAdmin_Content.ss +++ b/templates/Includes/AssetAdmin_Content.ss @@ -1,4 +1,4 @@ -
+
@@ -35,7 +35,7 @@
-
+
$EditForm
diff --git a/templates/Includes/CMSPageHistoryController_Content.ss b/templates/Includes/CMSPageHistoryController_Content.ss index eca8c331..7e0037f2 100644 --- a/templates/Includes/CMSPageHistoryController_Content.ss +++ b/templates/Includes/CMSPageHistoryController_Content.ss @@ -1,3 +1,3 @@ -
+
Not implemented yet
\ No newline at end of file diff --git a/templates/Includes/CMSPageReportsController_Content.ss b/templates/Includes/CMSPageReportsController_Content.ss index eca8c331..7e0037f2 100644 --- a/templates/Includes/CMSPageReportsController_Content.ss +++ b/templates/Includes/CMSPageReportsController_Content.ss @@ -1,3 +1,3 @@ -
+
Not implemented yet
\ No newline at end of file diff --git a/templates/Includes/CMSPagesController_Content.ss b/templates/Includes/CMSPagesController_Content.ss index c6e8f03d..25cb2790 100644 --- a/templates/Includes/CMSPagesController_Content.ss +++ b/templates/Includes/CMSPagesController_Content.ss @@ -1,4 +1,4 @@ -
+
@@ -28,9 +28,10 @@ $SearchForm
+
-
+
diff --git a/templates/Includes/CMSPagesController_ContentToolbar.ss b/templates/Includes/CMSPagesController_ContentToolbar.ss index 4984f3d4..6c95dc68 100644 --- a/templates/Includes/CMSPagesController_ContentToolbar.ss +++ b/templates/Includes/CMSPagesController_ContentToolbar.ss @@ -12,7 +12,7 @@
-
+ diff --git a/templates/Includes/ReportAdmin_Content.ss b/templates/Includes/ReportAdmin_Content.ss index c3ec7783..162c7613 100755 --- a/templates/Includes/ReportAdmin_Content.ss +++ b/templates/Includes/ReportAdmin_Content.ss @@ -1,4 +1,4 @@ -
+

<% _t('REPORTS','Reports') %>

@@ -17,7 +17,7 @@
-
+
$EditForm
diff --git a/tests/controller/CMSMainTest.php b/tests/controller/CMSMainTest.php index d9f0ecb4..2bf270ab 100644 --- a/tests/controller/CMSMainTest.php +++ b/tests/controller/CMSMainTest.php @@ -198,22 +198,22 @@ class CMSMainTest extends FunctionalTest { // with insufficient permissions $cmsUser->logIn(); $this->get('admin/pages'); - $response = $this->submitForm( - 'Form_AddForm', - null, - array('ParentID' => '0', 'ClassName' => 'Page', 'Locale' => 'en_US') + $response = $this->post( + 'admin/pages/AddForm', + array('ParentID' => '0', 'ClassName' => 'Page', 'Locale' => 'en_US', 'action_doAdd' => 1) ); // should redirect, which is a permission error $this->assertEquals(403, $response->getStatusCode(), 'Add TopLevel page must fail for normal user'); // with correct permissions $rootEditUser->logIn(); - $this->get('admin/pages/'); - $response = $this->submitForm( - 'Form_AddForm', - null, - array('ParentID' => '0', 'ClassName' => 'Page', 'Locale' => 'en_US') + $response = $this->get('admin/pages/'); + + $response = $this->post( + 'admin/pages/AddForm', + array('ParentID' => '0', 'ClassName' => 'Page', 'Locale' => 'en_US', 'action_doAdd' => 1) ); + $this->assertEquals(302, $response->getStatusCode(), 'Must be a redirect on success'); $location=$response->getHeader('Location'); $this->assertContains('/show/',$location, 'Must redirect to /show/ the new page'); diff --git a/tests/controller/ContentControllerPermissionsTest.php b/tests/controller/ContentControllerPermissionsTest.php index 48f0e0c1..bc01740f 100644 --- a/tests/controller/ContentControllerPermissionsTest.php +++ b/tests/controller/ContentControllerPermissionsTest.php @@ -16,19 +16,22 @@ class ContentControllerPermissionTest extends FunctionalTest { $page->publish('Stage', 'Live'); $response = $this->get('/testpage'); - $this->assertEquals($response->getStatusCode(), 200); + $this->assertEquals($response->getStatusCode(), 200, 'Doesnt require login for implicit live stage'); $response = $this->get('/testpage/?stage=Live'); - $this->assertEquals($response->getStatusCode(), 200); + $this->assertEquals($response->getStatusCode(), 200, 'Doesnt require login for explicit live stage'); $response = $this->get('/testpage/?stage=Stage'); // should redirect to login - $this->assertEquals($response->getStatusCode(), 302); + $this->assertEquals($response->getStatusCode(), 302, 'Redirects to login page when not logged in for draft stage'); + $this->assertContains('Security/login', $response->getHeader('Location')); $this->logInWithPermission('CMS_ACCESS_CMSMain'); $response = $this->get('/testpage/?stage=Stage'); - $this->assertEquals($response->getStatusCode(), 200); + $this->assertEquals($response->getStatusCode(), 302, 'Redirects to page view in CMS when logged in for draft stage'); + $this->assertNotContains('Security/login', $response->getHeader('Location')); + $this->assertContains('admin/page/edit/show/' . $page->ID, $response->getHeader('Location')); } diff --git a/tests/model/SiteTreePermissionsTest.php b/tests/model/SiteTreePermissionsTest.php index 72e2222f..5c911943 100755 --- a/tests/model/SiteTreePermissionsTest.php +++ b/tests/model/SiteTreePermissionsTest.php @@ -54,6 +54,7 @@ class SiteTreePermissionsTest extends FunctionalTest { // should be prompted for a login $response = $this->get($page->URLSegment . '?stage=Stage'); $this->assertEquals($response->getStatusCode(), '302'); + $this->assertContains('Security/login', $response->getHeader('Location')); $this->logInWithPermission('ADMIN'); @@ -61,7 +62,9 @@ class SiteTreePermissionsTest extends FunctionalTest { $this->assertEquals($response->getStatusCode(), '404'); $response = $this->get($page->URLSegment . '?stage=Stage'); - $this->assertEquals($response->getStatusCode(), '200'); + $this->assertEquals($response->getStatusCode(), '302'); + $this->assertNotContains('Security/login', $response->getHeader('Location')); + $this->assertContains('admin/page/edit/show/' . $page->ID, $response->getHeader('Location')); $response = $this->get($page->URLSegment . '?stage='); $this->assertEquals($response->getStatusCode(), '404'); @@ -330,9 +333,10 @@ class SiteTreePermissionsTest extends FunctionalTest { $response = $this->get($childPage->RelativeLink()); $this->assertEquals( $response->getStatusCode(), - 200, + 302, 'Authenticated members can view a page marked as "Viewable by these groups" if theyre in the listed groups by inherited permission' ); + $this->assertContains('admin/page/edit/show/' . $childPage->ID, $response->getHeader('Location')); $this->session()->inst_set('loggedInAs', null); }