Permalink
Browse files

ENHANCEMENT Added File.ShowInSearch flag to mirror the existing SiteT…

…ree.ShowInSearch flag - e.g. useful to limit visibility of user-uploaded files. Enforced in MySQLDatabase->searchEngine().
  • Loading branch information...
chillu committed Sep 15, 2011
1 parent 73cca09 commit 83ad8d48a99fcc82c2c0c4a24a4ed6923c506a1e
Showing with 41 additions and 5 deletions.
  1. +5 −0 core/model/MySQLDatabase.php
  2. +7 −3 filesystem/File.php
  3. +21 −1 tests/search/SearchFormTest.php
  4. +8 −1 tests/search/SearchFormTest.yml
@@ -767,6 +767,11 @@ public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $
// 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;
View
@@ -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 @@ function testInheritedRestrictedPagesNotInlucded() {
$member->logOut();
}
function testDisabledShowInSearchFlagNotIncluded() {
function testDisabledShowInSearchFlagNotIncludedForSiteTree() {
$sf = new SearchForm($this->mockController, 'SearchForm');
$page = $this->objFromFixture('SiteTree', 'dontShowInSearchPage');
@@ -181,6 +181,26 @@ function testDisabledShowInSearchFlagNotIncluded() {
'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&auml;cker
Content: Frisch vom B&auml;cker
File:
showInSearchFile:
Title: showInSearchFile
ShowInSearch: 1
dontShowInSearchFile:
Title: dontShowInSearchFile
ShowInSearch: 0

0 comments on commit 83ad8d4

Please sign in to comment.