-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathAdminSettings.vue
160 lines (152 loc) · 5.77 KB
/
AdminSettings.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!--
- @copyright 2019 Christoph Wurst <[email protected]>
-
- @author 2019 Christoph Wurst <[email protected]>
-
- @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/>.
-->
<template>
<div id="ldap-write-support-admin-settings" class="section">
<h2>{{ t('ldap_write_support', 'Writing') }}</h2>
<h3>{{ t('ldap_write_support', 'Switches') }}</h3>
<ul>
<ActionCheckbox :checked="switches.createPreventFallback"
@change.stop.prevent="toggleSwitch('createPreventFallback', !switches.createPreventFallback)">
{{ t('ldap_write_support', 'Prevent fallback to other backends when creating users or groups.') }}
</ActionCheckbox>
<ActionCheckbox :checked="switches.createRequireActorFromLdap"
@change.stop.prevent="toggleSwitch('createRequireActorFromLdap', !switches.createRequireActorFromLdap)">
{{ t('ldap_write_support', 'To create users, the acting (sub)admin has to be provided by LDAP.') }}
</ActionCheckbox>
<ActionCheckbox :checked="switches.newUserGenerateUserID"
@change.stop.prevent="toggleSwitch('newUserGenerateUserID', !switches.newUserGenerateUserID, 'core')">
{{ t('ldap_write_support', 'A random user ID has to be generated, i.e. not being provided by the (sub)admin.') }}
</ActionCheckbox>
<ActionCheckbox :checked="switches.newUserRequireEmail"
@change.stop.prevent="toggleSwitch('newUserRequireEmail', !switches.newUserRequireEmail, 'core')">
{{ t('ldap_write_support', 'An LDAP user must have an email address set.') }}
</ActionCheckbox>
<ActionCheckbox :checked="switches.hasAvatarPermission"
@change.stop.prevent="toggleSwitch('hasAvatarPermission', !switches.hasAvatarPermission)">
{{ t('ldap_write_support', 'Allow users to set their avatar') }}
</ActionCheckbox>
</ul>
<h3>{{ t('ldap_write_support', 'User template') }}</h3>
<p>{{ t('ldap_write_support', 'LDIF template for creating users. Following placeholders may be used') }}</p>
<ul class="disc">
<li><span class="mono">{UID}</span> – {{ t('ldap_write_support', 'the user id provided by the (sub)admin') }}</li>
<li><span class="mono">{PWD}</span> – {{ t('ldap_write_support', 'the password provided by the (sub)admin') }}</li>
<li><span class="mono">{BASE}</span> – {{ t('ldap_write_support', 'the LDAP node of the acting (sub)admin or the configured user base') }}</li>
</ul>
<textarea v-model="userTemplate" class="mono" @change="setUserTemplate" />
<h3>{{ t('ldap_write_support', 'Group template') }}</h3>
<p>{{ t('ldap_write_support', 'LDIF template for creating groups. Following placeholders may be used') }}</p>
<ul class="disc">
<li><span class="mono">{GID}</span> – {{ t('ldap_write_support', 'the group id provided by the (sub)admin') }}</li>
<li><span class="mono">{BASE}</span> – {{ t('ldap_write_support', 'the LDAP node of the acting (sub)admin or the configured group base') }}</li>
</ul>
<textarea class="mono" v-on:change="setGroupTemplate" v-model="templates.group">{{templates.group}}</textarea>
</div>
</template>
<script>
import { ActionCheckbox } from '@nextcloud/vue'
import { showError } from '@nextcloud/dialogs'
import i10n from '../mixins/i10n.js'
export default {
name: 'AdminSettings',
components: {
ActionCheckbox,
},
mixins: [i10n],
props: {
templates: {
required: true,
type: Object,
group: Object,
groupDefault: Object,
},
switches: {
required: true,
type: Object,
},
},
data() {
return {
userTemplate: this.templates.user.slice(),
checkboxes: { ...this.switches },
}
},
methods: {
setUserTemplate() {
if (this.templates.user === '') {
OCP.AppConfig.deleteKey('ldap_write_support', 'template.user', {
success: () => {
this.userTemplate = this.templates.userDefault.slice()
},
error: () => showError(t('ldap_write_support', 'Failed to set user template.')),
})
return
}
OCP.AppConfig.setValue('ldap_write_support', 'template.user', this.userTemplate)
},
setGroupTemplate() {
if(this.templates.group === "") {
let self = this;
OCP.AppConfig.deleteKey('ldap_write_support', 'template.group', {
success: function() {
self.templates.group = self.templates.groupDefault;
}
});
return;
}
OCP.AppConfig.setValue('ldap_write_support', 'template.group', this.templates.group);
},
toggleSwitch(prefKey, state, appId = 'ldap_write_support') {
this.checkboxes[prefKey] = state
let value = (state | 0).toString()
if (appId === 'core') {
// the database key has a slighlty different style, need to transform
prefKey = 'newUser.' + prefKey.charAt(7).toLowerCase() + prefKey.slice(8)
value = value === '1' ? 'yes' : 'no'
}
OCP.AppConfig.setValue(appId, prefKey, value, {
error: () => showError(t('ldap_write_support', 'Failed to set switch.')),
})
},
},
}
</script>
<style lang="scss">
#ldap-write-support-admin-settings {
.mono {
font-family: monospace;
font-size: larger;
}
ul.disc {
list-style-type: disc;
list-style-position: inside;
margin-left: 44px;
li {
margin: 5px 0;
}
}
textarea {
width: 100%;
height: 150px;
max-width: 600px;
}
}
</style>