Merge branch '4' into 5

This commit is contained in:
Guy Sartorelli 2022-10-13 11:18:14 +13:00
commit 9b64c7de24
No known key found for this signature in database
GPG Key ID: F313E3B9504D496A
20 changed files with 170 additions and 48 deletions

View File

@ -377,6 +377,16 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
return $this->Link('listview');
}
/**
* Get the link for editing a page.
*
* @see CMSEditLinkExtension::getCMSEditLinkForManagedDataObject()
*/
public function getCMSEditLinkForManagedDataObject(SiteTree $obj): string
{
return Controller::join_links(CMSPageEditController::singleton()->Link('show'), $obj->ID);
}
public function LinkPageEdit($id = null)
{
if (!$id) {

View File

@ -4,7 +4,9 @@ namespace SilverStripe\CMS\Model;
use Page;
use Psr\SimpleCache\CacheInterface;
use SilverStripe\Admin\CMSEditLinkExtension;
use SilverStripe\Assets\Shortcodes\FileLinkTracking;
use SilverStripe\CMS\Controllers\CMSMain;
use SilverStripe\CMS\Controllers\CMSPageEditController;
use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\CMS\Controllers\ModelAsController;
@ -113,7 +115,6 @@ use SilverStripe\View\SSViewer;
*/
class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvider, CMSPreviewable, Resettable, Flushable, MemberCacheFlusher
{
/**
* Indicates what kind of children this page type can have.
* This can be an array of allowed child classes, or the string "none" -
@ -215,6 +216,12 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
*/
private static $controller_name = null;
/**
* The class of the LeftAndMain controller where this class is managed.
* @see CMSEditLinkExtension::getCMSEditOwner()
*/
private static string $cms_edit_owner = CMSMain::class;
/**
* You can define the a map of Page namespaces to Controller namespaces here
* This will apply after the magic of appending Controller, and in order
@ -316,6 +323,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
Hierarchy::class,
Versioned::class,
InheritedPermissionsExtension::class,
CMSEditLinkExtension::class,
];
private static $searchable_fields = [
@ -736,14 +744,11 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
*/
public function CMSEditLink()
{
$link = Controller::join_links(
CMSPageEditController::singleton()->Link('show'),
$this->ID
);
return Director::absoluteURL($link);
// This method has to be implemented here to satisfy the CMSPreviewable interface.
// See the actual implementation in CMSEditLinkExtension.
return $this->extend('CMSEditLink')[0];
}
/**
* Return a CSS identifier generated from this page's link.
*

View File

@ -28,7 +28,7 @@
</a>
<% end_if %>
<% include SilverStripe\\Admin\\LeftAndMain_ViewModeSelector SelectID="preview-mode-dropdown-in-content" %>
<% include SilverStripe\\Admin\\LeftAndMain_ViewModeSelector SelectID="preview-mode-dropdown-in-content", ExtraClass='' %>
</div>
<% end_if %>
</div>

View File

@ -5,7 +5,8 @@ Feature: Apply rich formatting to content
Background:
Given a "page" "About Us" has the "Content" "<h1>My awesome headline</h1><p>Some amazing content</p>"
And I am logged in with "ADMIN" permissions
Given the "group" "EDITOR" has permissions "Access to 'Pages' section"
And I am logged in as a member of "EDITOR" group
And I go to "/admin/pages"
Then I click on "About Us" in the tree

View File

@ -6,12 +6,12 @@ Feature: Create a page
Background:
Given a "page" "MyPage"
And a "virtual page" "MyVirtualPage"
And a "group" "AUTHOR group" has permissions "Access to 'Pages' section"
And I am logged in with "ADMIN" permissions
And the "group" "EDITOR" has permissions "Access to 'Pages' section"
@javascript
Scenario: I can create a page from the pages section
When I go to "/admin/pages"
When I am logged in as a member of "EDITOR" group
And I go to "/admin/pages"
Then I should see "MyPage" in the tree
And I should see a "Add new" button in CMS Content Toolbar
When I press the "Add new" button
@ -21,7 +21,8 @@ Feature: Create a page
@javascript
Scenario: I can create a page under another page
When I go to "/admin/pages"
When I am logged in as a member of "EDITOR" group
And I go to "/admin/pages"
Then I should see "MyPage" in the tree
And I should see a "Add new" button in CMS Content Toolbar
When I press the "Add new" button
@ -39,12 +40,13 @@ Feature: Create a page
Then I should see an edit page form
Scenario: I cannot add root level pages without permission
When I go to "/admin/settings"
When I am logged in with "ADMIN" permissions
And I go to "/admin/settings"
And I click the "Access" CMS tab
And I click on the "#Form_EditForm_CanCreateTopLevelType_OnlyTheseUsers" element
And I press the "Save" button
And I click on the ".cms-login-status__logout-link" element
When I am logged in with "AUTHOR" permissions
When I am logged in as a member of "EDITOR" group
And I press the "Add new" button
Then I see the "Top level" radio button "disabled" attribute equals "1"
And I see the "Under another page" radio button "checked" attribute equals "1"

View File

@ -4,8 +4,9 @@ Feature: Duplicate a page
So that I can grow my website
Background:
Given I am logged in with "ADMIN" permissions
Given a "page" "Page1"
Given the "group" "EDITOR" has permissions "Access to 'Pages' section"
And I am logged in as a member of "EDITOR" group
And a "page" "Page1"
And the "page" "Page1a" is a child of the "page" "Page1"
And the "page" "Page1b" is a child of the "page" "Page1"
And the "page" "Page1b1" is a child of the "page" "Page1b"

View File

@ -7,7 +7,9 @@ Feature: Edit a page
Given a "page" "About Us" has the "Content" "<p>My content</p>"
And a "image" "assets/file1.jpg"
#And a file "assets/file1.jpg" with changes "image"="assets/folder1/file2.jpg" and "page"="About Us"
And I am logged in with "ADMIN" permissions
And the "group" "AUTHOR" has permissions "Access to 'Pages' section"
And the "group" "EDITOR" has permissions "Access to 'Pages' section" and "SITETREE_GRANT_ACCESS"
And I am logged in as a member of "AUTHOR" group
And I go to "/admin/pages"
Then I should see "About Us" in the tree
@ -115,6 +117,10 @@ Feature: Edit a page
Then I should see "Please choose a linked page in the main content fields in order to publish"
Scenario: Change permission levels for who can view and edit the page, at an individual page level
Given I am not logged in
And I am logged in as a member of "EDITOR" group
And I go to "/admin/pages"
Then I should see "About Us" in the tree
When I click on "About Us" in the tree
And I click the "Settings" CMS tab
And I select the "Form_EditForm_CanViewType_LoggedInUsers" radio button

View File

@ -8,7 +8,8 @@ So that I can link to a external website or a page on my site
Given a "page" "Home"
And a "page" "About Us" has the "Content" "<p>My awesome content</p>"
And a "file" "file1.jpg"
And I am logged in with "ADMIN" permissions
And the "group" "EDITOR" has permissions "Access to 'Pages' section"
And I am logged in as a member of "EDITOR" group
And I go to "/admin/pages"
And I click on "About Us" in the tree

View File

@ -9,7 +9,8 @@ So that I can link to a external website or a page on my site
And a "page" "Home"
And a "page" "About Us" has the "Content" "<p>My awesome content</p>"
And a "page" "Details" has the "Content" "<p>My sub-par content<a name="youranchor"></a></p>"
And I am logged in with "ADMIN" permissions
And the "group" "EDITOR" has permissions "Access to 'Pages' section"
And I am logged in as a member of "EDITOR" group
And I go to "/admin/pages"
And I click on "About Us" in the tree

View File

@ -5,8 +5,8 @@ Feature: Manage page permissions
Background:
Given a "page" "Home" with "Content"="<p>Welcome</p>"
And a "group" "AUTHOR group" has permissions "Access to 'Pages' section"
And a "group" "SECURITY group" has permissions "Access to 'Security' section"
And a "group" "EDITOR" has permissions "Access to 'Pages' section"
And a "group" "SECURITY" has permissions "Access to 'Security' section"
And I am logged in with "ADMIN" permissions
And I go to "/admin/pages"
And I click on "Home" in the tree
@ -20,42 +20,44 @@ Feature: Manage page permissions
# When I am not logged in
# And I go to the homepage
# Then I should see "Welcome"
Scenario: I can limit page view permissions to logged-in users
Given I select "Logged-in users" from "Who can view this page?" input group
And I press the "Publish" button
When I am not logged in
And I go to the homepage
Then I should see a log-in form
When I am logged in with "AUTHOR" permissions
When I am logged in as a member of "EDITOR" group
And I go to the homepage
Then I should see "Welcome"
Scenario: I can limit page view permissions to certain groups
Given I select "Only these groups (choose from list)" from "Who can view this page?" input group
And I select "AUTHOR group" in the "#Form_EditForm_ViewerGroups_Holder" tree dropdown
And I select "EDITOR" in the "#Form_EditForm_ViewerGroups_Holder" tree dropdown
And I press the "Publish" button
When I am not logged in
And I go to the homepage
Then I should see a log-in form
When I am logged in with "SECURITY" permissions
When I am logged in as a member of "SECURITY" group
And I go to the homepage
Then I will see a "warning" log-in message
When I am not logged in
And I am logged in with "AUTHOR" permissions
And I am logged in as a member of "EDITOR" group
And I go to the homepage
Then I should see "Welcome"
Scenario: I can limit page edit permissions to logged-in users
Given I select "Logged-in users" from "Who can edit this page?" input group
Given I am not logged in
And I am logged in as a member of "EDITOR" group
And I go to "/admin/pages"
And I click on "Home" in the tree
Then I should see an edit page form
And I click the "Settings" CMS tab
And I select "Logged-in users" from "Who can edit this page?" input group
And I press the "Publish" button
Then pages should be editable by "AUTHOR"
Then pages should be editable by "EDITOR"
And pages should be editable by "ADMIN"
Scenario: I can limit page edit permissions to certain groups
Given I select "Only these groups (choose from list)" from "Who can edit this page?" input group
And I select "ADMIN group" in the "#Form_EditForm_EditorGroups_Holder" tree dropdown
And I press the "Publish" button
Then pages should not be editable by "AUTHOR"
Then pages should not be editable by "EDITOR"
But pages should be editable by "ADMIN"

View File

@ -5,10 +5,11 @@ Feature: Preview a page
Background:
Given a "page" "About Us"
And the "group" "EDITOR" has permissions "Access to 'Pages' section"
And I am logged in as a member of "EDITOR" group
@javascript
Scenario: I can show a preview of the current page from the pages section
Given I am logged in with "ADMIN" permissions
And I go to "/admin/pages"
Then I should see "About Us" in the tree
@ -23,7 +24,6 @@ Feature: Preview a page
# - We should continue testing against it after we have fixtures ready
@javascript
Scenario: I can see an updated preview when editing content
Given I am logged in with "ADMIN" permissions
And I go to "/admin/pages"
Then I should see "About Us" in the tree

View File

@ -6,6 +6,8 @@ Feature: Publish a page
Background:
Given a "page" "My Page" with "URLSegment"="my-page" and "Content"="<p>initial content</p>"
And the "page" "My Page" is not published
And the "group" "EDITOR" has permissions "Access to 'Pages' section"
And I am logged in as a member of "EDITOR" group
@javascript
Scenario: I can have a unpublished version of a page that is not publicly available
@ -14,8 +16,7 @@ Feature: Publish a page
@javascript
Scenario: I can publish a previously never published page
Given I am logged in with "ADMIN" permissions
And I go to "/admin/pages"
Given I go to "/admin/pages"
And I should see "My Page" in the tree
And I click on "My Page" in the tree
And I press the "Publish" button
@ -27,8 +28,7 @@ Feature: Publish a page
@javascript
Scenario: I will get different options depending on the current publish state of the page
Given I am logged in with "ADMIN" permissions
And I go to "/admin/pages"
Given I go to "/admin/pages"
And I should see "My Page" in the tree
And I click on "My Page" in the tree
@ -58,7 +58,6 @@ Feature: Publish a page
And I go to "/hello"
Then I should see "hello world"
Given I am logged in with "ADMIN" permissions
And I go to "/admin/pages"
And I should see "Hello" in the tree
And I click on "Hello" in the tree
@ -72,8 +71,7 @@ Feature: Publish a page
@javascript
Scenario: I can delete a page from live and draft stage to completely remove it
Given I am logged in with "ADMIN" permissions
And I go to "/admin/pages"
Given I go to "/admin/pages"
And I should see "My Page" in the tree
And I click on "My Page" in the tree
And I press the "Publish" button

View File

@ -7,7 +7,8 @@ Feature: Redirector Pages
Given a "page" "Page 1"
And a "page" "My Redirect" which redirects to a "page" "Page 1"
And a "image" "assets/file1.jpg"
And I am logged in with "ADMIN" permissions
And the "group" "EDITOR" has permissions "Access to 'Pages' section"
And I am logged in as a member of "EDITOR" group
And I go to "/admin/pages"
Scenario: Only the appropriate fields are shown

View File

@ -8,7 +8,8 @@ Feature: Search for a page
Given a "page" "Home"
And a "page" "About Us"
And a "page" "Contact Us"
And I am logged in with "ADMIN" permissions
And the "group" "EDITOR" has permissions "Access to 'Pages' section"
And I am logged in as a member of "EDITOR" group
And I go to "/admin/pages"
And I press the "Filter" button

View File

@ -4,8 +4,8 @@ Feature: Sitetree
So that I can operate my website
Background:
Given the "group" "EDITOR group" has permissions "CMS_ACCESS_LeftAndMain" and "SITETREE_REORGANISE"
And I am logged in with "EDITOR" permissions
Given the "group" "EDITOR" has permissions "Access to 'Pages' section" and "SITETREE_REORGANISE"
And I am logged in as a member of "EDITOR" group
And a "page" "One"
And a "page" "Two"
And a "page" "Three"

View File

@ -6,7 +6,8 @@ Feature: View Reports
Background:
Given a "page" "Empty Page"
And a "page" "Filled Page" with "Content"="<p>Some Content</p>"
And I am logged in with "ADMIN" permissions
And the "group" "EDITOR" has permissions "Access to 'Pages' section" and "Access to 'Reports' section"
And I am logged in as a member of "EDITOR" group
And I go to "/admin/reports"
Scenario: I can view the "Pages with no content" report

View File

@ -0,0 +1,27 @@
<?php
namespace SilverStripe\CMS\Tests\CMSEditLinkExtensionTest;
use SilverStripe\Admin\CMSEditLinkExtension;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
class BelongsToPage extends DataObject implements TestOnly
{
private static $table_name = 'CMSEditLinkTest_BelongsToPage';
private static $cms_edit_owner = 'Parent';
private static $db = [
'Name' => 'Varchar(25)',
];
private static $has_one = [
'Parent' => SiteTree::class,
];
private static $extensions = [
CMSEditLinkExtension::class,
];
}

View File

@ -0,0 +1,25 @@
<?php
namespace SilverStripe\CMS\Tests\CMSEditLinkExtensionTest;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Dev\TestOnly;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
class PageWithChild extends SiteTree implements TestOnly
{
private static $has_many = [
'ChildObjects' => BelongsToPage::class,
];
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldToTab(
'Root.ChildObjects',
GridField::create('ChildObjects', 'ChildObjects', $this->ChildObjects(), GridFieldConfig_RelationEditor::create())
);
return $fields;
}
}

View File

@ -0,0 +1,9 @@
SilverStripe\CMS\Tests\CMSEditLinkExtensionTest\BelongsToPage:
one:
Name: 'some name'
SilverStripe\CMS\Tests\CMSEditLinkExtensionTest\PageWithChild:
root:
Title: 'page has child'
ChildObjects:
- '=>SilverStripe\CMS\Tests\CMSEditLinkExtensionTest\BelongsToPage.one'

View File

@ -9,6 +9,8 @@ use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Model\VirtualPage;
use SilverStripe\CMS\Tests\Controllers\SiteTreeTest_NamespaceMapTestController;
use SilverStripe\CMS\Tests\CMSEditLinkExtensionTest\BelongsToPage;
use SilverStripe\CMS\Tests\CMSEditLinkExtensionTest\PageWithChild;
use SilverStripe\CMS\Tests\Page\SiteTreeTest_NamespaceMapTest;
use SilverStripe\Control\ContentNegotiator;
use SilverStripe\Control\Controller;
@ -42,7 +44,10 @@ use const RESOURCES_DIR;
class SiteTreeTest extends SapphireTest
{
protected static $fixture_file = 'SiteTreeTest.yml';
protected static $fixture_file = [
'SiteTreeTest.yml',
'CMSEditLinkExtensionTest/fixtures.yml',
];
protected static $illegal_extensions = [
SiteTree::class => [
@ -60,6 +65,8 @@ class SiteTreeTest extends SapphireTest
SiteTreeTest_NotRoot::class,
SiteTreeTest_StageStatusInherit::class,
SiteTreeTest_DataObject::class,
PageWithChild::class,
BelongsToPage::class,
];
public function reservedSegmentsProvider()
@ -2043,4 +2050,28 @@ class SiteTreeTest extends SapphireTest
);
// END ARCHIVED
}
public function testGetCMSEditLinkForManagedDataObject()
{
$page = $this->objFromFixture(PageWithChild::class, 'root');
$child = $this->objFromFixture(BelongsToPage::class, 'one');
$this->assertSame(
"http://localhost/admin/pages/edit/show/$page->ID/field/ChildObjects/item/$child->ID",
$page->getCMSEditLinkForManagedDataObject($child, 'Parent')
);
}
public function testCMSEditLink()
{
$page = $this->objFromFixture(PageWithChild::class, 'root');
$child = $this->objFromFixture(BelongsToPage::class, 'one');
$this->assertSame(
"http://localhost/admin/pages/edit/show/$page->ID",
$page->CMSEditLink()
);
$this->assertSame(
"http://localhost/admin/pages/edit/show/$page->ID/field/ChildObjects/item/$child->ID",
$child->CMSEditLink()
);
}
}