aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/src/components/AdminSettingsSharingForm.vue
blob: 8a274af88a836c57c0c2f3428aa9c5e50b2602aa (plain)
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<!--
  - SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  - SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
	<form class="sharing">
		<NcCheckboxRadioSwitch aria-controls="settings-sharing-api settings-sharing-api-settings settings-sharing-default-permissions settings-sharing-privary-related"
			type="switch"
			:checked.sync="settings.enabled">
			{{ t('settings', 'Allow apps to use the Share API') }}
		</NcCheckboxRadioSwitch>

		<div v-show="settings.enabled" id="settings-sharing-api-settings" class="sharing__sub-section">
			<NcCheckboxRadioSwitch :checked.sync="settings.allowResharing">
				{{ t('settings', 'Allow resharing') }}
			</NcCheckboxRadioSwitch>
			<NcCheckboxRadioSwitch :checked.sync="settings.allowGroupSharing">
				{{ t('settings', 'Allow sharing with groups') }}
			</NcCheckboxRadioSwitch>
			<NcCheckboxRadioSwitch :checked.sync="settings.onlyShareWithGroupMembers">
				{{ t('settings', 'Restrict users to only share with users in their groups') }}
			</NcCheckboxRadioSwitch>
			<div v-show="settings.onlyShareWithGroupMembers" id="settings-sharing-api-excluded-groups" class="sharing__labeled-entry sharing__input">
				<label for="settings-sharing-only-group-members-excluded-groups">{{ t('settings', 'Ignore the following groups when checking group membership') }}</label>
				<NcSettingsSelectGroup id="settings-sharing-only-group-members-excluded-groups"
					v-model="settings.onlyShareWithGroupMembersExcludeGroupList"
					:label="t('settings', 'Ignore the following groups when checking group membership')"
					style="width: 100%" />
			</div>
		</div>

		<div v-show="settings.enabled" id="settings-sharing-api" class="sharing__section">
			<NcCheckboxRadioSwitch type="switch"
				aria-controls="settings-sharing-api-public-link"
				:checked.sync="settings.allowLinks">
				{{ t('settings', 'Allow users to share via link and emails') }}
			</NcCheckboxRadioSwitch>
			<fieldset v-show="settings.allowLinks" id="settings-sharing-api-public-link" class="sharing__sub-section">
				<NcCheckboxRadioSwitch :checked.sync="settings.allowPublicUpload">
					{{ t('settings', 'Allow public uploads') }}
				</NcCheckboxRadioSwitch>
				<NcCheckboxRadioSwitch :checked.sync="settings.enableLinkPasswordByDefault">
					{{ t('settings', 'Always ask for a password') }}
				</NcCheckboxRadioSwitch>
				<NcCheckboxRadioSwitch :checked.sync="settings.enforceLinksPassword" :disabled="!settings.enableLinkPasswordByDefault">
					{{ t('settings', 'Enforce password protection') }}
				</NcCheckboxRadioSwitch>
				<label v-if="settings.passwordExcludedGroupsFeatureEnabled" class="sharing__labeled-entry sharing__input">
					<span>{{ t('settings', 'Exclude groups from password requirements') }}</span>
					<NcSettingsSelectGroup v-model="settings.passwordExcludedGroups"
						style="width: 100%"
						:disabled="!settings.enforceLinksPassword || !settings.enableLinkPasswordByDefault" />
				</label>
				<label class="sharing__labeled-entry sharing__input">
					<span>{{ t('settings', 'Exclude groups from creating link shares') }}</span>
					<NcSettingsSelectGroup v-model="settings.allowLinksExcludeGroups"
						:label="t('settings', 'Exclude groups from creating link shares')"
						style="width: 100%" />
				</label>
			</fieldset>

			<label>{{ t('settings', 'Limit sharing based on groups') }}</label>
			<div class="sharing__sub-section">
				<NcCheckboxRadioSwitch :checked.sync="settings.excludeGroups"
					name="excludeGroups"
					value="no"
					type="radio"
					@update:checked="onUpdateExcludeGroups">
					{{ t('settings', 'Allow sharing for everyone (default)') }}
				</NcCheckboxRadioSwitch>
				<NcCheckboxRadioSwitch :checked.sync="settings.excludeGroups"
					name="excludeGroups"
					value="yes"
					type="radio"
					@update:checked="onUpdateExcludeGroups">
					{{ t('settings', 'Exclude some groups from sharing') }}
				</NcCheckboxRadioSwitch>
				<NcCheckboxRadioSwitch :checked.sync="settings.excludeGroups"
					name="excludeGroups"
					value="allow"
					type="radio"
					@update:checked="onUpdateExcludeGroups">
					{{ t('settings', 'Limit sharing to some groups') }}
				</NcCheckboxRadioSwitch>
				<div v-show="settings.excludeGroups !== 'no'" class="sharing__labeled-entry sharing__input">
					<NcSettingsSelectGroup id="settings-sharing-excluded-groups"
						v-model="settings.excludeGroupsList"
						aria-describedby="settings-sharing-excluded-groups-desc"
						:label="settings.excludeGroups === 'allow' ? t('settings', 'Groups allowed to share') : t('settings', 'Groups excluded from sharing')"
						:disabled="settings.excludeGroups === 'no'"
						style="width: 100%" />
					<em id="settings-sharing-excluded-groups-desc">{{ t('settings', 'Not allowed groups will still be able to receive shares, but not to initiate them.') }}</em>
				</div>
			</div>

			<NcCheckboxRadioSwitch type="switch"
				aria-controls="settings-sharing-api-expiration"
				:checked.sync="settings.defaultInternalExpireDate">
				{{ t('settings', 'Set default expiration date for shares') }}
			</NcCheckboxRadioSwitch>
			<fieldset v-show="settings.defaultInternalExpireDate" id="settings-sharing-api-expiration" class="sharing__sub-section">
				<NcCheckboxRadioSwitch :checked.sync="settings.enforceInternalExpireDate">
					{{ t('settings', 'Enforce expiration date') }}
				</NcCheckboxRadioSwitch>
				<NcTextField type="number"
					class="sharing__input"
					:label="t('settings', 'Default expiration time of new shares in days')"
					:placeholder="t('settings', 'Expire shares after x days')"
					:value.sync="settings.internalExpireAfterNDays" />
			</fieldset>

			<NcCheckboxRadioSwitch type="switch"
				aria-controls="settings-sharing-remote-api-expiration"
				:checked.sync="settings.defaultRemoteExpireDate">
				{{ t('settings', 'Set default expiration date for shares to other servers') }}
			</NcCheckboxRadioSwitch>
			<fieldset v-show="settings.defaultRemoteExpireDate" id="settings-sharing-remote-api-expiration" class="sharing__sub-section">
				<NcCheckboxRadioSwitch :checked.sync="settings.enforceRemoteExpireDate">
					{{ t('settings', 'Enforce expiration date for remote shares') }}
				</NcCheckboxRadioSwitch>
				<NcTextField type="number"
					class="sharing__input"
					:label="t('settings', 'Default expiration time of remote shares in days')"
					:placeholder="t('settings', 'Expire remote shares after x days')"
					:value.sync="settings.remoteExpireAfterNDays" />
			</fieldset>

			<NcCheckboxRadioSwitch type="switch"
				aria-controls="settings-sharing-api-api-expiration"
				:checked.sync="settings.defaultExpireDate"
				:disabled="!settings.allowLinks">
				{{ t('settings', 'Set default expiration date for shares via link or mail') }}
			</NcCheckboxRadioSwitch>
			<fieldset v-show="settings.allowLinks && settings.defaultExpireDate" id="settings-sharing-api-api-expiration" class="sharing__sub-section">
				<NcCheckboxRadioSwitch :checked.sync="settings.enforceExpireDate">
					{{ t('settings', 'Enforce expiration date for remote shares') }}
				</NcCheckboxRadioSwitch>
				<NcTextField type="number"
					class="sharing__input"
					:label="t('settings', 'Default expiration time of shares in days')"
					:placeholder="t('settings', 'Expire shares after x days')"
					:value.sync="settings.expireAfterNDays" />
			</fieldset>
		</div>

		<div v-show="settings.enabled" id="settings-sharing-privary-related" class="sharing__section">
			<h3>{{ t('settings', 'Privacy settings for sharing') }}</h3>

			<NcCheckboxRadioSwitch type="switch"
				aria-controls="settings-sharing-privacy-user-enumeration"
				:checked.sync="settings.allowShareDialogUserEnumeration">
				{{ t('settings', 'Allow account name autocompletion in share dialog and allow access to the system address book') }}
			</NcCheckboxRadioSwitch>
			<fieldset v-show="settings.allowShareDialogUserEnumeration" id="settings-sharing-privacy-user-enumeration" class="sharing__sub-section">
				<em>
					{{ t('settings', 'If autocompletion "same group" and "phone number integration" are enabled a match in either is enough to show the user.') }}
				</em>
				<NcCheckboxRadioSwitch :checked.sync="settings.restrictUserEnumerationToGroup">
					{{ t('settings', 'Restrict account name autocompletion and system address book access to users within the same groups') }}
				</NcCheckboxRadioSwitch>
				<NcCheckboxRadioSwitch :checked.sync="settings.restrictUserEnumerationToPhone">
					{{ t('settings', 'Restrict account name autocompletion to users based on phone number integration') }}
				</NcCheckboxRadioSwitch>
			</fieldset>

			<NcCheckboxRadioSwitch type="switch" :checked.sync="settings.restrictUserEnumerationFullMatch">
				{{ t('settings', 'Allow autocompletion when entering the full name or email address (ignoring missing phonebook match and being in the same group)') }}
			</NcCheckboxRadioSwitch>

			<NcCheckboxRadioSwitch type="switch" :checked.sync="publicShareDisclaimerEnabled">
				{{ t('settings', 'Show disclaimer text on the public link upload page (only shown when the file list is hidden)') }}
			</NcCheckboxRadioSwitch>
			<div v-if="typeof settings.publicShareDisclaimerText === 'string'"
				aria-describedby="settings-sharing-privary-related-disclaimer-hint"
				class="sharing__sub-section">
				<NcTextArea class="sharing__input"
					:label="t('settings', 'Disclaimer text')"
					aria-describedby="settings-sharing-privary-related-disclaimer-hint"
					:value="settings.publicShareDisclaimerText"
					@update:value="onUpdateDisclaimer" />
				<em id="settings-sharing-privary-related-disclaimer-hint" class="sharing__input">
					{{ t('settings', 'This text will be shown on the public link upload page when the file list is hidden.') }}
				</em>
			</div>
		</div>

		<div id="settings-sharing-default-permissions" class="sharing__section">
			<h3>{{ t('settings', 'Default share permissions') }}</h3>
			<SelectSharingPermissions :value.sync="settings.defaultPermissions" />
		</div>
	</form>
</template>

<script lang="ts">
import {
	NcCheckboxRadioSwitch,
	NcSettingsSelectGroup,
	NcTextArea,
	NcTextField,
} from '@nextcloud/vue'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import { loadState } from '@nextcloud/initial-state'
import { snakeCase } from 'lodash'
import { defineComponent } from 'vue'
import debounce from 'debounce'

import SelectSharingPermissions from './SelectSharingPermissions.vue'

interface IShareSettings {
	enabled: boolean
	allowGroupSharing: boolean
	allowLinks: boolean
	allowLinksExcludeGroups: unknown
	allowPublicUpload: boolean
	allowResharing: boolean
	allowShareDialogUserEnumeration: boolean
	restrictUserEnumerationToGroup: boolean
	restrictUserEnumerationToPhone: boolean
	restrictUserEnumerationFullMatch: boolean
	restrictUserEnumerationFullMatchUserId: boolean
	restrictUserEnumerationFullMatchEmail: boolean
	restrictUserEnumerationFullMatchIgnoreSecondDN: boolean
	enforceLinksPassword: boolean
	passwordExcludedGroups: string[]
	passwordExcludedGroupsFeatureEnabled: boolean
	onlyShareWithGroupMembers: boolean
	onlyShareWithGroupMembersExcludeGroupList: string[]
	defaultExpireDate: boolean
	expireAfterNDays: string
	enforceExpireDate: boolean
	excludeGroups: string
	excludeGroupsList: string[]
	publicShareDisclaimerText?: string
	enableLinkPasswordByDefault: boolean
	defaultPermissions: number
	defaultInternalExpireDate: boolean
	internalExpireAfterNDays: string
	enforceInternalExpireDate: boolean
	defaultRemoteExpireDate: boolean
	remoteExpireAfterNDays: string
	enforceRemoteExpireDate: boolean
}

