diff --git a/_config/extensions.yml b/_config/extensions.yml index a453b3e..96ed75b 100644 --- a/_config/extensions.yml +++ b/_config/extensions.yml @@ -28,3 +28,6 @@ SilverStripe\CMS\Model\SiteTree: extensions: SearchServiceExtension: SilverStripe\SearchService\Extensions\SearchServiceExtension SiteTreeHierarchyExtension: SilverStripe\SearchService\Extensions\SiteTreeHierarchyExtension +SilverStripe\Assets\File: + extensions: + SearchServiceExtension: SilverStripe\SearchService\Extensions\SearchServiceExtension diff --git a/tests/Service/FolderPrivacyTest.php b/tests/Service/FolderPrivacyTest.php new file mode 100644 index 0000000..07f0ec2 --- /dev/null +++ b/tests/Service/FolderPrivacyTest.php @@ -0,0 +1,74 @@ +objFromFixture(Folder::class, 'folder'); + // Add file to folder + $file = $this->objFromFixture(File::class, 'pdf-file'); + $file->ParentID = $folder->ID; + $file->write(); + + $this->assertCount(1, $folder->myChildren()); + + // File should be indexed + $doc = DataObjectDocument::create($file); + $this->assertTrue($doc->shouldIndex()); + } + + public function testRestrictedFolderFileShowInSearch(): void + { + $folder = $this->objFromFixture(Folder::class, 'folder'); + // Set permission to admin only + $folder->CanViewType = 'OnlyTheseUsers'; + $folder->ViewerGroups()->add($this->objFromFixture(Group::class, 'admin-group')); + $folder->write(); + $folder->publishRecursive(); + + // File::add_extension(SearchServiceExtension::class,); + + // Add files to folder + $file = $this->objFromFixture(File::class, 'pdf-file'); + $file->ParentID = $folder->ID; + $file->write(); + $image = $this->objFromFixture(Image::class, 'image'); + $image->ParentID = $folder->ID; + $image->write(); + + $this->assertCount(2, $folder->myChildren()); + + // Remove permission on folder and check if file is indexed + $folder->CanViewType = 'Inherit'; + $folder->ViewerGroups()->removeAll(); + $folder->write(); + + // File should be indexed + $doc1 = DataObjectDocument::create($file); + $this->assertTrue($doc1->shouldIndex()); + + // Image file should not be indexed + $doc2 = DataObjectDocument::create($image); + $this->assertFalse($doc2->shouldIndex()); + } +} diff --git a/tests/fixtures.yml b/tests/fixtures.yml index 4ee023f..d060a7b 100644 --- a/tests/fixtures.yml +++ b/tests/fixtures.yml @@ -14,6 +14,11 @@ SilverStripe\SearchService\Tests\Fake\ImageFake: URL: '/image-two/' Tags: =>SilverStripe\SearchService\Tests\Fake\TagFake.one,=>SilverStripe\SearchService\Tests\Fake\TagFake.two +SilverStripe\Security\Group: + admin-group: + Title: Administrators + Code: administrators + SilverStripe\Security\Member: one: FirstName: member-one-first @@ -24,6 +29,10 @@ SilverStripe\Security\Member: three: FirstName: member-three-first Surname: member-three-last + admin-user: + FirstName: admin-first + Surname: admin-last + Groups: =>SilverStripe\Security\Group.admin-group SilverStripe\SearchService\Tests\Fake\DataObjectFake: one: @@ -64,3 +73,19 @@ SilverStripe\Subsites\Model\Subsite: Title: 'Subsite 1' subsite2: Title: 'Subsite 2' + +SilverStripe\Assets\Image: + image: + Name: 'Image' + Filename: silverstripe-logo.png + PopulateFileFrom: tests/silverstripe-logo.png + +SilverStripe\Assets\File: + pdf-file: + Title: Test File + Filename: test-file.pdf + PopulateFileFrom: tests/test-file.pdf + +SilverStripe\Assets\Folder: + folder: + Name: 'Folder' diff --git a/tests/silverstripe-logo.png b/tests/silverstripe-logo.png new file mode 100644 index 0000000..c70ca44 Binary files /dev/null and b/tests/silverstripe-logo.png differ diff --git a/tests/test-file.pdf b/tests/test-file.pdf new file mode 100644 index 0000000..a9ecd2b Binary files /dev/null and b/tests/test-file.pdf differ