From 6bb95de1c50208d6cbaf1242f86a2fdab09c2246 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 8 Sep 2016 09:13:59 +0200 Subject: [PATCH 1/4] Adding a optional disclaimer to the anonymous upload page --- apps/files_sharing/css/public.css | 11 +++++ .../lib/Controllers/ShareController.php | 1 + apps/files_sharing/templates/public.php | 5 ++- lib/private/Settings/Admin/Sharing.php | 1 + settings/css/settings.css | 8 ++++ settings/js/admin.js | 41 ++++++++++++++++++- settings/templates/admin/sharing.php | 10 ++++- tests/lib/Settings/Admin/SharingTest.php | 12 ++++++ 8 files changed, 86 insertions(+), 3 deletions(-) diff --git a/apps/files_sharing/css/public.css b/apps/files_sharing/css/public.css index 4c5f847f9ff..3e3d13cebf0 100644 --- a/apps/files_sharing/css/public.css +++ b/apps/files_sharing/css/public.css @@ -168,6 +168,10 @@ thead { margin: 0 auto; } +#emptycontent.has-disclaimer { + margin-top: 10vh; +} + #public-upload #emptycontent h2 { margin: 10px 0 5px 0; } @@ -222,3 +226,10 @@ thead { padding-left: 18px; margin-right: 7px; } + + +.disclaimer { + margin: -20px auto 30px; + max-width: 400px; + text-align: left; +} \ No newline at end of file diff --git a/apps/files_sharing/lib/Controllers/ShareController.php b/apps/files_sharing/lib/Controllers/ShareController.php index cd0d40048cf..5ccaab746fc 100644 --- a/apps/files_sharing/lib/Controllers/ShareController.php +++ b/apps/files_sharing/lib/Controllers/ShareController.php @@ -357,6 +357,7 @@ class ShareController extends Controller { $shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true); $shareTmpl['previewMaxX'] = $this->config->getSystemValue('preview_max_x', 1024); $shareTmpl['previewMaxY'] = $this->config->getSystemValue('preview_max_y', 1024); + $shareTmpl['disclaimer'] = $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null); // Load files we need \OCP\Util::addScript('files', 'file-upload'); diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php index 1b282f04a7a..bdedb04d244 100644 --- a/apps/files_sharing/templates/public.php +++ b/apps/files_sharing/templates/public.php @@ -104,10 +104,13 @@ $maxUploadFilesize = min($upload_max_filesize, $post_max_size);
-
+

t('Upload files to %s', [$_['shareOwner']])) ?>

+ +

+ t('Select or drop files')) ?> diff --git a/lib/private/Settings/Admin/Sharing.php b/lib/private/Settings/Admin/Sharing.php index 8d3ddc9b3b5..59821044605 100644 --- a/lib/private/Settings/Admin/Sharing.php +++ b/lib/private/Settings/Admin/Sharing.php @@ -65,6 +65,7 @@ class Sharing implements ISettings { 'shareEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'), 'shareExcludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes' ? true : false, 'shareExcludedGroupsList' => $excludeGroupsList, + 'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null), ]; return new TemplateResponse('settings', 'admin/sharing', $parameters, ''); diff --git a/settings/css/settings.css b/settings/css/settings.css index 6ed707f7c45..d66b0f82b55 100644 --- a/settings/css/settings.css +++ b/settings/css/settings.css @@ -499,6 +499,14 @@ table.grid td.date{ display: inline-block; } +#publicShareDisclaimerText { + width: calc(100% - 23px); /* 20 px left margin, 3 px right margin */ + max-width: 600px; + height: 150px; + margin-left: 20px; + box-sizing: border-box; +} + /* correctly display help icons next to headings */ .icon-info { padding: 11px 20px; diff --git a/settings/js/admin.js b/settings/js/admin.js index fb59b3ba026..a2a1cef531c 100644 --- a/settings/js/admin.js +++ b/settings/js/admin.js @@ -90,7 +90,7 @@ $(document).ready(function(){ } }); - $('#shareAPI input:not(#excludedGroups)').change(function() { + $('#shareAPI input:not(.noJSAutoUpdate)').change(function() { var value = $(this).val(); if ($(this).attr('type') === 'checkbox') { if (this.checked) { @@ -106,6 +106,45 @@ $(document).ready(function(){ $("#setDefaultExpireDate").toggleClass('hidden', !this.checked); }); + $('#publicShareDisclaimer').change(function() { + $("#publicShareDisclaimerText").toggleClass('hidden', !this.checked); + if(!this.checked) { + savePublicShareDisclaimerText(''); + } + }); + + var savePublicShareDisclaimerText = _.debounce(function(value) { + var data = { + app:'core', + key:'shareapi_public_link_disclaimertext' + }; + if (_.isString(value) && value !== '') { + data['action'] = 'setValue'; + data['value'] = value; + } else { + data['action'] = 'deleteKey'; + $('#publicShareDisclaimerText').val(''); + } + + OC.msg.startSaving('#publicShareDisclaimerStatus'); + $.post( + OC.AppConfig.url, + data, + function(result){ + if(result.status === 'success'){ + OC.msg.finishedSuccess('#publicShareDisclaimerStatus', t('core', 'Saved')) + } else { + OC.msg.finishedError('#publicShareDisclaimerStatus', t('core', 'Not saved')) + } + }, + 'json' + ); + }, 500); + + $('#publicShareDisclaimerText').on('change, keyup', function() { + savePublicShareDisclaimerText(this.value); + }); + $('#allowLinks').change(function() { $("#publicLinkSettings").toggleClass('hidden', !this.checked); $('#setDefaultExpireDate').toggleClass('hidden', !(this.checked && $('#shareapiDefaultExpireDate')[0].checked)); diff --git a/settings/templates/admin/sharing.php b/settings/templates/admin/sharing.php index b8f8e920246..1c47d74770f 100644 --- a/settings/templates/admin/sharing.php +++ b/settings/templates/admin/sharing.php @@ -95,7 +95,7 @@

