diff --git a/src/Dev/FixFilePermissionsTask.php b/src/Dev/FixFilePermissionsTask.php new file mode 100644 index 00000000..79e84187 --- /dev/null +++ b/src/Dev/FixFilePermissionsTask.php @@ -0,0 +1,39 @@ +baseTable(), + ['CanViewType' => 'Inherit'], + ['ISNUll(CanViewType)'] + )->execute(); + + // This part won't work if run from the CLI, because Apache and the CLI don't share the same cache. + InheritedPermissionFlusher::flush(); + + echo "Done!"; + } +} diff --git a/tests/php/FixFilePermissionsTaskTest.php b/tests/php/FixFilePermissionsTaskTest.php new file mode 100644 index 00000000..2ec32349 --- /dev/null +++ b/tests/php/FixFilePermissionsTaskTest.php @@ -0,0 +1,32 @@ +run(null); + + $this->assertEquals('Inherit', Folder::get()->where(['Name' => 'ParentFolder'])->first()->CanViewType); + $this->assertEquals('Inherit', Folder::get()->where(['Name' => 'SubFolder'])->first()->CanViewType); + $this->assertEquals('LoggedInUsers', Image::get()->where(['Name' => 'myimage.jpg'])->first()->CanViewType); + $this->assertEquals('OnlyTheseUsers', Image::get()->where(['Name' => 'myotherimage.jpg'])->first()->CanViewType); + $this->assertEquals('Inherit', File::get()->where(['Name' => 'anotherfile.jpg'])->first()->CanViewType); + $this->assertEquals('Inherit', File::get()->where(['Name' => 'file.jpg'])->first()->CanViewType); + $this->assertEquals('Anyone', File::get()->where(['Name' => 'picture.jpg'])->first()->CanViewType); + $this->assertEquals('Inherit', File::get()->where(['Name' => 'file2.jpg'])->first()->CanViewType); + } +} diff --git a/tests/php/FixFilePermissionsTaskTest.yml b/tests/php/FixFilePermissionsTaskTest.yml new file mode 100644 index 00000000..31183666 --- /dev/null +++ b/tests/php/FixFilePermissionsTaskTest.yml @@ -0,0 +1,31 @@ +SilverStripe\Assets\Folder: + parent: + Name: ParentFolder + CanViewType: NULL + subfolder: + Name: SubFolder + Parent: =>SilverStripe\Assets\Folder.parent +SilverStripe\Assets\Image: + image1: + Name: myimage.jpg + CanViewType: LoggedInUsers + image2: + Name: myotherimage.jpg + ParentID: =>SilverStripe\Assets\Folder.subfolder + CanViewType: OnlyTheseUsers +SilverStripe\Assets\File: + file1: + Name: anotherfile.jpg + CanViewType: Inherit + file2: + Name: file.jpg + ParentID: =>SilverStripe\Assets\Folder.parent + CanViewType: NULL + file3: + Name: picture.jpg + ParentID: =>SilverStripe\Assets\Folder.subfolder + CanViewType: Anyone + file4: + Name: file2.jpg + ParentID: =>SilverStripe\Assets\Folder.parent + CanViewType: