Skip to content

Commit

Permalink
Merge pull request #4093 from nextcloud/endorse-password-protection
Browse files Browse the repository at this point in the history
Endorse password protection
  • Loading branch information
rullzer authored Apr 4, 2017
2 parents 0d69b52 + 5e7197e commit efb21a9
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
1 change: 1 addition & 0 deletions core/js/shareconfigmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
defaults: {
publicUploadEnabled: false,
enforcePasswordForPublicLink: oc_appconfig.core.enforcePasswordForPublicLink,
enableLinkPasswordByDefault: oc_appconfig.core.enableLinkPasswordByDefault,
isDefaultExpireDateEnforced: oc_appconfig.core.defaultExpireDateEnforced === true,
isDefaultExpireDateEnabled: oc_appconfig.core.defaultExpireDateEnabled === true,
isRemoteShareAllowed: oc_appconfig.core.remoteShareAllowed,
Expand Down
26 changes: 22 additions & 4 deletions core/js/sharedialoglinkshareview.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

var PASSWORD_PLACEHOLDER = '**********';
var PASSWORD_PLACEHOLDER_MESSAGE = t('core', 'Choose a password for the public link');
var PASSWORD_PLACEHOLDER_MESSAGE_OPTIONAL = t('core', 'Choose a password for the public link or press enter');

var TEMPLATE =
'{{#if shareAllowed}}' +
Expand Down Expand Up @@ -61,7 +62,11 @@
' {{/if}}' +
'<div id="linkPass" class="linkPass {{#unless isPasswordSet}}hidden{{/unless}}">' +
' <label for="linkPassText-{{cid}}" class="hidden-visually">{{passwordLabel}}</label>' +
' {{#if showPasswordCheckBox}}' +
' <input id="linkPassText-{{cid}}" class="linkPassText" type="password" placeholder="{{passwordPlaceholder}}" />' +
' {{else}}' +
' <input id="linkPassText-{{cid}}" class="linkPassText" type="password" placeholder="{{passwordPlaceholderInitial}}" />' +
' {{/if}}' +
' <span class="icon-loading-small hidden"></span>' +
'</div>' +
'{{else}}' +
Expand Down Expand Up @@ -228,7 +233,7 @@
}

