mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
ENHANCEMENT: display only members of Administrators and Blog Management groups in the blog holder's blog owners dropdown field
FEATURE: allow blog owner customisation
This commit is contained in:
parent
3e952feefc
commit
d9d12dd621
@ -28,18 +28,38 @@ class BlogHolder extends BlogTree implements PermissionProvider {
|
||||
);
|
||||
|
||||
function getCMSFields() {
|
||||
$blogOwners = $this->blogOwners();
|
||||
|
||||
SiteTree::disableCMSFieldsExtensions();
|
||||
$fields = parent::getCMSFields();
|
||||
SiteTree::enableCMSFieldsExtensions();
|
||||
|
||||
$fields->addFieldToTab('Root.Content.Main', new CheckboxField('TrackBacksEnabled', 'Enable TrackBacks'));
|
||||
$fields->addFieldToTab('Root.Content.Main', new DropdownField('OwnerID', 'Blog owner', DataObject::get('Member')->toDropDownMap('ID', 'Name', 'None')));
|
||||
$fields->addFieldToTab('Root.Content.Main', new DropdownField('OwnerID', 'Blog owner', $blogOwners->toDropDownMap('ID', 'Name', 'None')));
|
||||
$fields->addFieldToTab('Root.Content.Main', new CheckboxField('AllowCustomAuthors', 'Allow non-admins to have a custom author field'));
|
||||
|
||||
$this->extend('updateCMSFields', $fields);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get members who have BLOGMANAGEMENT and ADMIN permission
|
||||
*/
|
||||
function blogOwners($sort = 'Name', $direction = "ASC") {
|
||||
$adminMembers = Permission::get_members_by_permission('ADMIN');
|
||||
$blogOwners = Permission::get_members_by_permission('BLOGMANAGEMENT');
|
||||
|
||||
if(!$adminMembers) $adminMembers = new DataObjectSet();
|
||||
if(!$blogOwners) $blogOwners = new DataObjectSet();
|
||||
|
||||
$blogOwners->merge($adminMembers);
|
||||
$blogOwners->sort($sort, $direction);
|
||||
|
||||
$this->extend('extendBlogOwners', $blogOwners);
|
||||
|
||||
return $blogOwners;
|
||||
}
|
||||
|
||||
public function BlogHolderIDs() {
|
||||
return array( $this->ID );
|
||||
|
@ -53,6 +53,21 @@ class BlogHolderTest extends SapphireTest {
|
||||
$this->assertContains($entry->URLSegment, $expectedEntries);
|
||||
}
|
||||
}
|
||||
|
||||
function testBlogOwners() {
|
||||
$mainblog = $this->objFromFixture('BlogHolder', 'mainblog');
|
||||
$actualMembers = array_values($mainblog->blogOwners()->toDropDownMap('ID', 'Name'));
|
||||
$expectedMembers = array(
|
||||
'ADMIN User', // test default admin
|
||||
'Admin One',
|
||||
'Admin Two',
|
||||
'Blog Owner One',
|
||||
'Blog Owner Three',
|
||||
'Blog Owner Two',
|
||||
);
|
||||
|
||||
$this->assertEquals($expectedMembers, $actualMembers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,43 @@ BlogEntry:
|
||||
Date: 2008-01-17 18:45:00
|
||||
Parent: =>BlogHolder.mainblog
|
||||
Tags: tag1,tag2,tag3
|
||||
|
||||
|
||||
|
||||
Permission:
|
||||
admin:
|
||||
Code: ADMIN
|
||||
blogOwners:
|
||||
Code: BLOGMANAGEMENT
|
||||
|
||||
Group:
|
||||
admin:
|
||||
Title: Admin
|
||||
Permissions: =>Permission.admin
|
||||
blogOwners:
|
||||
Title: Blog Owners
|
||||
Permissions: =>Permission.blogOwners
|
||||
|
||||
Member:
|
||||
admin1:
|
||||
Name: Admin One
|
||||
Groups: =>Group.admin
|
||||
admin2:
|
||||
Name: Admin Two
|
||||
Groups: =>Group.admin
|
||||
blogOwner1:
|
||||
Name: Blog Owner One
|
||||
Groups: =>Group.blogOwners
|
||||
blogOwner2:
|
||||
Name: Blog Owner Two
|
||||
Groups: =>Group.blogOwners
|
||||
blogOwner3:
|
||||
Name: Blog Owner Three
|
||||
Groups: =>Group.admin, =>Group.blogOwners
|
||||
noBody:
|
||||
Name: No Body
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user