diff --git a/code/model/Blog.php b/code/model/Blog.php index a9aa25b..99180e0 100644 --- a/code/model/Blog.php +++ b/code/model/Blog.php @@ -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"); diff --git a/code/model/BlogCategory.php b/code/model/BlogCategory.php index 58ead95..8f63efc 100644 --- a/code/model/BlogCategory.php +++ b/code/model/BlogCategory.php @@ -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); } diff --git a/code/model/BlogTag.php b/code/model/BlogTag.php index a479d25..9dbaf69 100644 --- a/code/model/BlogTag.php +++ b/code/model/BlogTag.php @@ -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); } diff --git a/tests/BlogCategoryTest.php b/tests/BlogCategoryTest.php index 5b618ca..428a442 100755 --- a/tests/BlogCategoryTest.php +++ b/tests/BlogCategoryTest.php @@ -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."); } diff --git a/tests/BlogTagTest.php b/tests/BlogTagTest.php index 6bf44e3..e7da478 100755 --- a/tests/BlogTagTest.php +++ b/tests/BlogTagTest.php @@ -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."); } diff --git a/tests/BlogTest.php b/tests/BlogTest.php index a9e32f1..2a7d284 100755 --- a/tests/BlogTest.php +++ b/tests/BlogTest.php @@ -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));