From 54aeb2335609d425e4b75148bd7945c946b8bc67 Mon Sep 17 00:00:00 2001 From: zanderwar Date: Wed, 1 Nov 2017 22:00:33 +1300 Subject: [PATCH 1/4] Fixed return tags and values --- src/Model/BlogController.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Model/BlogController.php b/src/Model/BlogController.php index 445be05..4bc5565 100644 --- a/src/Model/BlogController.php +++ b/src/Model/BlogController.php @@ -6,6 +6,7 @@ use PageController; use SilverStripe\Control\Director; use SilverStripe\Control\RSS\RSSFeed; use SilverStripe\ORM\ArrayList; +use SilverStripe\ORM\DataList; use SilverStripe\ORM\FieldType\DBDatetime; use SilverStripe\ORM\PaginatedList; use SilverStripe\Security\Member; @@ -67,7 +68,7 @@ class BlogController extends PageController /** * Renders a Blog Member's profile. * - * @return HTTPResponse + * @return string */ public function profile() { @@ -121,7 +122,7 @@ class BlogController extends PageController /** * Renders an archive for a specified date. This can be by year or year/month. * - * @return null|HTTPResponse + * @return null|string */ public function archive() { @@ -212,7 +213,7 @@ class BlogController extends PageController /** * Renders the blog posts for a given tag. * - * @return null|HTTPResponse + * @return null|string */ public function tag() { @@ -258,7 +259,7 @@ class BlogController extends PageController /** * Renders the blog posts for a given category. * - * @return null|HTTPResponse + * @return null|string */ public function category() { @@ -440,7 +441,7 @@ class BlogController extends PageController * * @example "<% if $PaginationAbsoluteNextLink %><% end_if %>" * - * @return string + * @return string|null */ public function PaginationAbsoluteNextLink() { @@ -448,6 +449,8 @@ class BlogController extends PageController if ($posts->NotLastPage()) { return Director::absoluteURL($posts->NextLink()); } + + return null; } /** @@ -456,7 +459,7 @@ class BlogController extends PageController * * @example "<% if $PaginationAbsolutePrevLink %><% end_if %>" * - * @return string + * @return string|null */ public function PaginationAbsolutePrevLink() { @@ -464,6 +467,8 @@ class BlogController extends PageController if ($posts->NotFirstPage()) { return Director::absoluteURL($posts->PrevLink()); } + + return null; } /** @@ -486,7 +491,7 @@ class BlogController extends PageController /** * Returns the current archive date. * - * @return null|Date + * @return null|DBDatetime */ public function getArchiveDate() { From 3d8f0941ed4266fe9d9976992b3b4cf606f7a39c Mon Sep 17 00:00:00 2001 From: zanderwar Date: Fri, 3 Nov 2017 08:32:03 +1300 Subject: [PATCH 2/4] Added config option check for disable_profiles and removed linking if it is disabled --- src/Model/BlogController.php | 15 +++++++++++++++ src/Model/BlogPost.php | 11 +++++++++++ templates/SilverStripe/Blog/Includes/EntryMeta.ss | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Model/BlogController.php b/src/Model/BlogController.php index 4bc5565..6af2e62 100644 --- a/src/Model/BlogController.php +++ b/src/Model/BlogController.php @@ -4,6 +4,7 @@ namespace SilverStripe\Blog\Model; use PageController; use SilverStripe\Control\Director; +use SilverStripe\Control\HTTPResponse_Exception; use SilverStripe\Control\RSS\RSSFeed; use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\DataList; @@ -43,6 +44,14 @@ class BlogController extends PageController 'FilterDescription' => 'Text' ]; + /** + * If enabled, blog author profiles will be turned off for this site + * + * @config + * @var bool + */ + private static $disable_profiles = false; + /** * The current Blog Post DataList query. * @@ -68,10 +77,16 @@ class BlogController extends PageController /** * Renders a Blog Member's profile. * + * @throws HTTPResponse_Exception + * * @return string */ public function profile() { + if ($this->config()->get('disable_profiles')) { + $this->httpError(404, 'Not Found'); + } + $profile = $this->getCurrentProfile(); if (!$profile) { diff --git a/src/Model/BlogPost.php b/src/Model/BlogPost.php index c34da5c..b9194c8 100644 --- a/src/Model/BlogPost.php +++ b/src/Model/BlogPost.php @@ -9,6 +9,7 @@ use SilverStripe\Blog\Model\BlogCategory; use SilverStripe\Blog\Model\BlogPostFilter; use SilverStripe\Blog\Model\BlogTag; use SilverStripe\Control\Controller; +use SilverStripe\Core\Config\Config; use SilverStripe\Core\Manifest\ModuleLoader; use SilverStripe\Forms\DatetimeField; use SilverStripe\Forms\HiddenField; @@ -712,6 +713,16 @@ class BlogPost extends Page return $items; } + /** + * Checks to see if User Profiles has been disabled via config + * + * @return bool + */ + public function getProfilesDisabled() + { + return Config::inst()->get(BlogController::class, 'disable_profiles'); + } + /** * Sets the label for BlogPost.Title to 'Post Title' (Rather than 'Page name'). * diff --git a/templates/SilverStripe/Blog/Includes/EntryMeta.ss b/templates/SilverStripe/Blog/Includes/EntryMeta.ss index 11160a7..1b0044e 100644 --- a/templates/SilverStripe/Blog/Includes/EntryMeta.ss +++ b/templates/SilverStripe/Blog/Includes/EntryMeta.ss @@ -29,7 +29,7 @@ <% loop $Credits %> <% if not $First && not $Last %>, <% end_if %> <% if not $First && $Last %> <%t SilverStripe\\Blog\\Model\\Blog.AND "and" %> <% end_if %> - <% if $URLSegment %> + <% if $URLSegment && not $Up.ProfilesDisabled %> $Name.XML <% else %> $Name.XML From 2e01219e8f13e30d4038dce44a3c17cf519f4268 Mon Sep 17 00:00:00 2001 From: zanderwar Date: Fri, 3 Nov 2017 08:32:25 +1300 Subject: [PATCH 3/4] Documentation for disabling user profiles --- docs/en/configuring-user-profiles.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 docs/en/configuring-user-profiles.md diff --git a/docs/en/configuring-user-profiles.md b/docs/en/configuring-user-profiles.md new file mode 100644 index 0000000..3616a4b --- /dev/null +++ b/docs/en/configuring-user-profiles.md @@ -0,0 +1,12 @@ +## Configuring user profiles + +This module ships with User Profiles enabled by default. + +If you'd prefer to disable this functionality and instead return a 404 for the `/profile/` page, you can do so using SilverStripe config. + +In mysite/_config/settings.yml + +```yaml +SilverStripe\Blog\Model\BlogController: + disable_profiles: true +``` From 99112e6eef89e6cb8880579279407faaa7de171e Mon Sep 17 00:00:00 2001 From: zanderwar Date: Fri, 3 Nov 2017 08:32:38 +1300 Subject: [PATCH 4/4] Test for disable_profiles option --- tests/BlogTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/BlogTest.php b/tests/BlogTest.php index a942267..553597b 100755 --- a/tests/BlogTest.php +++ b/tests/BlogTest.php @@ -9,6 +9,7 @@ use SilverStripe\CMS\Controllers\ContentController; use SilverStripe\Control\Controller; use SilverStripe\Control\Director; use SilverStripe\Control\HTTPRequest; +use SilverStripe\Control\HTTPResponse_Exception; use SilverStripe\Control\Session; use SilverStripe\Core\Config\Config; use SilverStripe\Dev\SapphireTest; @@ -348,6 +349,21 @@ class BlogTest extends SapphireTest ); } + public function testDisabledProfiles() + { + Config::modify()->set(BlogController::class, 'disable_profiles', true); + + try { + $controller = BlogController::create(); + $controller->setRequest(Controller::curr()->getRequest()); + $controller->profile(); + + $this->fail('The "profile" action should throw a HTTPResponse_Exception when disable_profiles is enabled'); + } catch (HTTPResponse_Exception $e) { + $this->assertEquals(404, $e->getResponse()->getStatusCode(), 'The response status code should be 404 Not Found'); + } + } + /** * Mock a request against a given controller *