- +
t('These groups will still be able to receive shares, but not to initiate them.')); ?>

@@ -104,4 +104,12 @@ />

+

+ /> + + +
+ +

diff --git a/tests/lib/Settings/Admin/SharingTest.php b/tests/lib/Settings/Admin/SharingTest.php index 38ab7614d1c..86bbdcbbfb0 100644 --- a/tests/lib/Settings/Admin/SharingTest.php +++ b/tests/lib/Settings/Admin/SharingTest.php @@ -109,6 +109,11 @@ class SharingTest extends TestCase { ->method('getAppValue') ->with('core', 'shareapi_exclude_groups', 'no') ->willReturn('no'); + $this->config + ->expects($this->at(13)) + ->method('getAppValue') + ->with('core', 'shareapi_public_link_disclaimertext', null) + ->willReturn('Lorem ipsum'); $expected = new TemplateResponse( 'settings', @@ -129,6 +134,7 @@ class SharingTest extends TestCase { 'shareEnforceExpireDate' => 'no', 'shareExcludeGroups' => false, 'shareExcludedGroupsList' => '', + 'publicShareDisclaimer' => 'Lorem ipsum', ], '' ); @@ -202,6 +208,11 @@ class SharingTest extends TestCase { ->method('getAppValue') ->with('core', 'shareapi_exclude_groups', 'no') ->willReturn('yes'); + $this->config + ->expects($this->at(13)) + ->method('getAppValue') + ->with('core', 'shareapi_public_link_disclaimertext', null) + ->willReturn('Lorem ipsum'); $expected = new TemplateResponse( 'settings', @@ -222,6 +233,7 @@ class SharingTest extends TestCase { 'shareEnforceExpireDate' => 'no', 'shareExcludeGroups' => true, 'shareExcludedGroupsList' => 'NoSharers|OtherNoSharers', + 'publicShareDisclaimer' => 'Lorem ipsum', ], '' ); From 9a2ae2fe7de25b3b68b3e4c451ea550f59304ae3 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Thu, 8 Sep 2016 20:11:21 +0200 Subject: [PATCH 2/4] Fix tests --- apps/files_sharing/css/public.css | 3 +-- tests/lib/Settings/Admin/SharingTest.php | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/files_sharing/css/public.css b/apps/files_sharing/css/public.css index 3e3d13cebf0..1bb83106543 100644 --- a/apps/files_sharing/css/public.css +++ b/apps/files_sharing/css/public.css @@ -227,9 +227,8 @@ thead { margin-right: 7px; } - .disclaimer { margin: -20px auto 30px; max-width: 400px; text-align: left; -} \ No newline at end of file +} diff --git a/tests/lib/Settings/Admin/SharingTest.php b/tests/lib/Settings/Admin/SharingTest.php index 86bbdcbbfb0..d0cda5308f5 100644 --- a/tests/lib/Settings/Admin/SharingTest.php +++ b/tests/lib/Settings/Admin/SharingTest.php @@ -134,7 +134,7 @@ class SharingTest extends TestCase { 'shareEnforceExpireDate' => 'no', 'shareExcludeGroups' => false, 'shareExcludedGroupsList' => '', - 'publicShareDisclaimer' => 'Lorem ipsum', + 'publicShareDisclaimerText' => 'Lorem ipsum', ], '' ); @@ -233,7 +233,7 @@ class SharingTest extends TestCase { 'shareEnforceExpireDate' => 'no', 'shareExcludeGroups' => true, 'shareExcludedGroupsList' => 'NoSharers|OtherNoSharers', - 'publicShareDisclaimer' => 'Lorem ipsum', + 'publicShareDisclaimerText' => 'Lorem ipsum', ], '' ); From 404b212b87457429b441911abc3e38699ab6eae7 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Thu, 8 Sep 2016 20:11:54 +0200 Subject: [PATCH 3/4] Use l10n --- settings/templates/admin/sharing.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings/templates/admin/sharing.php b/settings/templates/admin/sharing.php index 1c47d74770f..802bcad3198 100644 --- a/settings/templates/admin/sharing.php +++ b/settings/templates/admin/sharing.php @@ -110,6 +110,6 @@
- +

From 268c5a0aa010cda1438a32fbbd9d433ebc555902 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Thu, 8 Sep 2016 20:34:04 +0200 Subject: [PATCH 4/4] Adjust test --- .../tests/Controllers/ShareControllerTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/tests/Controllers/ShareControllerTest.php b/apps/files_sharing/tests/Controllers/ShareControllerTest.php index 34ed08629af..1b9fd401f78 100644 --- a/apps/files_sharing/tests/Controllers/ShareControllerTest.php +++ b/apps/files_sharing/tests/Controllers/ShareControllerTest.php @@ -357,6 +357,11 @@ class ShareControllerTest extends \Test\TestCase { ->method('getShareByToken') ->with('token') ->willReturn($share); + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('core', 'shareapi_public_link_disclaimertext', null) + ->willReturn('My disclaimer text'); $this->userManager->method('get')->with('ownerUID')->willReturn($owner); @@ -385,7 +390,8 @@ class ShareControllerTest extends \Test\TestCase { 'previewMaxX' => 1024, 'previewMaxY' => 1024, 'hideFileList' => false, - 'shareOwner' => 'ownerDisplay' + 'shareOwner' => 'ownerDisplay', + 'disclaimer' => 'My disclaimer text', ); $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();