diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-05-24 17:57:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-24 17:57:25 +0200 |
commit | cef2e190a14f5512950308a089c611d85daea56c (patch) | |
tree | 50839f83e3284529e6b3945946e24c8f3379cf3e | |
parent | 5bd9087cb73af5e1a1dfea33e53028c17ba03ce5 (diff) | |
parent | cee2d1783d583496d49b44767994b7cd8b122329 (diff) | |
download | nextcloud-server-cef2e190a14f5512950308a089c611d85daea56c.tar.gz nextcloud-server-cef2e190a14f5512950308a089c611d85daea56c.zip |
Merge pull request #9586 from nextcloud/feature/9577/privacy-link
[stable13] add privacy link to theming and fix scrollbars
-rw-r--r-- | apps/theming/appinfo/info.xml | 2 | ||||
-rw-r--r-- | apps/theming/css/theming.scss | 6 | ||||
-rw-r--r-- | apps/theming/js/settings-admin.js | 13 | ||||
-rw-r--r-- | apps/theming/lib/Controller/ThemingController.php | 11 | ||||
-rw-r--r-- | apps/theming/lib/Settings/Admin.php | 1 | ||||
-rw-r--r-- | apps/theming/lib/ThemingDefaults.php | 45 | ||||
-rw-r--r-- | apps/theming/templates/settings-admin.php | 11 | ||||
-rw-r--r-- | apps/theming/tests/Controller/ThemingControllerTest.php | 2 | ||||
-rw-r--r-- | apps/theming/tests/Settings/AdminTest.php | 10 | ||||
-rw-r--r-- | apps/theming/tests/ThemingDefaultsTest.php | 102 |
10 files changed, 178 insertions, 25 deletions
diff --git a/apps/theming/appinfo/info.xml b/apps/theming/appinfo/info.xml index 6514f8d5bcd..671bb7c5e02 100644 --- a/apps/theming/appinfo/info.xml +++ b/apps/theming/appinfo/info.xml @@ -5,7 +5,7 @@ <description>Adjust the Nextcloud theme</description> <licence>AGPL</licence> <author>Nextcloud</author> - <version>1.4.3</version> + <version>1.4.4</version> <namespace>Theming</namespace> <types> <logging/> diff --git a/apps/theming/css/theming.scss b/apps/theming/css/theming.scss index 3bb26a14814..f67df4937e9 100644 --- a/apps/theming/css/theming.scss +++ b/apps/theming/css/theming.scss @@ -155,3 +155,9 @@ input.primary, border: 1px solid #ebebeb; } } + +@if ($has-legal-links == 'true') { + footer { + height: 92px; + } +} diff --git a/apps/theming/js/settings-admin.js b/apps/theming/js/settings-admin.js index c34da3ff874..a8c45977e3b 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 80eab2b2153..33af0f513aa 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 469d4b3d6a9..a772ab04fe5 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 b2d31b90836..ef2b97ac4b4 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -143,7 +143,11 @@ class ThemingDefaults extends \OC_Defaults { } public function getImprintUrl() { - return $this->config->getAppValue('theming', 'imprintUrl', ''); + return (string)$this->config->getAppValue('theming', 'imprintUrl', ''); + } + + public function getPrivacyUrl() { + return (string)$this->config->getAppValue('theming', 'privacyUrl', ''); } public function getShortFooter() { @@ -152,14 +156,31 @@ class ThemingDefaults extends \OC_Defaults { ' rel="noreferrer noopener">' .$this->getEntity() . '</a>'. ($slogan !== '' ? ' – ' . $slogan : ''); - $imprintUrl = (string)$this->getImprintUrl(); - if($imprintUrl !== '' - && filter_var($imprintUrl, FILTER_VALIDATE_URL, [ - 'flags' => FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED - ]) - ) { - $footer .= '<br/><a href="' . $imprintUrl . '" class="legal" target="_blank"' . - ' rel="noreferrer noopener">' . $this->l->t('Legal notice') . '</a>'; + $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 . '<a href="' . $link['url'] . '" class="legal" target="_blank"' . + ' rel="noreferrer noopener">' . $link['text'] . '</a>'; + $divider = ' · '; + } + } + if($legalLinks !== '' ) { + $footer .= '<br/>' . $legalLinks; } return $footer; @@ -269,6 +290,12 @@ class ThemingDefaults extends \OC_Defaults { if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') { $variables['image-login-plain'] = 'true'; } + + $variables['has-legal-links'] = 'false'; + if($this->getImprintUrl() !== '' || $this->getPrivacyUrl() !== '') { + $variables['has-legal-links'] = 'true'; + } + $cache->set('getScssVariables', $variables); return $variables; } diff --git a/apps/theming/templates/settings-admin.php b/apps/theming/templates/settings-admin.php index 907c8662efe..cf4a1117185 100644 --- a/apps/theming/templates/settings-admin.php +++ b/apps/theming/templates/settings-admin.php @@ -90,11 +90,18 @@ style('theming', 'settings-admin'); </div> <div> <label> - <span><?php p($l->t('Legal notice link')) ?></span> - <input id="theming-imprintUrl" type="text" placeholder="<?php p($l->t('https://…')); ?>" value="<?php p($_['imprintUrl']) ?>" maxlength="500" /> + <span><?php p($l->t('Legal notice link')) ?></span> + <input id="theming-imprintUrl" type="text" placeholder="<?php p($l->t('https://…')); ?>" value="<?php p($_['imprintUrl']) ?>" maxlength="500" /> <div data-setting="imprintUrl" data-toggle="tooltip" data-original-title="<?php p($l->t('Reset to default')); ?>" class="theme-undo icon icon-history"></div> </label> </div> + <div> + <label> + <span><?php p($l->t('Privacy policy link')) ?></span> + <input id="theming-privacyUrl" type="text" placeholder="<?php p($l->t('https://…')); ?>" value="<?php p($_['privacyUrl']) ?>" maxlength="500" /> + <div data-setting="privacyUrl" data-toggle="tooltip" data-original-title="<?php p($l->t('Reset to default')); ?>" class="theme-undo icon icon-history"></div> + </label> + </div> <div class="theming-hints"> <?php if (!$_['canThemeIcons']) { ?> <p class="info"> diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php index 43f3d1aa2ae..44658c11fe2 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 f1fda94eb2d..b5353c82dcd 100644 --- a/apps/theming/tests/Settings/AdminTest.php +++ b/apps/theming/tests/Settings/AdminTest.php @@ -82,6 +82,10 @@ class AdminTest extends TestCase { ->willReturn(''); $this->themingDefaults ->expects($this->once()) + ->method('getPrivacyUrl') + ->willReturn(''); + $this->themingDefaults + ->expects($this->once()) ->method('getSlogan') ->willReturn('MySlogan'); $this->themingDefaults @@ -108,6 +112,7 @@ class AdminTest extends TestCase { 'canThemeIcons' => null, 'iconDocs' => null, 'imprintUrl' => '', + 'privacyUrl' => '', ]; $expected = new TemplateResponse('theming', 'settings-admin', $params, ''); @@ -139,6 +144,10 @@ class AdminTest extends TestCase { ->willReturn(''); $this->themingDefaults ->expects($this->once()) + ->method('getPrivacyUrl') + ->willReturn(''); + $this->themingDefaults + ->expects($this->once()) ->method('getSlogan') ->willReturn('MySlogan'); $this->themingDefaults @@ -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 9c876b2c0d2..912b0315f9b 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('<a href="url" target="_blank" rel="noreferrer noopener">Name</a> – 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('<a href="url" target="_blank" rel="noreferrer noopener">Name</a>', $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('<a href="url" target="_blank" rel="noreferrer noopener">Name</a> – Slogan<br/><a href="https://example.com/imprint" class="legal" target="_blank" rel="noreferrer noopener">Legal notice</a>', $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('<a href="url" target="_blank" rel="noreferrer noopener">Name</a> – Slogan<br/><a href="https://example.com/privacy" class="legal" target="_blank" rel="noreferrer noopener">Privacy policy</a>', $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('<a href="url" target="_blank" rel="noreferrer noopener">Name</a> – Slogan<br/><a href="https://example.com/imprint" class="legal" target="_blank" rel="noreferrer noopener">Legal notice</a> · <a href="https://example.com/privacy" class="legal" target="_blank" rel="noreferrer noopener">Privacy policy</a>', $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('<a href="url" target="_blank" rel="noreferrer noopener">Name</a> – 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('<a href="url" target="_blank" rel="noreferrer noopener">Name</a> – Slogan', $this->template->getShortFooter()); @@ -593,7 +670,8 @@ class ThemingDefaultsTest extends TestCase { 'color-primary' => $this->defaults->getColorPrimary(), 'color-primary-text' => '#ffffff', 'image-login-plain' => 'false', - 'color-primary-element' => '#aaaaaa' + 'color-primary-element' => '#aaaaaa', + 'has-legal-links' => 'false' ]; $this->assertEquals($expected, $this->template->getScssVariables()); |