diff --git a/appinfo/app.php b/appinfo/app.php
index bafc3467..d99c18d4 100644
--- a/appinfo/app.php
+++ b/appinfo/app.php
@@ -23,6 +23,16 @@
namespace OCA\Richdocuments\AppInfo;
use OC\Security\CSP\ContentSecurityPolicy;
+use OCA\Richdocuments\PermissionManager;
+
+$currentUser = \OC::$server->getUserSession()->getUser();
+if($currentUser !== null) {
+ /** @var PermissionManager $permissionManager */
+ $permissionManager = \OC::$server->query(PermissionManager::class);
+ if(!$permissionManager->isEnabledForUser($currentUser)) {
+ return;
+ }
+}
$eventDispatcher = \OC::$server->getEventDispatcher();
$eventDispatcher->addListener(
diff --git a/js/admin.js b/js/admin.js
index 58162f69..58ddbd06 100644
--- a/js/admin.js
+++ b/js/admin.js
@@ -40,15 +40,11 @@ var documentsSettings = {
);
},
- saveGroups: function(groups) {
- var data = {
- 'edit_groups': groups
- };
-
+ saveGroups: function(data) {
$.post(
OC.filePath('richdocuments', 'ajax', 'admin.php'),
data
- );
+ );
},
saveDocFormat: function(format) {
@@ -80,14 +76,23 @@ var documentsSettings = {
OC.msg.finishedAction('#enable-external-apps-section-msg', response);
},
- initEditGroups: function() {
- var groups = $('#edit_group_select').val();
+ initGroups: function() {
+ var selectorPrefixes = [
+ 'edit',
+ 'use'
+ ];
+
+ for (i = 0; i < selectorPrefixes.length; i++) {
+ var selectorPrefix = selectorPrefixes[i];
+
+ var groups = $('#' + selectorPrefix + '_group_select').val();
if (groups !== '') {
- OC.Settings.setupGroupsSelect($('#edit_group_select'));
- $('.edit-groups-enable').attr('checked', 'checked');
+ OC.Settings.setupGroupsSelect($('#' + selectorPrefix + '_group_select'));
+ $('.' + selectorPrefix + '-groups-enable').attr('checked', 'checked');
} else {
- $('.edit-groups-enable').attr('checked', null);
+ $('.' + selectorPrefix + '-groups-enable').attr('checked', null);
}
+ }
},
initExternalApps: function() {
@@ -106,7 +111,7 @@ var documentsSettings = {
},
initialize: function() {
- documentsSettings.initEditGroups();
+ documentsSettings.initGroups();
documentsSettings.initExternalApps();
$('#wopi_apply').on('click', documentsSettings.save);
@@ -189,7 +194,7 @@ var documentsSettings = {
$(document).on('change', '#edit_group_select', function() {
var element = $(this).parent().find('input.edit-groups-enable');
var groups = $(this).val();
- documentsSettings.saveGroups(groups);
+ documentsSettings.saveGroups({edit_groups: groups});
});
$(document).on('change', '.edit-groups-enable', function() {
@@ -207,6 +212,27 @@ var documentsSettings = {
$select.change();
});
+ $(document).on('change', '#use_group_select', function() {
+ var element = $(this).parent().find('input.use-groups-enable');
+ var groups = $(this).val();
+ documentsSettings.saveGroups({use_groups: groups});
+ });
+
+ $(document).on('change', '.use-groups-enable', function() {
+ var $select = $(this).parent().find('#use_group_select');
+ $select.val('');
+
+ if (this.checked) {
+ OC.Settings.setupGroupsSelect($select, {
+ placeholder: t('core', 'All')
+ });
+ } else {
+ $select.select2('destroy');
+ }
+
+ $select.change();
+ });
+
}
};
diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php
index 850b28d1..60a4c10b 100644
--- a/lib/Controller/SettingsController.php
+++ b/lib/Controller/SettingsController.php
@@ -53,6 +53,7 @@ class SettingsController extends Controller{
public function getSettings() {
return new JSONResponse([
'wopi_url' => $this->appConfig->getAppValue('wopi_url'),
+ 'use_groups' => $this->appConfig->getAppValue('use_groups'),
'edit_groups' => $this->appConfig->getAppValue('edit_groups'),
'doc_format' => $this->appConfig->getAppValue('doc_format'),
]);
@@ -61,11 +62,13 @@ class SettingsController extends Controller{
/**
* @param string $wopi_url
* @param string $edit_groups
+ * @param string $use_groups
* @param string $doc_format
* @return JSONResponse
*/
public function setSettings($wopi_url,
$edit_groups,
+ $use_groups,
$doc_format,
$external_apps){
$message = $this->l10n->t('Saved');
@@ -83,6 +86,10 @@ class SettingsController extends Controller{
$this->appConfig->setAppValue('edit_groups', $edit_groups);
}
+ if ($use_groups !== null){
+ $this->appConfig->setAppValue('use_groups', $use_groups);
+ }
+
if ($doc_format !== null) {
$this->appConfig->setAppValue('doc_format', $doc_format);
}
diff --git a/lib/PermissionManager.php b/lib/PermissionManager.php
new file mode 100644
index 00000000..d956c50c
--- /dev/null
+++ b/lib/PermissionManager.php
@@ -0,0 +1,65 @@
+
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see