]> source.dussan.org Git - nextcloud-server.git/commitdiff
Delete theming images when logo/background is reset to default 4594/head
authorJulius Härtl <jus@bitgrid.net>
Sat, 29 Apr 2017 09:22:34 +0000 (11:22 +0200)
committerMorris Jobke <hey@morrisjobke.de>
Sun, 30 Apr 2017 14:04:55 +0000 (11:04 -0300)
Signed-off-by: Julius Härtl <jus@bitgrid.net>
apps/theming/lib/Controller/ThemingController.php
apps/theming/tests/Controller/ThemingControllerTest.php

index cffc628e9b981f351a4cda10efdd7f603b91072f..faaff1f2174cceb5e57b7aec50526d1d22c2fbbe 100644 (file)
@@ -40,6 +40,7 @@ use OCP\AppFramework\Utility\ITimeFactory;
 use OCP\Files\File;
 use OCP\Files\IAppData;
 use OCP\Files\NotFoundException;
+use OCP\Files\NotPermittedException;
 use OCP\IConfig;
 use OCP\IL10N;
 use OCP\ILogger;
@@ -265,6 +266,24 @@ class ThemingController extends Controller {
                $value = $this->themingDefaults->undo($setting);
                // reprocess server scss for preview
                $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/server.scss', 'core');
+
+               if($setting === 'logoMime') {
+                       try {
+                               $file = $this->appData->getFolder('images')->getFile('logo');
+                               $file->delete();
+                       } catch (NotFoundException $e) {
+                       } catch (NotPermittedException $e) {
+                       }
+               }
+               if($setting === 'backgroundMime') {
+                       try {
+                               $file = $this->appData->getFolder('images')->getFile('background');
+                               $file->delete();
+                       } catch (NotFoundException $e) {
+                       } catch (NotPermittedException $e) {
+                       }
+               }
+
                return new DataResponse(
                        [
                                'data' =>
index 0aa9ead3742bfb93b37c28d735b26d9f26d34f63..f22c317d73d6101fe007ab2d54c03df5432e4239 100644 (file)
@@ -385,6 +385,56 @@ class ThemingControllerTest extends TestCase {
                $this->assertEquals($expected, $this->themingController->undo('MySetting'));
        }
 
+       public function dataUndoDelete() {
+               return [
+                       [ 'backgroundMime', 'background' ],
+                       [ 'logoMime', 'logo' ]
+               ];
+       }
+
+       /** @dataProvider dataUndoDelete */
+       public function testUndoDelete($value, $filename) {
+               $this->l10n
+                       ->expects($this->once())
+                       ->method('t')
+                       ->with('Saved')
+                       ->willReturn('Saved');
+               $this->themingDefaults
+                       ->expects($this->once())
+                       ->method('undo')
+                       ->with($value)
+                       ->willReturn($value);
+               $folder = $this->createMock(ISimpleFolder::class);
+               $file = $this->createMock(ISimpleFile::class);
+               $this->appData
+                       ->expects($this->once())
+                       ->method('getFolder')
+                       ->with('images')
+                       ->willReturn($folder);
+               $folder
+                       ->expects($this->once())
+                       ->method('getFile')
+                       ->with($filename)
+                       ->willReturn($file);
+               $file
+                       ->expects($this->once())
+                       ->method('delete');
+
+               $expected = new DataResponse(
+                       [
+                               'data' =>
+                                       [
+                                               'value' => $value,
+                                               'message' => 'Saved',
+                                       ],
+                               'status' => 'success'
+                       ]
+               );
+               $this->assertEquals($expected, $this->themingController->undo($value));
+       }
+
+
+
        public function testGetLogoNotExistent() {
                $this->appData->method('getFolder')
                        ->with($this->equalTo('images'))