Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2021-07-22 12:41:29 +0300
committerCarl Schwan <carl@carlschwan.eu>2021-09-29 22:43:31 +0300
commit6958d8005ae3b86759f49746564bf7238456be52 (patch)
treeaab851e09351c631129e4729aa49c03533ce6180 /apps/settings/src
parentee987d74303cb38b864f96660cd2ee6d6552ebfd (diff)
Add admin privilege delegation for admin settings
This makes it possible for selected groups to access some settings pages. Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'apps/settings/src')
-rw-r--r--apps/settings/src/components/AdminDelegating.vue37
-rw-r--r--apps/settings/src/components/AdminDelegation/GroupSelect.vue75
-rw-r--r--apps/settings/src/main-admin-delegation.js32
3 files changed, 144 insertions, 0 deletions
diff --git a/apps/settings/src/components/AdminDelegating.vue b/apps/settings/src/components/AdminDelegating.vue
new file mode 100644
index 00000000000..c32da671adc
--- /dev/null
+++ b/apps/settings/src/components/AdminDelegating.vue
@@ -0,0 +1,37 @@
+<template>
+ <div id="admin-right-sub-granting" class="section">
+ <h2>{{ t('settings', 'Admin right privilege') }}</h2>
+ <p class="settings-hint">
+ {{ t('settings', 'Here you can decide which group can access some of the admin settings.') }}
+ </p>
+
+ <div class="setting-list">
+ <div v-for="setting in availableSettings" :key="setting.class">
+ <h3>{{ setting.sectionName }}</h3>
+ <GroupSelect :available-groups="availableGroups" :authorized-groups="authorizedGroups" :setting="setting" />
+ </div>
+ </div>
+ </div>
+</template>
+
+<script>
+import GroupSelect from './AdminDelegation/GroupSelect'
+import { loadState } from '@nextcloud/initial-state'
+
+export default {
+ name: 'AdminDelegating',
+ components: {
+ GroupSelect,
+ },
+ data() {
+ const availableSettings = loadState('settings', 'available-settings')
+ const availableGroups = loadState('settings', 'available-groups')
+ const authorizedGroups = loadState('settings', 'authorized-groups')
+ return {
+ availableSettings,
+ availableGroups,
+ authorizedGroups,
+ }
+ },
+}
+</script>
diff --git a/apps/settings/src/components/AdminDelegation/GroupSelect.vue b/apps/settings/src/components/AdminDelegation/GroupSelect.vue
new file mode 100644
index 00000000000..8f27efdfef0
--- /dev/null
+++ b/apps/settings/src/components/AdminDelegation/GroupSelect.vue
@@ -0,0 +1,75 @@
+<template>
+ <Multiselect
+ v-model="selected"
+ class="group-multiselect"
+ :placeholder="t('settings', 'None')"
+ track-by="gid"
+ label="displayName"
+ :options="availableGroups"
+ open-direction="bottom"
+ :multiple="true"
+ :allow-empty="true" />
+</template>
+
+<script>
+import Multiselect from '@nextcloud/vue/dist/Components/Multiselect'
+import { generateUrl } from '@nextcloud/router'
+import axios from '@nextcloud/axios'
+import { showError } from '@nextcloud/dialogs'
+import logger from '../../logger'
+
+export default {
+ name: 'GroupSelect',
+ components: {
+ Multiselect,
+ },
+ props: {
+ availableGroups: {
+ type: Array,
+ default: () => [],
+ },
+ setting: {
+ type: Object,
+ required: true,
+ },
+ authorizedGroups: {
+ type: Array,
+ required: true,
+ },
+ },
+ data() {
+ return {
+ selected: this.authorizedGroups
+ .filter((group) => group.class === this.setting.class)
+ .map((groupToMap) => this.availableGroups.find((group) => group.gid === groupToMap.group_id))
+ .filter((group) => group !== undefined)
+ }
+ },
+ watch: {
+ selected() {
+ this.saveGroups()
+ },
+ },
+ methods: {
+ async saveGroups() {
+ const data = {
+ newGroups: this.selected,
+ class: this.setting.class,
+ }
+ try {
+ await axios.post(generateUrl('/apps/settings/') + '/settings/authorizedgroups/saveSettings', data)
+ } catch (e) {
+ showError(t('settings', 'Unable to modify setting'))
+ logger.error('Unable to modify setting', e)
+ }
+ },
+ }
+}
+</script>
+
+<style lang="scss">
+.group-multiselect {
+ width: 100%;
+ margin-right: 0;
+}
+</style>
diff --git a/apps/settings/src/main-admin-delegation.js b/apps/settings/src/main-admin-delegation.js
new file mode 100644
index 00000000000..c2474bf5867
--- /dev/null
+++ b/apps/settings/src/main-admin-delegation.js
@@ -0,0 +1,32 @@
+/**
+ * @copyright Copyright (c) 2021 Carl Schwan <carl@carlschwan.eu>
+ *
+ * @author Carl Schwan <carl@carlschwan.eu>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import Vue from 'vue'
+import App from './components/AdminDelegating.vue'
+
+// bind to window
+Vue.prototype.OC = OC
+Vue.prototype.t = t
+
+const View = Vue.extend(App)
+const accessibility = new View()
+accessibility.$mount('#admin-right-sub-granting')