summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-02-27 13:44:34 +0100
committerGitHub <noreply@github.com>2018-02-27 13:44:34 +0100
commit7bc3c2e057c8c265ca7b1aa387dd1ba479690143 (patch)
treec02f1ec27b8037ef2f604829347e7efe2e3d34ab /core
parent01f420c7ac38128c03975d7de7dd20190c4afcc1 (diff)
parent20ec0344a26faf725762e3b344b66bb45ef1a5a2 (diff)
downloadnextcloud-server-7bc3c2e057c8c265ca7b1aa387dd1ba479690143.tar.gz
nextcloud-server-7bc3c2e057c8c265ca7b1aa387dd1ba479690143.zip
Merge pull request #7363 from nextcloud/default-share-perms
Let the admin configure the default share permissions
Diffstat (limited to 'core')
-rw-r--r--core/Controller/OCJSController.php8
-rw-r--r--core/js/js.js19
-rw-r--r--core/js/shareitemmodel.js17
-rw-r--r--core/js/tests/specs/shareitemmodelSpec.js25
4 files changed, 58 insertions, 11 deletions
diff --git a/core/Controller/OCJSController.php b/core/Controller/OCJSController.php
index 8db26dd3d38..37fe17c8dd1 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 @@ class OCJSController extends Controller {
IConfig $config,
IGroupManager $groupManager,
IniGetWrapper $iniWrapper,
- IURLGenerator $urlGenerator) {
+ IURLGenerator $urlGenerator,
+ CapabilitiesManager $capabilitiesManager) {
parent::__construct($appName, $request);
$this->helper = new JSConfigHelper(
@@ -82,7 +85,8 @@ class OCJSController extends Controller {
$config,
$groupManager,
$iniWrapper,
- $urlGenerator
+ $urlGenerator,
+ $capabilitiesManager
);
}
diff --git a/core/js/js.js b/core/js/js.js
index 9b8829de250..fa92508ff7a 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 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/core/js/tests/specs/shareitemmodelSpec.js b/core/js/tests/specs/shareitemmodelSpec.js
index 3b17051508e..0a345786b73 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);
});
});
});