if($checkBox.is(':checked')) {
if(this.configModel.get('enforcePasswordForPublicLink') === false) {
if(this.configModel.get('enforcePasswordForPublicLink') === false && this.configModel.get('enableLinkPasswordByDefault') === false) {
$loading.removeClass('hidden');
// this will create it
this.model.saveLinkShare();
Expand Down Expand Up @@ -280,9 +285,19 @@
var $input = this.$el.find('.linkPassText');
$input.removeClass('error');
var password = $input.val();
// in IE9 the password might be the placeholder due to bugs in the placeholders polyfill
if(password === '' || password === PASSWORD_PLACEHOLDER || password === PASSWORD_PLACEHOLDER_MESSAGE) {
return;

if (this.$el.find('.linkPassText').attr('placeholder') === PASSWORD_PLACEHOLDER_MESSAGE_OPTIONAL) {

// in IE9 the password might be the placeholder due to bugs in the placeholders polyfill
if(password === PASSWORD_PLACEHOLDER_MESSAGE_OPTIONAL) {
password = '';
}
} else {

// in IE9 the password might be the placeholder due to bugs in the placeholders polyfill
if(password === '' || password === PASSWORD_PLACEHOLDER || password === PASSWORD_PLACEHOLDER_MESSAGE) {
return;
}
}

$loading
Expand Down Expand Up @@ -391,6 +406,8 @@
var showPasswordCheckBox = isLinkShare
&& ( !this.configModel.get('enforcePasswordForPublicLink')
|| !this.model.get('linkShare').password);
var passwordPlaceholderInitial = this.configModel.get('enforcePasswordForPublicLink')
? PASSWORD_PLACEHOLDER_MESSAGE : PASSWORD_PLACEHOLDER_MESSAGE_OPTIONAL;

var publicEditable =
!this.model.isFolder()
Expand Down Expand Up @@ -428,6 +445,7 @@
enablePasswordLabel: t('core', 'Password protect'),
passwordLabel: t('core', 'Password'),
passwordPlaceholder: isPasswordSet ? PASSWORD_PLACEHOLDER : PASSWORD_PLACEHOLDER_MESSAGE,
passwordPlaceholderInitial: passwordPlaceholderInitial,
isPasswordSet: isPasswordSet,
showPasswordCheckBox: showPasswordCheckBox,
publicUpload: publicUpload && isLinkShare,
Expand Down
1 change: 1 addition & 0 deletions lib/private/Settings/Admin/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function getForm() {
'shareExcludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes' ? true : false,
'shareExcludedGroupsList' => $excludeGroupsList,
'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null),
'enableLinkPasswordByDefault' => $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'),
];

return new TemplateResponse('settings', 'admin/sharing', $parameters, '');
Expand Down
4 changes: 4 additions & 0 deletions lib/private/Template/JSConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public function getConfig() {
$apps_paths[$app] = \OC_App::getAppWebPath($app);
}


$enableLinkPasswordByDefault = $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no');
$enableLinkPasswordByDefault = ($enableLinkPasswordByDefault === 'yes') ? true : false;
$defaultExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes';
$defaultExpireDate = $enforceDefaultExpireDate = null;
if ($defaultExpireDateEnabled) {
Expand Down Expand Up @@ -217,6 +220,7 @@ public function getConfig() {
'defaultExpireDate' => $defaultExpireDate,
'defaultExpireDateEnforced' => $enforceDefaultExpireDate,
'enforcePasswordForPublicLink' => \OCP\Util::isPublicLinkPasswordRequired(),
'enableLinkPasswordByDefault' => $enableLinkPasswordByDefault,
'sharingDisabledForUser' => \OCP\Util::isSharingDisabledForUser(),
'resharingAllowed' => \OCP\Share::isResharingAllowed(),
'remoteShareAllowed' => $outgoingServer2serverShareEnabled,
Expand Down
4 changes: 3 additions & 1 deletion settings/templates/admin/sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
<input type="checkbox" name="shareapi_allow_public_upload" id="allowPublicUpload" class="checkbox"
value="1" <?php if ($_['allowPublicUpload'] == 'yes') print_unescaped('checked="checked"'); ?> />
<label for="allowPublicUpload"><?php p($l->t('Allow public uploads'));?></label><br/>

<input type="checkbox" name="shareapi_enable_link_password_by_default" id="enableLinkPasswordByDefault" class="checkbox"
value="1" <?php if ($_['enableLinkPasswordByDefault'] === 'yes') print_unescaped('checked="checked"'); ?> />
<label for="enableLinkPasswordByDefault"><?php p($l->t('Always ask for a password'));?></label><br/>
<input type="checkbox" name="shareapi_enforce_links_password" id="enforceLinkPassword" class="checkbox"
value="1" <?php if ($_['enforceLinkPassword']) print_unescaped('checked="checked"'); ?> />
<label for="enforceLinkPassword"><?php p($l->t('Enforce password protection'));?></label><br/>
Expand Down
16 changes: 14 additions & 2 deletions tests/lib/Settings/Admin/SharingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public function testGetFormWithoutExcludedGroups() {
->method('getAppValue')
->with('core', 'shareapi_public_link_disclaimertext', null)
->willReturn('Lorem ipsum');
$this->config
->expects($this->at(12))
->method('getAppValue')
->with('core', 'shareapi_enable_link_password_by_default', 'no')
->willReturn('yes');

$expected = new TemplateResponse(
'settings',
Expand All @@ -122,7 +127,8 @@ public function testGetFormWithoutExcludedGroups() {
'shareEnforceExpireDate' => 'no',
'shareExcludeGroups' => false,
'shareExcludedGroupsList' => '',
'publicShareDisclaimerText' => 'Lorem ipsum',
'publicShareDisclaimerText' => 'Lorem ipsum',
'enableLinkPasswordByDefault' => 'yes'
],
''
);
Expand Down Expand Up @@ -191,6 +197,11 @@ public function testGetFormWithExcludedGroups() {
->method('getAppValue')
->with('core', 'shareapi_public_link_disclaimertext', null)
->willReturn('Lorem ipsum');
$this->config
->expects($this->at(12))
->method('getAppValue')
->with('core', 'shareapi_enable_link_password_by_default', 'no')
->willReturn('yes');

$expected = new TemplateResponse(
'settings',
Expand All @@ -209,7 +220,8 @@ public function testGetFormWithExcludedGroups() {
'shareEnforceExpireDate' => 'no',
'shareExcludeGroups' => true,
'shareExcludedGroupsList' => 'NoSharers|OtherNoSharers',
'publicShareDisclaimerText' => 'Lorem ipsum',
'publicShareDisclaimerText' => 'Lorem ipsum',
'enableLinkPasswordByDefault' => 'yes'
],
''
);
Expand Down

0 comments on commit efb21a9

Please sign in to comment.