diff --git a/apps/theming/js/settings-admin.js b/apps/theming/js/settings-admin.js index c34da3ff87..a8c45977e3 100644 --- a/apps/theming/js/settings-admin.js +++ b/apps/theming/js/settings-admin.js @@ -96,7 +96,8 @@ function hideUndoButton(setting, value) { color: '#0082c9', logoMime: '', backgroundMime: '', - imprintUrl: '' + imprintUrl: '', + privacyUrl: '' }; if (value === themingDefaults[setting] || value === '') { @@ -206,6 +207,16 @@ $(document).ready(function () { } }); + $('#theming-privacyUrl').change(function(e) { + var el = $(this); + $.when(el.focusout()).then(function () { + setThemingValue('privacyUrl', $(this).val()); + }); + if (e.keyCode == 13) { + setThemingValue('privacyUrl', $(this).val()); + } + }); + $('#theming-slogan').change(function(e) { var el = $(this); $.when(el.focusout()).then(function() { diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php index 80eab2b215..33af0f513a 100644 --- a/apps/theming/lib/Controller/ThemingController.php +++ b/apps/theming/lib/Controller/ThemingController.php @@ -167,6 +167,16 @@ class ThemingController extends Controller { ]); } break; + case 'privacyUrl': + if (strlen($value) > 500) { + return new DataResponse([ + 'data' => [ + 'message' => $this->l10n->t('The given privacy policy address is too long'), + ], + 'status' => 'error' + ]); + } + break; case 'slogan': if (strlen($value) > 500) { return new DataResponse([ @@ -470,6 +480,7 @@ class ThemingController extends Controller { slogan: ' . json_encode($this->themingDefaults->getSlogan()) . ', color: ' . json_encode($this->themingDefaults->getColorPrimary()) . ', imprintUrl: ' . json_encode($this->themingDefaults->getImprintUrl()) . ', + privacyUrl: ' . json_encode($this->themingDefaults->getPrivacyUrl()) . ', inverted: ' . json_encode($this->util->invertTextColor($this->themingDefaults->getColorPrimary())) . ', cacheBuster: ' . json_encode($cacheBusterValue) . ' }; diff --git a/apps/theming/lib/Settings/Admin.php b/apps/theming/lib/Settings/Admin.php index 469d4b3d6a..a772ab04fe 100644 --- a/apps/theming/lib/Settings/Admin.php +++ b/apps/theming/lib/Settings/Admin.php @@ -85,6 +85,7 @@ class Admin implements ISettings { 'canThemeIcons' => $this->themingDefaults->shouldReplaceIcons(), 'iconDocs' => $this->urlGenerator->linkToDocs('admin-theming-icons'), 'imprintUrl' => $this->themingDefaults->getImprintUrl(), + 'privacyUrl' => $this->themingDefaults->getPrivacyUrl(), ]; return new TemplateResponse('theming', 'settings-admin', $parameters, ''); diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index b2d31b9083..22ab8d9c9e 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -146,20 +146,41 @@ class ThemingDefaults extends \OC_Defaults { return $this->config->getAppValue('theming', 'imprintUrl', ''); } + public function getPrivacyUrl() { + return $this->config->getAppValue('theming', 'privacyUrl', ''); + } + public function getShortFooter() { $slogan = $this->getSlogan(); $footer = '' .$this->getEntity() . ''. ($slogan !== '' ? ' – ' . $slogan : ''); - $imprintUrl = (string)$this->getImprintUrl(); - if($imprintUrl !== '' - && filter_var($imprintUrl, FILTER_VALIDATE_URL, [ - 'flags' => FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED - ]) - ) { - $footer .= '
' . $this->l->t('Legal notice') . ''; + $links = [ + [ + 'text' => $this->l->t('Legal notice'), + 'url' => (string)$this->getImprintUrl() + ], + [ + 'text' => $this->l->t('Privacy policy'), + 'url' => (string)$this->getPrivacyUrl() + ], + ]; + + $legalLinks = ''; $divider = ''; + foreach($links as $link) { + if($link['url'] !== '' + && filter_var($link['url'], FILTER_VALIDATE_URL, [ + 'flags' => FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED + ]) + ) { + $legalLinks .= $divider . '' . $link['text'] . ''; + $divider = ' · '; + } + } + if($legalLinks !== '' ) { + $footer .= '
' . $legalLinks; } return $footer; diff --git a/apps/theming/templates/settings-admin.php b/apps/theming/templates/settings-admin.php index 907c8662ef..cf4a111718 100644 --- a/apps/theming/templates/settings-admin.php +++ b/apps/theming/templates/settings-admin.php @@ -90,11 +90,18 @@ style('theming', 'settings-admin');
+
+ +

diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php index 43f3d1aa2a..44658c11fe 100644 --- a/apps/theming/tests/Controller/ThemingControllerTest.php +++ b/apps/theming/tests/Controller/ThemingControllerTest.php @@ -877,6 +877,7 @@ class ThemingControllerTest extends TestCase { slogan: "", color: "#000", imprintUrl: null, + privacyUrl: null, inverted: false, cacheBuster: null }; @@ -912,6 +913,7 @@ class ThemingControllerTest extends TestCase { slogan: "awesome", color: "#ffffff", imprintUrl: null, + privacyUrl: null, inverted: true, cacheBuster: null }; diff --git a/apps/theming/tests/Settings/AdminTest.php b/apps/theming/tests/Settings/AdminTest.php index f1fda94eb2..b5353c82dc 100644 --- a/apps/theming/tests/Settings/AdminTest.php +++ b/apps/theming/tests/Settings/AdminTest.php @@ -80,6 +80,10 @@ class AdminTest extends TestCase { ->expects($this->once()) ->method('getImprintUrl') ->willReturn(''); + $this->themingDefaults + ->expects($this->once()) + ->method('getPrivacyUrl') + ->willReturn(''); $this->themingDefaults ->expects($this->once()) ->method('getSlogan') @@ -108,6 +112,7 @@ class AdminTest extends TestCase { 'canThemeIcons' => null, 'iconDocs' => null, 'imprintUrl' => '', + 'privacyUrl' => '', ]; $expected = new TemplateResponse('theming', 'settings-admin', $params, ''); @@ -137,6 +142,10 @@ class AdminTest extends TestCase { ->expects($this->once()) ->method('getImprintUrl') ->willReturn(''); + $this->themingDefaults + ->expects($this->once()) + ->method('getPrivacyUrl') + ->willReturn(''); $this->themingDefaults ->expects($this->once()) ->method('getSlogan') @@ -165,6 +174,7 @@ class AdminTest extends TestCase { 'canThemeIcons' => null, 'iconDocs' => null, 'imprintUrl' => '', + 'privacyUrl' => '', ]; $expected = new TemplateResponse('theming', 'settings-admin', $params, ''); diff --git a/apps/theming/tests/ThemingDefaultsTest.php b/apps/theming/tests/ThemingDefaultsTest.php index 9c876b2c0d..dd0361dc68 100644 --- a/apps/theming/tests/ThemingDefaultsTest.php +++ b/apps/theming/tests/ThemingDefaultsTest.php @@ -193,16 +193,16 @@ class ThemingDefaultsTest extends TestCase { $this->assertEquals('https://example.com/', $this->template->getBaseUrl()); } - public function imprintUrlProvider() { + public function legalUrlProvider() { return [ [ '' ], - [ 'https://example.com/imprint.html'] + [ 'https://example.com/legal.html'] ]; } /** * @param $imprintUrl - * @dataProvider imprintUrlProvider + * @dataProvider legalUrlProvider */ public function testGetImprintURL($imprintUrl) { $this->config @@ -214,6 +214,20 @@ class ThemingDefaultsTest extends TestCase { $this->assertEquals($imprintUrl, $this->template->getImprintUrl()); } + /** + * @param $privacyUrl + * @dataProvider legalUrlProvider + */ + public function testGetPrivacyURL($privacyUrl) { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'privacyUrl', '') + ->willReturn($privacyUrl); + + $this->assertEquals($privacyUrl, $this->template->getPrivacyUrl()); + } + public function testGetSloganWithDefault() { $this->config ->expects($this->once()) @@ -236,13 +250,14 @@ class ThemingDefaultsTest extends TestCase { public function testGetShortFooter() { $this->config - ->expects($this->exactly(4)) + ->expects($this->exactly(5)) ->method('getAppValue') ->willReturnMap([ ['theming', 'url', $this->defaults->getBaseUrl(), 'url'], ['theming', 'name', 'Nextcloud', 'Name'], ['theming', 'slogan', $this->defaults->getSlogan(), 'Slogan'], ['theming', 'imprintUrl', '', ''], + ['theming', 'privacyUrl', '', ''], ]); $this->assertEquals('Name – Slogan', $this->template->getShortFooter()); @@ -250,13 +265,14 @@ class ThemingDefaultsTest extends TestCase { public function testGetShortFooterEmptySlogan() { $this->config - ->expects($this->exactly(4)) + ->expects($this->exactly(5)) ->method('getAppValue') ->willReturnMap([ ['theming', 'url', $this->defaults->getBaseUrl(), 'url'], ['theming', 'name', 'Nextcloud', 'Name'], ['theming', 'slogan', $this->defaults->getSlogan(), ''], ['theming', 'imprintUrl', '', ''], + ['theming', 'privacyUrl', '', ''], ]); $this->assertEquals('Name', $this->template->getShortFooter()); @@ -264,13 +280,14 @@ class ThemingDefaultsTest extends TestCase { public function testGetShortFooterImprint() { $this->config - ->expects($this->exactly(4)) + ->expects($this->exactly(5)) ->method('getAppValue') ->willReturnMap([ ['theming', 'url', $this->defaults->getBaseUrl(), 'url'], ['theming', 'name', 'Nextcloud', 'Name'], ['theming', 'slogan', $this->defaults->getSlogan(), 'Slogan'], ['theming', 'imprintUrl', '', 'https://example.com/imprint'], + ['theming', 'privacyUrl', '', ''], ]); $this->l10n @@ -281,26 +298,86 @@ class ThemingDefaultsTest extends TestCase { $this->assertEquals('Name – Slogan
Legal notice', $this->template->getShortFooter()); } - public function invalidImprintUrlProvider() { + public function testGetShortFooterPrivacy() { + $this->config + ->expects($this->exactly(5)) + ->method('getAppValue') + ->willReturnMap([ + ['theming', 'url', $this->defaults->getBaseUrl(), 'url'], + ['theming', 'name', 'Nextcloud', 'Name'], + ['theming', 'slogan', $this->defaults->getSlogan(), 'Slogan'], + ['theming', 'imprintUrl', '', ''], + ['theming', 'privacyUrl', '', 'https://example.com/privacy'], + ]); + + $this->l10n + ->expects($this->any()) + ->method('t') + ->willReturnArgument(0); + + $this->assertEquals('Name – Slogan
Privacy policy', $this->template->getShortFooter()); + } + + public function testGetShortFooterAllLegalLinks() { + $this->config + ->expects($this->exactly(5)) + ->method('getAppValue') + ->willReturnMap([ + ['theming', 'url', $this->defaults->getBaseUrl(), 'url'], + ['theming', 'name', 'Nextcloud', 'Name'], + ['theming', 'slogan', $this->defaults->getSlogan(), 'Slogan'], + ['theming', 'imprintUrl', '', 'https://example.com/imprint'], + ['theming', 'privacyUrl', '', 'https://example.com/privacy'], + ]); + + $this->l10n + ->expects($this->any()) + ->method('t') + ->willReturnArgument(0); + + $this->assertEquals('Name – Slogan
Legal notice · Privacy policy', $this->template->getShortFooter()); + } + + public function invalidLegalUrlProvider() { return [ - ['example.com/imprint'], # missing scheme - ['https:///imprint'], # missing host + ['example.com/legal'], # missing scheme + ['https:///legal'], # missing host ]; } /** * @param $invalidImprintUrl - * @dataProvider invalidImprintUrlProvider + * @dataProvider invalidLegalUrlProvider */ public function testGetShortFooterInvalidImprint($invalidImprintUrl) { $this->config - ->expects($this->exactly(4)) + ->expects($this->exactly(5)) ->method('getAppValue') ->willReturnMap([ ['theming', 'url', $this->defaults->getBaseUrl(), 'url'], ['theming', 'name', 'Nextcloud', 'Name'], ['theming', 'slogan', $this->defaults->getSlogan(), 'Slogan'], ['theming', 'imprintUrl', '', $invalidImprintUrl], + ['theming', 'privacyUrl', '', ''], + ]); + + $this->assertEquals('Name – Slogan', $this->template->getShortFooter()); + } + + /** + * @param $invalidPrivacyUrl + * @dataProvider invalidLegalUrlProvider + */ + public function testGetShortFooterInvalidPrivacy($invalidPrivacyUrl) { + $this->config + ->expects($this->exactly(5)) + ->method('getAppValue') + ->willReturnMap([ + ['theming', 'url', $this->defaults->getBaseUrl(), 'url'], + ['theming', 'name', 'Nextcloud', 'Name'], + ['theming', 'slogan', $this->defaults->getSlogan(), 'Slogan'], + ['theming', 'imprintUrl', '', ''], + ['theming', 'privacyUrl', '', $invalidPrivacyUrl], ]); $this->assertEquals('Name – Slogan', $this->template->getShortFooter());