diff --git a/apps/files_sharing/lib/Capabilities.php b/apps/files_sharing/lib/Capabilities.php
index af41add250c92..ce10c8df8a16b 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 @@ public function getCapabilities() {
$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/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index 990571b778f91..1e121d8c868d3 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -35,8 +35,10 @@
use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
+use OCP\Constants;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
+use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IUserManager;
@@ -75,6 +77,8 @@ class ShareAPIController extends OCSController {
private $l;
/** @var \OCP\Files\Node */
private $lockedNode;
+ /** @var IConfig */
+ private $config;
/**
* Share20OCS constructor.
@@ -88,6 +92,7 @@ class ShareAPIController extends OCSController {
* @param IURLGenerator $urlGenerator
* @param string $userId
* @param IL10N $l10n
+ * @param IConfig $config
*/
public function __construct(
$appName,
@@ -98,7 +103,8 @@ public function __construct(
IRootFolder $rootFolder,
IURLGenerator $urlGenerator,
$userId,
- IL10N $l10n
+ IL10N $l10n,
+ IConfig $config
) {
parent::__construct($appName, $request);
@@ -110,6 +116,7 @@ public function __construct(
$this->urlGenerator = $urlGenerator;
$this->currentUser = $userId;
$this->l = $l10n;
+ $this->config = $config;
}
/**
@@ -318,7 +325,7 @@ public function deleteShare($id) {
*/
public function createShare(
$path = null,
- $permissions = \OCP\Constants::PERMISSION_ALL,
+ $permissions = null,
$shareType = -1,
$shareWith = null,
$publicUpload = 'false',
@@ -327,6 +334,10 @@ public function createShare(
) {
$share = $this->shareManager->newShare();
+ if ($permissions === null) {
+ $permissions = $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL);
+ }
+
// Verify path
if ($path === null) {
throw new OCSNotFoundException($this->l->t('Please specify a file or folder path'));
@@ -347,17 +358,17 @@ public function createShare(
throw new OCSNotFoundException($this->l->t('Could not create share'));
}
- if ($permissions < 0 || $permissions > \OCP\Constants::PERMISSION_ALL) {
+ if ($permissions < 0 || $permissions > Constants::PERMISSION_ALL) {
throw new OCSNotFoundException($this->l->t('invalid permissions'));
}
// Shares always require read permissions
- $permissions |= \OCP\Constants::PERMISSION_READ;
+ $permissions |= Constants::PERMISSION_READ;
if ($path instanceof \OCP\Files\File) {
// Single file shares should never have delete or create permissions
- $permissions &= ~\OCP\Constants::PERMISSION_DELETE;
- $permissions &= ~\OCP\Constants::PERMISSION_CREATE;
+ $permissions &= ~Constants::PERMISSION_DELETE;
+ $permissions &= ~Constants::PERMISSION_CREATE;
}
/*
@@ -414,13 +425,13 @@ public function createShare(
}
$share->setPermissions(
- \OCP\Constants::PERMISSION_READ |
- \OCP\Constants::PERMISSION_CREATE |
- \OCP\Constants::PERMISSION_UPDATE |
- \OCP\Constants::PERMISSION_DELETE
+ Constants::PERMISSION_READ |
+ Constants::PERMISSION_CREATE |
+ Constants::PERMISSION_UPDATE |
+ Constants::PERMISSION_DELETE
);
} else {
- $share->setPermissions(\OCP\Constants::PERMISSION_READ);
+ $share->setPermissions(Constants::PERMISSION_READ);
}
// Set password
@@ -447,13 +458,9 @@ public function createShare(
$share->setPermissions($permissions);
} else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) {
if ($share->getNodeType() === 'file') {
- $share->setPermissions(\OCP\Constants::PERMISSION_READ);
+ $share->setPermissions(Constants::PERMISSION_READ);
} else {
- $share->setPermissions(
- \OCP\Constants::PERMISSION_READ |
- \OCP\Constants::PERMISSION_CREATE |
- \OCP\Constants::PERMISSION_UPDATE |
- \OCP\Constants::PERMISSION_DELETE);
+ $share->setPermissions($permissions);
}
$share->setSharedWith($shareWith);
} else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) {
@@ -698,23 +705,23 @@ public function updateShare(
$newPermissions = null;
if ($publicUpload === 'true') {
- $newPermissions = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE;
+ $newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE;
} else if ($publicUpload === 'false') {
- $newPermissions = \OCP\Constants::PERMISSION_READ;
+ $newPermissions = Constants::PERMISSION_READ;
}
if ($permissions !== null) {
$newPermissions = (int)$permissions;
- $newPermissions = $newPermissions & ~\OCP\Constants::PERMISSION_SHARE;
+ $newPermissions = $newPermissions & ~Constants::PERMISSION_SHARE;
}
if ($newPermissions !== null &&
!in_array($newPermissions, [
- \OCP\Constants::PERMISSION_READ,
- \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE, // legacy
- \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE, // correct
- \OCP\Constants::PERMISSION_CREATE, // hidden file list
- \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE, // allow to edit single files
+ Constants::PERMISSION_READ,
+ Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE, // legacy
+ Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE, // correct
+ Constants::PERMISSION_CREATE, // hidden file list
+ Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE, // allow to edit single files
])
) {
throw new OCSBadRequestException($this->l->t('Can\'t change permissions for public share links'));
@@ -722,9 +729,9 @@ public function updateShare(
if (
// legacy
- $newPermissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE) ||
+ $newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE) ||
// correct
- $newPermissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE)
+ $newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
) {
if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator'));
@@ -735,7 +742,7 @@ public function updateShare(
}
// normalize to correct public upload permissions
- $newPermissions = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE;
+ $newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE;
}
if ($newPermissions !== null) {
diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php
index 6d8e2dd8d844e..d7bc169bf4ae4 100644
--- a/apps/files_sharing/tests/ApiTest.php
+++ b/apps/files_sharing/tests/ApiTest.php
@@ -37,6 +37,7 @@
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\AppFramework\OCS\OCSNotFoundException;
+use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
@@ -105,6 +106,7 @@ private function createOCS($userId) {
->will($this->returnCallback(function($text, $parameters = []) {
return vsprintf($text, $parameters);
}));
+ $config = $this->createMock(IConfig::class);
return new ShareAPIController(
self::APP_NAME,
@@ -115,7 +117,8 @@ private function createOCS($userId) {
\OC::$server->getRootFolder(),
\OC::$server->getURLGenerator(),
$userId,
- $l
+ $l,
+ $config
);
}
diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
index c438dac252159..a475474e3cf13 100644
--- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
@@ -31,6 +31,7 @@
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\Storage;
+use OCP\IConfig;
use OCP\IL10N;
use OCA\Files_Sharing\Controller\ShareAPIController;
use OCP\Files\NotFoundException;
@@ -84,6 +85,9 @@ class ShareAPIControllerTest extends TestCase {
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
private $l;
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
+ private $config;
+
protected function setUp() {
$this->shareManager = $this->createMock(IManager::class);
$this->shareManager
@@ -102,6 +106,7 @@ protected function setUp() {
->will($this->returnCallback(function($text, $parameters = []) {
return vsprintf($text, $parameters);
}));
+ $this->config = $this->createMock(IConfig::class);
$this->ocs = new ShareAPIController(
$this->appName,
@@ -112,7 +117,8 @@ protected function setUp() {
$this->rootFolder,
$this->urlGenerator,
$this->currentUser,
- $this->l
+ $this->l,
+ $this->config
);
}
@@ -131,6 +137,7 @@ private function mockFormatShare() {
$this->urlGenerator,
$this->currentUser,
$this->l,
+ $this->config
])->setMethods(['formatShare'])
->getMock();
}
@@ -439,6 +446,7 @@ public function testGetShare(\OCP\Share\IShare $share, array $result) {
$this->urlGenerator,
$this->currentUser,
$this->l,
+ $this->config
])->setMethods(['canAccessShare'])
->getMock();
@@ -707,6 +715,7 @@ public function testCreateShareUser() {
$this->urlGenerator,
$this->currentUser,
$this->l,
+ $this->config
])->setMethods(['formatShare'])
->getMock();
@@ -804,6 +813,7 @@ public function testCreateShareGroup() {
$this->urlGenerator,
$this->currentUser,
$this->l,
+ $this->config
])->setMethods(['formatShare'])
->getMock();
@@ -1119,6 +1129,7 @@ public function testCreateReshareOfFederatedMountNoDeletePermissions() {
$this->urlGenerator,
$this->currentUser,
$this->l,
+ $this->config
])->setMethods(['formatShare'])
->getMock();
diff --git a/core/Controller/OCJSController.php b/core/Controller/OCJSController.php
index 8db26dd3d382f..37fe17c8dd163 100644
--- a/core/Controller/OCJSController.php
+++ b/core/Controller/OCJSController.php
@@ -26,6 +26,7 @@
namespace OC\Core\Controller;
use bantu\IniGetWrapper\IniGetWrapper;
+use OC\CapabilitiesManager;
use OC\Template\JSConfigHelper;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
@@ -59,6 +60,7 @@ class OCJSController extends Controller {
* @param IGroupManager $groupManager
* @param IniGetWrapper $iniWrapper
* @param IURLGenerator $urlGenerator
+ * @param CapabilitiesManager $capabilitiesManager
*/
public function __construct($appName,
IRequest $request,
@@ -70,7 +72,8 @@ public function __construct($appName,
IConfig $config,
IGroupManager $groupManager,
IniGetWrapper $iniWrapper,
- IURLGenerator $urlGenerator) {
+ IURLGenerator $urlGenerator,
+ CapabilitiesManager $capabilitiesManager) {
parent::__construct($appName, $request);
$this->helper = new JSConfigHelper(
@@ -82,7 +85,8 @@ public function __construct($appName,
$config,
$groupManager,
$iniWrapper,
- $urlGenerator
+ $urlGenerator,
+ $capabilitiesManager
);
}
diff --git a/core/js/js.js b/core/js/js.js
index 9b8829de25041..fa92508ff7ad0 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -80,6 +80,13 @@ var OCP = {},
*/
webroot:oc_webroot,
+ /**
+ * Capabilities
+ *
+ * @type array
+ */
+ _capabilities: window.oc_capabilities || null,
+
appswebroots:(typeof oc_appswebroots !== 'undefined') ? oc_appswebroots:false,
/**
* Currently logged in user or null if none
@@ -308,6 +315,18 @@ var OCP = {},
return OC.webroot;
},
+
+ /**
+ * Returns the capabilities
+ *
+ * @return {array} capabilities
+ *
+ * @since 14.0
+ */
+ getCapabilities: function() {
+ return OC._capabilities;
+ },
+
/**
* Returns the currently logged in user or null if there is no logged in
* user (public page mode)
diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js
index b699513c73488..e7824aca33a15 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/core/js/tests/specs/shareitemmodelSpec.js b/core/js/tests/specs/shareitemmodelSpec.js
index 3b17051508e6e..0a345786b7347 100644
--- a/core/js/tests/specs/shareitemmodelSpec.js
+++ b/core/js/tests/specs/shareitemmodelSpec.js
@@ -25,6 +25,7 @@ describe('OC.Share.ShareItemModel', function() {
var fetchSharesDeferred, fetchReshareDeferred;
var fileInfoModel, configModel, model;
var oldCurrentUser;
+ var capsSpec;
beforeEach(function() {
oldCurrentUser = OC.currentUser;
@@ -56,8 +57,15 @@ describe('OC.Share.ShareItemModel', function() {
configModel: configModel,
fileInfoModel: fileInfoModel
});
+ capsSpec = sinon.stub(OC, 'getCapabilities');
+ capsSpec.returns({
+ 'files_sharing': {
+ 'default_permissions': OC.PERMISSION_ALL
+ }
+ });
});
afterEach(function() {
+ capsSpec.restore();
if (fetchSharesStub) {
fetchSharesStub.restore();
}
@@ -527,7 +535,22 @@ describe('OC.Share.ShareItemModel', function() {
});
expect(
testWithPermissions(OC.PERMISSION_UPDATE | OC.PERMISSION_SHARE)
- ).toEqual(OC.PERMISSION_READ | OC.PERMISSION_UPDATE | OC.PERMISSION_UPDATE);
+ ).toEqual(OC.PERMISSION_READ | OC.PERMISSION_UPDATE);
+ });
+ it('uses default permissions from capabilities', function() {
+ capsSpec.returns({
+ 'files_sharing': {
+ 'default_permissions': OC.PERMISSION_READ | OC.PERMISSION_CREATE | OC.PERMISSION_SHARE
+ }
+ });
+ configModel.set('isResharingAllowed', true);
+ model.set({
+ reshare: {},
+ shares: []
+ });
+ expect(
+ testWithPermissions(OC.PERMISSION_ALL)
+ ).toEqual(OC.PERMISSION_READ | OC.PERMISSION_CREATE | OC.PERMISSION_SHARE);
});
});
});
diff --git a/lib/private/Settings/Admin/Sharing.php b/lib/private/Settings/Admin/Sharing.php
index dbdacf78dab0f..dfc0b11478b98 100644
--- a/lib/private/Settings/Admin/Sharing.php
+++ b/lib/private/Settings/Admin/Sharing.php
@@ -28,7 +28,9 @@
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;
}
/**
@@ -53,26 +59,58 @@ public function getForm() {
$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' => $this->getSharePermissionList(),
];
return new TemplateResponse('settings', 'settings/admin/sharing', $parameters, '');
}
+ /**
+ * get share permission list for template
+ *
+ * @return array
+ */
+ private function getSharePermissionList() {
+ return [
+ [
+ '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
+ ],
+ ];
+ }
+
/**
* @return string the section ID, e.g. 'sharing'
*/
diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php
index 387460852abe5..7111511eca2fb 100644
--- a/lib/private/Settings/Manager.php
+++ b/lib/private/Settings/Manager.php
@@ -271,7 +271,7 @@ private function getBuiltInAdminSettings($section): array {
}
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/lib/private/Template/JSConfigHelper.php b/lib/private/Template/JSConfigHelper.php
index b8bff07420013..b691a8a64cb33 100644
--- a/lib/private/Template/JSConfigHelper.php
+++ b/lib/private/Template/JSConfigHelper.php
@@ -28,6 +28,7 @@
namespace OC\Template;
use bantu\IniGetWrapper\IniGetWrapper;
+use OC\CapabilitiesManager;
use OCP\App\IAppManager;
use OCP\Defaults;
use OCP\IConfig;
@@ -66,6 +67,9 @@ class JSConfigHelper {
/** @var IURLGenerator */
private $urlGenerator;
+ /** @var CapabilitiesManager */
+ private $capabilitiesManager;
+
/**
* @param IL10N $l
* @param Defaults $defaults
@@ -76,6 +80,7 @@ class JSConfigHelper {
* @param IGroupManager $groupManager
* @param IniGetWrapper $iniWrapper
* @param IURLGenerator $urlGenerator
+ * @param CapabilitiesManager $capabilitiesManager
*/
public function __construct(IL10N $l,
Defaults $defaults,
@@ -85,7 +90,8 @@ public function __construct(IL10N $l,
IConfig $config,
IGroupManager $groupManager,
IniGetWrapper $iniWrapper,
- IURLGenerator $urlGenerator) {
+ IURLGenerator $urlGenerator,
+ CapabilitiesManager $capabilitiesManager) {
$this->l = $l;
$this->defaults = $defaults;
$this->appManager = $appManager;
@@ -95,6 +101,7 @@ public function __construct(IL10N $l,
$this->groupManager = $groupManager;
$this->iniWrapper = $iniWrapper;
$this->urlGenerator = $urlGenerator;
+ $this->capabilitiesManager = $capabilitiesManager;
}
public function getConfig() {
@@ -146,6 +153,8 @@ public function getConfig() {
$lastConfirmTimestamp = 0;
}
+ $capabilities = $this->capabilitiesManager->getCapabilities();
+
$array = [
"oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false',
"oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false',
@@ -252,6 +261,7 @@ public function getConfig() {
'longFooter' => $this->defaults->getLongFooter(),
'folder' => \OC_Util::getTheme(),
]),
+ "oc_capabilities" => json_encode($capabilities),
];
if ($this->currentUser !== null) {
diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php
index 8cc235bf81824..115daab70abc3 100644
--- a/lib/private/TemplateLayout.php
+++ b/lib/private/TemplateLayout.php
@@ -156,7 +156,8 @@ public function __construct( $renderAs, $appId = '' ) {
$this->config,
\OC::$server->getGroupManager(),
\OC::$server->getIniWrapper(),
- \OC::$server->getURLGenerator()
+ \OC::$server->getURLGenerator(),
+ \OC::$server->getCapabilitiesManager()
);
$this->assign('inline_ocjs', $jsConfigHelper->getConfig());
} else {
diff --git a/settings/css/settings.scss b/settings/css/settings.scss
index 05d62423d175a..611961b10659e 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 177f6d3f7f432..f637cb64592cb 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 156e8ddd81d31..5913524be40f4 100644
--- a/settings/templates/settings/admin/sharing.php
+++ b/settings/templates/settings/admin/sharing.php
@@ -106,4 +106,15 @@