add share permissions to settings page
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
This commit is contained in:
parent
7d0102bf73
commit
1615312bf1
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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, '');
|
||||
|
|
|
@ -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') {
|
||||
|
|
|
@ -1030,6 +1030,13 @@ table.grid td.date {
|
|||
.double-indent {
|
||||
padding-left: 56px;
|
||||
}
|
||||
.nocheckbox {
|
||||
padding-left: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
#shareApiDefaultPermissionsSection label {
|
||||
margin-right: 20px;
|
||||
}
|
||||
|
||||
#fileSharingSettings h3 {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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"'); ?> />
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue