Skip to content

Commit f09e172

Browse files
committed
feat: default expiration dates
- default expiration date for folders with RW permissions is 30 days - if the expiration date is set for more than 3 years, is updated - removes the option to unset expiration dates for RW folders
1 parent e6c7b25 commit f09e172

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ import { isLocationSharesActive, useSharesStore } from '@ownclouders/web-pkg'
102102
import { useGettext } from 'vue3-gettext'
103103
import { storeToRefs } from 'pinia'
104104
import { SharingLinkType } from '@ownclouders/web-client/graph/generated'
105+
import { DateTime } from 'luxon'
105106
106107
export default defineComponent({
107108
name: 'FileLinks',
@@ -192,6 +193,22 @@ export default defineComponent({
192193
options: UpdateLinkOptions['options']
193194
}) => {
194195
try {
196+
// default expiration date
197+
if (unref(resource).isFolder && options.type === 'edit' && !linkShare.expirationDateTime) {
198+
Object.assign(options, {
199+
...options,
200+
expirationDateTime: DateTime.now().plus({ days: 30 }).endOf('day').toISO()
201+
})
202+
}
203+
// expiration date capped at 3 years
204+
if (unref(resource).isFolder && linkShare.expirationDateTime) {
205+
if (DateTime.fromISO(linkShare.expirationDateTime).diffNow('years').years > 3) {
206+
Object.assign(options, {
207+
...options,
208+
expirationDateTime: DateTime.now().plus({ years: 3 }).endOf('day').toISO()
209+
})
210+
}
211+
}
195212
await updateLink({
196213
clientService,
197214
space: unref(space),

packages/web-app-files/src/components/SideBar/Shares/Links/EditDropdown.vue

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ export default defineComponent({
110110
customComponent: DatePickerModal,
111111
customComponentAttrs: () => ({
112112
currentDate: currentDate.isValid ? currentDate : null,
113-
minDate: DateTime.now()
113+
minDate: DateTime.now(),
114+
maxDate:
115+
resource.value.isFolder && props.linkShare.type === SharingLinkType.Edit
116+
? DateTime.now().plus({ years: 3 }).endOf('day')
117+
: null
114118
}),
115119
onConfirm: (expirationDateTime: DateTime) => {
116120
emit('updateLink', {
@@ -214,18 +218,21 @@ export default defineComponent({
214218
method: showDatePickerModal
215219
})
216220
217-
result.push({
218-
id: 'remove-expiration',
219-
title: $gettext('Remove expiration date'),
220-
icon: 'calendar-close',
221-
method: () => {
222-
emit('updateLink', {
223-
linkShare: { ...props.linkShare },
224-
options: { expirationDateTime: null }
225-
})
226-
unref(editPublicLinkDropdown).hide()
227-
}
228-
})
221+
// only if is not a edit folder link
222+
if (!(props.linkShare.type === SharingLinkType.Edit && resource.value.isFolder)) {
223+
result.push({
224+
id: 'remove-expiration',
225+
title: $gettext('Remove expiration date'),
226+
icon: 'calendar-close',
227+
method: () => {
228+
emit('updateLink', {
229+
linkShare: { ...props.linkShare },
230+
options: { expirationDateTime: null }
231+
})
232+
unref(editPublicLinkDropdown).hide()
233+
}
234+
})
235+
}
229236
} else if (!unref(isInternalLink)) {
230237
result.push({
231238
id: 'add-expiration',

packages/web-pkg/src/components/CreateLinkModal.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
v-if="isAdvancedMode"
4949
class="oc-mt-s"
5050
:min-date="DateTime.now()"
51+
:max-date="
52+
isFolder && selectedType === 'edit' ? DateTime.now().plus({ years: 3 }).endOf('day') : null
53+
"
5154
:label="$gettext('Expiry date')"
5255
@date-changed="onExpiryDateChanged"
5356
/>
@@ -303,6 +306,13 @@ export default defineComponent({
303306
304307
const updateSelectedLinkType = (type: SharingLinkType) => {
305308
selectedType.value = type
309+
onExpiryDateChanged({
310+
date: unref(selectedExpiry),
311+
error:
312+
unref(selectedExpiry)?.toISO() > DateTime.now().plus({ years: 3 }).endOf('day').toISO() &&
313+
isFolder &&
314+
unref(selectedType) === 'edit'
315+
})
306316
}
307317
308318
onMounted(() => {

0 commit comments

Comments
 (0)