BUG Fix editors not being able to create categories / tags

Remove debug::dump from tests
Hide options if not allowed to edit the blog
This commit is contained in:
Damian Mooyman 2015-03-25 14:59:58 +13:00
parent 3be06ffd20
commit 45a1af4a0d
6 changed files with 13 additions and 21 deletions

View File

@ -82,6 +82,9 @@ class Blog extends Page implements PermissionProvider {
$self =& $this;
$this->beforeUpdateCMSFields(function($fields) use ($self) {
// Don't show this tab if edit is not allowed
if(!$self->canEdit()) return;
// Create categories and tag config
$config = GridFieldConfig_RecordEditor::create();
$config->removeComponentsByType("GridFieldAddNewButton");

View File

@ -84,7 +84,10 @@ class BlogCategory extends DataObject {
if($extended !== null) {
return $extended;
}
return $this->Blog()->canEdit($member);
// Since there is no parent yet, need to make a best guess
$permission = Blog::config()->grant_user_permission;
return Permission::checkMember($member, $permission);
}

View File

@ -76,7 +76,10 @@ class BlogTag extends DataObject {
if($extended !== null) {
return $extended;
}
return $this->Blog()->canEdit($member);
// Since there is no parent yet, need to make a best guess
$permission = Blog::config()->grant_user_permission;
return Permission::checkMember($member, $permission);
}

View File

@ -77,17 +77,9 @@ class BlogCategoryTest extends FunctionalTest {
$editor = $this->objFromFixture('Member', 'editor');
// The first blog can bew viewed by anybody
$category = $this->objFromFixture("BlogCategory", "firstcategory");
$category = singleton('BlogCategory');
$this->assertTrue($category->canCreate($admin), "Admin should be able to create category.");
$this->assertTrue($category->canCreate($editor), "Editor should be able to create category.");
$category = $this->objFromFixture("BlogCategory", "secondcategory");
$this->assertTrue($category->canCreate($admin), "Admin should be able to create category.");
$this->assertFalse($category->canCreate($editor), "Editor should not be able to create category.");
$category = $this->objFromFixture("BlogCategory", "thirdcategory");
$this->assertTrue($category->canCreate($admin), "Admin should always be able to create category.");
$this->assertTrue($category->canCreate($editor), "Editor should be able to create category.");
}

View File

@ -77,17 +77,9 @@ class BlogTagTest extends FunctionalTest {
$editor = $this->objFromFixture('Member', 'editor');
// The first blog can bew viewed by anybody
$tag = $this->objFromFixture("BlogTag", "firsttag");
$tag = singleton("BlogTag");
$this->assertTrue($tag->canCreate($admin), "Admin should be able to create tag.");
$this->assertTrue($tag->canCreate($editor), "Editor should be able to create tag.");
$tag = $this->objFromFixture("BlogTag", "secondtag");
$this->assertTrue($tag->canCreate($admin), "Admin should be able to create tag.");
$this->assertFalse($tag->canCreate($editor), "Editor should not be able to create tag.");
$tag = $this->objFromFixture("BlogTag", "thirdtag");
$this->assertTrue($tag->canCreate($admin), "Admin should always be able to create tags.");
$this->assertTrue($tag->canCreate($editor), "Editor should be able to create tag.");
}

View File

@ -111,7 +111,6 @@ class BlogTest extends SapphireTest {
// Check that editors have all permissions on their own blog
$this->assertTrue($blog->canEdit($editor));
Debug::dump($blog2->Editors()->count());
$this->assertFalse($blog2->canEdit($editor));
$this->assertTrue($blog->canAddChildren($editor));
$this->assertFalse($blog2->canAddChildren($editor));