Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit 83ad8d48a99fcc82c2c0c4a24a4ed6923c506a1e 1 parent 73cca09
@chillu chillu authored
View
5 core/model/MySQLDatabase.php
@@ -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
10 filesystem/File.php
@@ -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",
);
View
22 tests/search/SearchFormTest.php
@@ -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');
View
9 tests/search/SearchFormTest.yml
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.