Merge pull request #486 from zanderwar/pulls/3.0/optional-profiles

Allow a user to disable all profiles
This commit is contained in:
Daniel Hensby 2017-11-06 15:56:55 +00:00 committed by GitHub
commit 1d6cf1dec6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 67 additions and 8 deletions

View File

@ -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
```

View File

@ -4,8 +4,10 @@ namespace SilverStripe\Blog\Model;
use PageController; use PageController;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Control\RSS\RSSFeed; use SilverStripe\Control\RSS\RSSFeed;
use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\FieldType\DBDatetime; use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\PaginatedList; use SilverStripe\ORM\PaginatedList;
use SilverStripe\Security\Member; use SilverStripe\Security\Member;
@ -42,6 +44,14 @@ class BlogController extends PageController
'FilterDescription' => 'Text' '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. * The current Blog Post DataList query.
* *
@ -67,10 +77,16 @@ class BlogController extends PageController
/** /**
* Renders a Blog Member's profile. * Renders a Blog Member's profile.
* *
* @return HTTPResponse * @throws HTTPResponse_Exception
*
* @return string
*/ */
public function profile() public function profile()
{ {
if ($this->config()->get('disable_profiles')) {
$this->httpError(404, 'Not Found');
}
$profile = $this->getCurrentProfile(); $profile = $this->getCurrentProfile();
if (!$profile) { if (!$profile) {
@ -121,7 +137,7 @@ class BlogController extends PageController
/** /**
* Renders an archive for a specified date. This can be by year or year/month. * Renders an archive for a specified date. This can be by year or year/month.
* *
* @return null|HTTPResponse * @return null|string
*/ */
public function archive() public function archive()
{ {
@ -212,7 +228,7 @@ class BlogController extends PageController
/** /**
* Renders the blog posts for a given tag. * Renders the blog posts for a given tag.
* *
* @return null|HTTPResponse * @return null|string
*/ */
public function tag() public function tag()
{ {
@ -258,7 +274,7 @@ class BlogController extends PageController
/** /**
* Renders the blog posts for a given category. * Renders the blog posts for a given category.
* *
* @return null|HTTPResponse * @return null|string
*/ */
public function category() public function category()
{ {
@ -440,7 +456,7 @@ class BlogController extends PageController
* *
* @example "<% if $PaginationAbsoluteNextLink %><link rel="next" href="$PaginationAbsoluteNextLink"><% end_if %>" * @example "<% if $PaginationAbsoluteNextLink %><link rel="next" href="$PaginationAbsoluteNextLink"><% end_if %>"
* *
* @return string * @return string|null
*/ */
public function PaginationAbsoluteNextLink() public function PaginationAbsoluteNextLink()
{ {
@ -448,6 +464,8 @@ class BlogController extends PageController
if ($posts->NotLastPage()) { if ($posts->NotLastPage()) {
return Director::absoluteURL($posts->NextLink()); return Director::absoluteURL($posts->NextLink());
} }
return null;
} }
/** /**
@ -456,7 +474,7 @@ class BlogController extends PageController
* *
* @example "<% if $PaginationAbsolutePrevLink %><link rel="prev" href="$PaginationAbsolutePrevLink"><% end_if %>" * @example "<% if $PaginationAbsolutePrevLink %><link rel="prev" href="$PaginationAbsolutePrevLink"><% end_if %>"
* *
* @return string * @return string|null
*/ */
public function PaginationAbsolutePrevLink() public function PaginationAbsolutePrevLink()
{ {
@ -464,6 +482,8 @@ class BlogController extends PageController
if ($posts->NotFirstPage()) { if ($posts->NotFirstPage()) {
return Director::absoluteURL($posts->PrevLink()); return Director::absoluteURL($posts->PrevLink());
} }
return null;
} }
/** /**
@ -486,7 +506,7 @@ class BlogController extends PageController
/** /**
* Returns the current archive date. * Returns the current archive date.
* *
* @return null|Date * @return null|DBDatetime
*/ */
public function getArchiveDate() public function getArchiveDate()
{ {

View File

@ -9,6 +9,7 @@ use SilverStripe\Blog\Model\BlogCategory;
use SilverStripe\Blog\Model\BlogPostFilter; use SilverStripe\Blog\Model\BlogPostFilter;
use SilverStripe\Blog\Model\BlogTag; use SilverStripe\Blog\Model\BlogTag;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Manifest\ModuleLoader; use SilverStripe\Core\Manifest\ModuleLoader;
use SilverStripe\Forms\DatetimeField; use SilverStripe\Forms\DatetimeField;
use SilverStripe\Forms\HiddenField; use SilverStripe\Forms\HiddenField;
@ -718,6 +719,16 @@ class BlogPost extends Page
return $items; 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'). * Sets the label for BlogPost.Title to 'Post Title' (Rather than 'Page name').
* *

View File

@ -29,7 +29,7 @@
<% loop $Credits %> <% loop $Credits %>
<% if not $First && not $Last %>, <% end_if %> <% if not $First && not $Last %>, <% end_if %>
<% if not $First && $Last %> <%t SilverStripe\\Blog\\Model\\Blog.AND "and" %> <% end_if %> <% if not $First && $Last %> <%t SilverStripe\\Blog\\Model\\Blog.AND "and" %> <% end_if %>
<% if $URLSegment %> <% if $URLSegment && not $Up.ProfilesDisabled %>
<a href="$URL">$Name.XML</a> <a href="$URL">$Name.XML</a>
<% else %> <% else %>
$Name.XML $Name.XML

View File

@ -9,6 +9,7 @@ use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Control\Session; use SilverStripe\Control\Session;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\SapphireTest; 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 * Mock a request against a given controller
* *