diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-05-13 15:22:18 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2014-05-22 10:43:44 +0200 |
commit | 12338e0ef07c409156fa9cd1008bb981bda20461 (patch) | |
tree | fe859814a2321ab98f498a623db39dab892b8153 /settings | |
parent | 14a953fbe01a3d26e1330ea224ab71928a2f93c1 (diff) | |
download | nextcloud-server-12338e0ef07c409156fa9cd1008bb981bda20461.tar.gz nextcloud-server-12338e0ef07c409156fa9cd1008bb981bda20461.zip |
allow admin to disable sharing for specific groups of users
Diffstat (limited to 'settings')
-rwxr-xr-x | settings/admin.php | 18 | ||||
-rw-r--r-- | settings/ajax/excludegroups.php | 18 | ||||
-rw-r--r-- | settings/css/settings.css | 9 | ||||
-rw-r--r-- | settings/js/admin.js | 49 | ||||
-rw-r--r-- | settings/routes.php | 2 | ||||
-rw-r--r-- | settings/templates/admin.php | 22 |
6 files changed, 114 insertions, 4 deletions
diff --git a/settings/admin.php b/settings/admin.php index f9406246e76..699ba97edd5 100755 --- a/settings/admin.php +++ b/settings/admin.php @@ -10,6 +10,7 @@ OC_Util::checkAdminUser(); OC_Util::addStyle( "settings", "settings" ); OC_Util::addScript( "settings", "admin" ); OC_Util::addScript( "settings", "log" ); +OC_Util::addScript( 'core', 'multiselect' ); OC_App::setActiveNavigationEntry( "admin" ); $tmpl = new OC_Template( 'settings', 'admin', 'user'); @@ -48,6 +49,23 @@ $tmpl->assign('shareAPIEnabled', OC_Appconfig::getValue('core', 'shareapi_enable $tmpl->assign('shareDefaultExpireDateSet', OC_Appconfig::getValue('core', 'shareapi_default_expire_date', 'no')); $tmpl->assign('shareExpireAfterNDays', OC_Appconfig::getValue('core', 'shareapi_expire_after_n_days', '7')); $tmpl->assign('shareEnforceExpireDate', OC_Appconfig::getValue('core', 'shareapi_enforce_expire_date', 'no')); +$excludeGroups = OC_Appconfig::getValue('core', 'shareapi_exclude_groups', 'no') === 'yes' ? true : false; +$tmpl->assign('shareExcludeGroups', $excludeGroups); +$allGroups = OC_Group::getGroups(); +$excludedGroupsList = OC_Appconfig::getValue('core', 'shareapi_exclude_groups_list', ''); +$excludedGroups = $excludedGroupsList !== '' ? explode(',', $excludedGroupsList) : array(); +$groups = array(); +foreach ($allGroups as $group) { + if (in_array($group, $excludedGroups)) { + $groups[$group] = array('gid' => $group, + 'excluded' => true); + } else { + $groups[$group] = array('gid' => $group, + 'excluded' => false); + } +} +ksort($groups); +$tmpl->assign('groups', $groups); // Check if connected using HTTPS diff --git a/settings/ajax/excludegroups.php b/settings/ajax/excludegroups.php new file mode 100644 index 00000000000..2934a448a6a --- /dev/null +++ b/settings/ajax/excludegroups.php @@ -0,0 +1,18 @@ +<?php +OC_JSON::checkSubAdminUser(); +OCP\JSON::callCheck(); + +$selectedGroups = isset($_POST["selectedGroups"]) ? json_decode($_POST["selectedGroups"]) : array(); +$changedGroup = isset($_POST["changedGroup"]) ? $_POST["changedGroup"] : ''; + +if ($changedGroup !== '') { + if(($key = array_search($changedGroup, $selectedGroups)) !== false) { + unset($selectedGroups[$key]); + } else { + $selectedGroups[] = $changedGroup; + } +} else { + \OCP\Util::writeLog('core', 'Can not update list of excluded groups from sharing, parameter missing', \OCP\Util::WARN); +} + +\OC_Appconfig::setValue('core', 'shareapi_exclude_groups_list', implode(',', $selectedGroups)); diff --git a/settings/css/settings.css b/settings/css/settings.css index 2056e567b38..d0e44e721b4 100644 --- a/settings/css/settings.css +++ b/settings/css/settings.css @@ -158,6 +158,15 @@ table.shareAPI .indent { padding-left: 2em; } vertical-align: text-bottom; } +#selectGroups select { + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; + display: inline-block; + height: 36px; + padding: 7px 10px +} + span.success { background: #37ce02; border-radius: 8px; diff --git a/settings/js/admin.js b/settings/js/admin.js index cd11e68442a..249131464a8 100644 --- a/settings/js/admin.js +++ b/settings/js/admin.js @@ -1,4 +1,49 @@ +var SharingGroupList = { + applyMultipleSelect: function(element) { + var checked = []; + if ($(element).hasClass('groupsselect')) { + if (element.data('userGroups')) { + checked = element.data('userGroups'); + } + var checkHandeler = function(group) { + $.post(OC.filePath('settings', 'ajax', 'excludegroups.php'), + {changedGroup: group, selectedGroups: JSON.stringify(checked)}, + function() {}); + }; + + + var addGroup = function(select, group) { + $(this).each(function(index, element) { + if ($(element).find('option[value="' + group + '"]').length === 0 && + select.data('msid') !== $(element).data('msid')) { + $(element).append('<option value="' + escapeHTML(group) + '">' + + escapeHTML(group) + '</option>'); + } + }); + }; + + var label = null; + element.multiSelect({ + createCallback: addGroup, + createText: label, + selectedFirst: true, + checked: checked, + oncheck: checkHandeler, + onuncheck: checkHandeler, + minWidth: 100 + }); + + } + } +}; + $(document).ready(function(){ + + $('select#excludedGroups[multiple]').each(function (index, element) { + SharingGroupList.applyMultipleSelect($(element)); + }); + + $('#loglevel').change(function(){ $.post(OC.filePath('settings','ajax','setloglevel.php'), { level: $(this).val() },function(){ OC.Log.reload(); @@ -84,4 +129,8 @@ $(document).ready(function(){ OC.msg.finishedAction('#sendtestmail_msg', data); }); }); + + $('#shareapiExcludeGroups').change(function() { + $("#selectExcludedGroups").toggleClass('hidden', !this.checked); + }); }); diff --git a/settings/routes.php b/settings/routes.php index 21d406beeca..0e0f293b9be 100644 --- a/settings/routes.php +++ b/settings/routes.php @@ -84,3 +84,5 @@ $this->create('settings_admin_mail_test', '/settings/admin/mailtest') ->action('OC\Settings\Admin\Controller', 'sendTestMail'); $this->create('settings_ajax_setsecurity', '/settings/ajax/setsecurity.php') ->actionInclude('settings/ajax/setsecurity.php'); +$this->create('settings_ajax_excludegroups', '/settings/ajax/excludegroups.php') + ->actionInclude('settings/ajax/excludegroups.php'); diff --git a/settings/templates/admin.php b/settings/templates/admin.php index d1f519a072d..a4a3698d3bd 100644 --- a/settings/templates/admin.php +++ b/settings/templates/admin.php @@ -240,9 +240,6 @@ if (!$_['internetconnectionworking']) { </div> <em><?php p($l->t('Allow users to share items to the public with links')); ?></em> - - - </td> </tr> <tr> @@ -271,7 +268,24 @@ if (!$_['internetconnectionworking']) { <em><?php p($l->t('Allow users to send mail notification for shared files')); ?></em> </td> </tr> - + <tr> + <td <?php if ($_['shareAPIEnabled'] === 'no') print_unescaped('class="hidden"');?>> + <input type="checkbox" name="shareapi_exclude_groups" id="shareapiExcludeGroups" + value="1" <?php if ($_['shareExcludeGroups']) print_unescaped('checked="checked"'); ?> /> + <label for="shareapiExcludeGroups"><?php p($l->t('Exclude groups from sharing'));?></label><br/> + <div id="selectExcludedGroups" class="<?php ($_['shareExcludeGroups']) ? p('indent') : p('hidden indent'); ?>"> + <select + class="groupsselect" + id="excludedGroups" data-placeholder="groups" + title="<?php p($l->t('Groups'))?>" multiple="multiple"> + <?php foreach($_["groups"] as $group): ?> + <option value="<?php p($group['gid'])?>" <?php if($group['excluded']) { p('selected="selected"'); }?>><?php p($group['gid']);?></option> + <?php endforeach;?> + </select> + </div> + <em><?php p($l->t('These groups will still be able to receive shares, but not to initiate them.')); ?></em> + </td> + </tr> </table> </div> |