aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern Schiessle <bjoern@schiessle.org>2017-12-01 11:35:01 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2018-02-27 12:29:25 +0100
commit1615312bf1044dcbd98c7e4739467314ada618cf (patch)
tree9788f5cb7fe746078953cafadf78e3b2e845d52b
parent7d0102bf7302a483209e0d1c926260713f0e56c6 (diff)
downloadnextcloud-server-1615312bf1044dcbd98c7e4739467314ada618cf.tar.gz
nextcloud-server-1615312bf1044dcbd98c7e4739467314ada618cf.zip
add share permissions to settings page
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
-rw-r--r--apps/files_sharing/lib/Capabilities.php2
-rw-r--r--core/js/shareitemmodel.js17
-rw-r--r--lib/private/Settings/Admin/Sharing.php63
-rw-r--r--lib/private/Settings/Manager.php2
-rw-r--r--settings/css/settings.scss7
-rw-r--r--settings/js/admin.js22
-rw-r--r--settings/templates/settings/admin/sharing.php12
-rw-r--r--tests/lib/Settings/Admin/SharingTest.php7
-rw-r--r--tests/lib/Settings/ManagerTest.php2
9 files changed, 107 insertions, 27 deletions
diff --git a/apps/files_sharing/lib/Capabilities.php b/apps/files_sharing/lib/Capabilities.php
index af41add250c..ce10c8df8a1 100644
--- a/apps/files_sharing/lib/Capabilities.php
+++ b/apps/files_sharing/lib/Capabilities.php
@@ -23,6 +23,7 @@
namespace OCA\Files_Sharing;
use OCP\Capabilities\ICapability;
+use OCP\Constants;
use \OCP\IConfig;
/**
@@ -86,6 +87,7 @@ class Capabilities implements ICapability {
$res['group'] = [];
$res['group']['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes';
$res['group']['expire_date']['enabled'] = true;
+ $res['default_permissions'] = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL);
}
//Federated sharing
diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js
index b699513c734..e7824aca33a 100644
--- a/core/js/shareitemmodel.js
+++ b/core/js/shareitemmodel.js
@@ -158,23 +158,24 @@
var shareType = attributes.shareType;
attributes = _.extend({}, attributes);
- // Default permissions are Edit (CRUD) and Share
- // Check if these permissions are possible
- var permissions = OC.PERMISSION_READ;
+ // get default permissions
+ var defaultPermissions = OC.getCapabilities()['files_sharing']['default_permissions'] || OC.PERMISSION_ALL;
+ var possiblePermissions = OC.PERMISSION_READ;
+
if (this.updatePermissionPossible()) {
- permissions = permissions | OC.PERMISSION_UPDATE;
+ possiblePermissions = possiblePermissions | OC.PERMISSION_UPDATE;
}
if (this.createPermissionPossible()) {
- permissions = permissions | OC.PERMISSION_CREATE;
+ possiblePermissions = possiblePermissions | OC.PERMISSION_CREATE;
}
if (this.deletePermissionPossible()) {
- permissions = permissions | OC.PERMISSION_DELETE;
+ possiblePermissions = possiblePermissions | OC.PERMISSION_DELETE;
}
if (this.configModel.get('isResharingAllowed') && (this.sharePermissionPossible())) {
- permissions = permissions | OC.PERMISSION_SHARE;
+ possiblePermissions = possiblePermissions | OC.PERMISSION_SHARE;
}
- attributes.permissions = permissions;
+ attributes.permissions = defaultPermissions & possiblePermissions;
if (_.isUndefined(attributes.path)) {
attributes.path = this.fileInfoModel.getFullPath();
}
diff --git a/lib/private/Settings/Admin/Sharing.php b/lib/private/Settings/Admin/Sharing.php
index dbdacf78dab..7b60efdc67b 100644
--- a/lib/private/Settings/Admin/Sharing.php
+++ b/lib/private/Settings/Admin/Sharing.php
@@ -28,7 +28,9 @@ namespace OC\Settings\Admin;
use OC\Share\Share;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\Constants;
use OCP\IConfig;
+use OCP\IL10N;
use OCP\Settings\ISettings;
use OCP\Util;
@@ -36,11 +38,15 @@ class Sharing implements ISettings {
/** @var IConfig */
private $config;
+ /** @var IL10N */
+ private $l;
+
/**
* @param IConfig $config
*/
- public function __construct(IConfig $config) {
+ public function __construct(IConfig $config, IL10N $l) {
$this->config = $config;
+ $this->l = $l;
}
/**
@@ -51,23 +57,48 @@ class Sharing implements ISettings {
$excludeGroupsList = !is_null(json_decode($excludedGroups))
? implode('|', json_decode($excludedGroups, true)) : '';
+ $permList = [
+ [
+ 'id' => 'cancreate',
+ 'label' => $this->l->t('Create'),
+ 'value' => Constants::PERMISSION_CREATE
+ ],
+ [
+ 'id' => 'canupdate',
+ 'label' => $this->l->t('Change'),
+ 'value' => Constants::PERMISSION_UPDATE
+ ],
+ [
+ 'id' => 'candelete',
+ 'label' => $this->l->t('Delete'),
+ 'value' => Constants::PERMISSION_DELETE
+ ],
+ [
+ 'id' => 'canshare',
+ 'label' => $this->l->t('Share'),
+ 'value' => Constants::PERMISSION_SHARE
+ ],
+ ];
+
$parameters = [
// Built-In Sharing
- 'allowGroupSharing' => $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'),
- 'allowLinks' => $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'),
- 'allowPublicUpload' => $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes'),
- 'allowResharing' => $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes'),
- 'allowShareDialogUserEnumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'),
- 'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(),
- 'onlyShareWithGroupMembers' => Share::shareWithGroupMembersOnly(),
- 'shareAPIEnabled' => $this->config->getAppValue('core', 'shareapi_enabled', 'yes'),
- 'shareDefaultExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no'),
- 'shareExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'),
- 'shareEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'),
- 'shareExcludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes',
- 'shareExcludedGroupsList' => $excludeGroupsList,
- 'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null),
- 'enableLinkPasswordByDefault' => $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'),
+ 'allowGroupSharing' => $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'),
+ 'allowLinks' => $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'),
+ 'allowPublicUpload' => $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes'),
+ 'allowResharing' => $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes'),
+ 'allowShareDialogUserEnumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'),
+ 'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(),
+ 'onlyShareWithGroupMembers' => Share::shareWithGroupMembersOnly(),
+ 'shareAPIEnabled' => $this->config->getAppValue('core', 'shareapi_enabled', 'yes'),
+ 'shareDefaultExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no'),
+ 'shareExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'),
+ 'shareEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'),
+ 'shareExcludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes',
+ 'shareExcludedGroupsList' => $excludeGroupsList,
+ 'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null),
+ 'enableLinkPasswordByDefault' => $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'),
+ 'shareApiDefaultPermissions' => $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL),
+ 'shareApiDefaultPermissionsCheckboxes' => $permList,
];
return new TemplateResponse('settings', 'settings/admin/sharing', $parameters, '');
diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php
index 387460852ab..7111511eca2 100644
--- a/lib/private/Settings/Manager.php
+++ b/lib/private/Settings/Manager.php
@@ -271,7 +271,7 @@ class Manager implements IManager {
}
if ($section === 'sharing') {
/** @var ISettings $form */
- $form = new Admin\Sharing($this->config);
+ $form = new Admin\Sharing($this->config, $this->l);
$forms[$form->getPriority()] = [$form];
}
if ($section === 'additional') {
diff --git a/settings/css/settings.scss b/settings/css/settings.scss
index 05d62423d17..611961b1065 100644
--- a/settings/css/settings.scss
+++ b/settings/css/settings.scss
@@ -1030,6 +1030,13 @@ table.grid td.date {
.double-indent {
padding-left: 56px;
}
+ .nocheckbox {
+ padding-left: 20px;
+ }
+}
+
+#shareApiDefaultPermissionsSection label {
+ margin-right: 20px;
}
#fileSharingSettings h3 {
diff --git a/settings/js/admin.js b/settings/js/admin.js
index 177f6d3f7f4..f637cb64592 100644
--- a/settings/js/admin.js
+++ b/settings/js/admin.js
@@ -121,6 +121,28 @@ $(document).ready(function(){
}
});
+ $('#shareApiDefaultPermissionsSection input').change(function(ev) {
+ var $el = $('#shareApiDefaultPermissions');
+ var $target = $(ev.target);
+
+ var value = $el.val();
+ if ($target.is(':checked')) {
+ value = value | $target.val();
+ } else {
+ value = value & ~$target.val();
+ }
+
+ // always set read permission
+ value |= OC.PERMISSION_READ;
+
+ // this will trigger the field's change event and will save it
+ $el.val(value).change();
+
+ ev.preventDefault();
+
+ return false;
+ });
+
var savePublicShareDisclaimerText = _.debounce(function(value) {
var options = {
success: function() {
diff --git a/settings/templates/settings/admin/sharing.php b/settings/templates/settings/admin/sharing.php
index 156e8ddd81d..1f8e72910c4 100644
--- a/settings/templates/settings/admin/sharing.php
+++ b/settings/templates/settings/admin/sharing.php
@@ -78,6 +78,18 @@
value="1" <?php if ($_['allowGroupSharing'] === 'yes') print_unescaped('checked="checked"'); ?> />
<label for="allowGroupSharing"><?php p($l->t('Allow sharing with groups'));?></label><br />
</p>
+ <p class="nocheckbox <?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>">
+ <input type="hidden" name="shareapi_default_permissions" id="shareApiDefaultPermissions" class="checkbox"
+ value="<?php p($_['shareApiDefaultPermissions']) ?>" />
+ <?php p($l->t('Default user and group share permissions'));?>
+ </p>
+ <p id="shareApiDefaultPermissionsSection" class="indent <?php if ($_['shareAPIEnabled'] === 'no') p('hidden'); ?>">
+ <?php foreach ($_['shareApiDefaultPermissionsCheckboxes'] as $perm): ?>
+ <input type="checkbox" name="shareapi_default_permission_<?php p($perm['id']) ?>" id="shareapi_default_permission_<?php p($perm['id']) ?>"
+ class="noautosave checkbox" value="<?php p($perm['value']) ?>" <?php if (($_['shareApiDefaultPermissions'] & $perm['value']) !== 0) print_unescaped('checked="checked"'); ?> />
+ <label for="shareapi_default_permission_<?php p($perm['id']) ?>"><?php p($perm['label']);?></label>
+ <?php endforeach ?>
+ </p>
<p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>">
<input type="checkbox" name="shareapi_only_share_with_group_members" id="onlyShareWithGroupMembers" class="checkbox"
value="1" <?php if ($_['onlyShareWithGroupMembers']) print_unescaped('checked="checked"'); ?> />
diff --git a/tests/lib/Settings/Admin/SharingTest.php b/tests/lib/Settings/Admin/SharingTest.php
index 9498a1466d3..ee60979b96d 100644
--- a/tests/lib/Settings/Admin/SharingTest.php
+++ b/tests/lib/Settings/Admin/SharingTest.php
@@ -26,6 +26,7 @@ namespace Test\Settings\Admin;
use OC\Settings\Admin\Sharing;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
+use OCP\IL10N;
use Test\TestCase;
class SharingTest extends TestCase {
@@ -33,13 +34,17 @@ class SharingTest extends TestCase {
private $admin;
/** @var IConfig */
private $config;
+ /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
+ private $l10n;
public function setUp() {
parent::setUp();
$this->config = $this->getMockBuilder(IConfig::class)->getMock();
+ $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
$this->admin = new Sharing(
- $this->config
+ $this->config,
+ $this->l10n
);
}
diff --git a/tests/lib/Settings/ManagerTest.php b/tests/lib/Settings/ManagerTest.php
index 577abc7915c..b218a347e85 100644
--- a/tests/lib/Settings/ManagerTest.php
+++ b/tests/lib/Settings/ManagerTest.php
@@ -209,7 +209,7 @@ class ManagerTest extends TestCase {
public function testGetAdminSettings() {
$this->assertEquals([
- 0 => [new Sharing($this->config)],
+ 0 => [new Sharing($this->config, $this->l10n)],
], $this->manager->getAdminSettings('sharing'));
}