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,12 +28,14 @@ class BlogHolder extends BlogTree implements PermissionProvider {
|
|||||||
);
|
);
|
||||||
|
|
||||||
function getCMSFields() {
|
function getCMSFields() {
|
||||||
|
$blogOwners = $this->blogOwners();
|
||||||
|
|
||||||
SiteTree::disableCMSFieldsExtensions();
|
SiteTree::disableCMSFieldsExtensions();
|
||||||
$fields = parent::getCMSFields();
|
$fields = parent::getCMSFields();
|
||||||
SiteTree::enableCMSFieldsExtensions();
|
SiteTree::enableCMSFieldsExtensions();
|
||||||
|
|
||||||
$fields->addFieldToTab('Root.Content.Main', new CheckboxField('TrackBacksEnabled', 'Enable TrackBacks'));
|
$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'));
|
$fields->addFieldToTab('Root.Content.Main', new CheckboxField('AllowCustomAuthors', 'Allow non-admins to have a custom author field'));
|
||||||
|
|
||||||
$this->extend('updateCMSFields', $fields);
|
$this->extend('updateCMSFields', $fields);
|
||||||
@ -41,6 +43,24 @@ class BlogHolder extends BlogTree implements PermissionProvider {
|
|||||||
return $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() {
|
public function BlogHolderIDs() {
|
||||||
return array( $this->ID );
|
return array( $this->ID );
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,21 @@ class BlogHolderTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -25,4 +25,41 @@ BlogEntry:
|
|||||||
Tags: tag1,tag2,tag3
|
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