mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Added File.ShowInSearch flag to mirror the existing SiteTree.ShowInSearch flag - e.g. useful to limit visibility of user-uploaded files. Enforced in MySQLDatabase->searchEngine().
This commit is contained in:
parent
73cca09960
commit
83ad8d48a9
@ -767,6 +767,11 @@ class MySQLDatabase extends SS_Database {
|
||||
|
||||
// Always ensure that only pages with ShowInSearch = 1 can be searched
|
||||
$extraFilters['SiteTree'] .= " AND ShowInSearch <> 0";
|
||||
|
||||
// File.ShowInSearch was added later, keep the database driver backwards compatible
|
||||
// by checking for its existence first
|
||||
$fields = $this->fieldList('File');
|
||||
if(array_key_exists('ShowInSearch', $fields)) $extraFilters['File'] .= " AND ShowInSearch <> 0";
|
||||
|
||||
$limit = $start . ", " . (int) $pageLength;
|
||||
|
||||
|
@ -74,7 +74,9 @@ class File extends DataObject {
|
||||
"Title" => "Varchar(255)",
|
||||
"Filename" => "Text",
|
||||
"Content" => "Text",
|
||||
"Sort" => "Int"
|
||||
"Sort" => "Int",
|
||||
// Only applies to files, doesn't inherit for folder
|
||||
'ShowInSearch' => 'Boolean(1)',
|
||||
);
|
||||
|
||||
static $has_one = array(
|
||||
@ -90,8 +92,10 @@ class File extends DataObject {
|
||||
"BackLinkTracking" => "SiteTree",
|
||||
);
|
||||
|
||||
static $defaults = array();
|
||||
|
||||
static $defaults = array(
|
||||
"ShowInSearch" => 1,
|
||||
);
|
||||
|
||||
static $extensions = array(
|
||||
"Hierarchy",
|
||||
);
|
||||
|
@ -170,7 +170,7 @@ class SearchFormTest extends FunctionalTest {
|
||||
$member->logOut();
|
||||
}
|
||||
|
||||
function testDisabledShowInSearchFlagNotIncluded() {
|
||||
function testDisabledShowInSearchFlagNotIncludedForSiteTree() {
|
||||
$sf = new SearchForm($this->mockController, 'SearchForm');
|
||||
|
||||
$page = $this->objFromFixture('SiteTree', 'dontShowInSearchPage');
|
||||
@ -181,6 +181,26 @@ class SearchFormTest extends FunctionalTest {
|
||||
'Page with "Show in Search" disabled doesnt show'
|
||||
);
|
||||
}
|
||||
|
||||
function testDisabledShowInSearchFlagNotIncludedForFiles() {
|
||||
$sf = new SearchForm($this->mockController, 'SearchForm');
|
||||
|
||||
$dontShowInSearchFile = $this->objFromFixture('File', 'dontShowInSearchFile');
|
||||
$showInSearchFile = $this->objFromFixture('File', 'showInSearchFile');
|
||||
$results = $sf->getResults(null, array('Search'=>'dontShowInSearchFile'));
|
||||
$this->assertNotContains(
|
||||
$dontShowInSearchFile->ID,
|
||||
$results->column('ID'),
|
||||
'File with "Show in Search" disabled doesnt show'
|
||||
);
|
||||
|
||||
$results = $sf->getResults(null, array('Search'=>'showInSearchFile'));
|
||||
$this->assertContains(
|
||||
$showInSearchFile->ID,
|
||||
$results->column('ID'),
|
||||
'File with "Show in Search" enabled can be found'
|
||||
);
|
||||
}
|
||||
|
||||
function testSearchTitleAndContentWithSpecialCharacters() {
|
||||
$sf = new SearchForm($this->mockController, 'SearchForm');
|
||||
|
@ -33,4 +33,11 @@ SiteTree:
|
||||
ShowInSearch: 0
|
||||
pageWithSpecialChars:
|
||||
Title: Brötchen
|
||||
Content: Frisch vom Bäcker
|
||||
Content: Frisch vom Bäcker
|
||||
File:
|
||||
showInSearchFile:
|
||||
Title: showInSearchFile
|
||||
ShowInSearch: 1
|
||||
dontShowInSearchFile:
|
||||
Title: dontShowInSearchFile
|
||||
ShowInSearch: 0
|
Loading…
Reference in New Issue
Block a user