export default defineComponent({
	name: 'AdminSettingsSharingForm',
	components: {
		NcCheckboxRadioSwitch,
		NcSettingsSelectGroup,
		NcTextArea,
		NcTextField,
		SelectSharingPermissions,
	},
	data() {
		return {
			settingsData: loadState<IShareSettings>('settings', 'sharingSettings'),
		}
	},
	computed: {
		settings() {
			console.warn('new proxy')
			return new Proxy(this.settingsData, {
				get(target, property) {
					return target[property]
				},
				set(target, property: string, newValue) {
					const configName = `shareapi_${snakeCase(property)}`
					const value = typeof newValue === 'boolean' ? (newValue ? 'yes' : 'no') : (typeof newValue === 'string' ? newValue : JSON.stringify(newValue))
					window.OCP.AppConfig.setValue('core', configName, value)
					target[property] = newValue
					return true
				},
			})
		},
		publicShareDisclaimerEnabled: {
			get() {
				return typeof this.settingsData.publicShareDisclaimerText === 'string'
			},
			set(value) {
				if (value) {
					this.settingsData.publicShareDisclaimerText = ''
				} else {
					this.onUpdateDisclaimer()
				}
			},
		},
	},
	methods: {
		t,

		onUpdateDisclaimer: debounce(function(value?: string) {
			const options = {
				success() {
					if (value) {
						showSuccess(t('settings', 'Changed disclaimer text'))
					} else {
						showSuccess(t('settings', 'Deleted disclaimer text'))
					}
				},
				error() {
					showError(t('settings', 'Could not set disclaimer text'))
				},
			}
			if (!value) {
				window.OCP.AppConfig.deleteKey('core', 'shareapi_public_link_disclaimertext', options)
			} else {
				window.OCP.AppConfig.setValue('core', 'shareapi_public_link_disclaimertext', value, options)
			}
			this.settingsData.publicShareDisclaimerText = value
		}, 500) as (v?: string) => void,
		onUpdateExcludeGroups: debounce(function(value: string) {
			window.OCP.AppConfig.setValue('core', 'excludeGroups', value)
			this.settings.excludeGroups = value
		}, 500) as (v?: string) => void,
	},
})
</script>

<style scoped lang="scss">
.sharing {
	display: flex;
	flex-direction: column;
	gap: 12px;

	&__labeled-entry {
		display: flex;
		flex: 1 0;
		flex-direction: column;
		gap: 4px;
	}

	&__section {
		display: flex;
		flex-direction: column;
		gap: 4px;
		margin-block-end: 12px
	}

	&__sub-section {
		display: flex;
		flex-direction: column;
		gap: 4px;

		margin-inline-start: 44px;
		margin-block-end: 12px
	}

	&__input {
		max-width: 500px;
		// align with checkboxes
		margin-inline-start: 14px;

		:deep(.v-select.select) {
			width: 100%;
		}
	}
}

@media only screen and (max-width: 350px) {
	// ensure no overflow happens on small devices (required for WCAG)
	.sharing {
		&__sub-section {
			margin-inline-start: 14px;
		}
	}
}
</style>