From 5040593e21c10217918556b45022e78f7b110bb4 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Tue, 28 Nov 2023 16:52:40 +0100 Subject: [PATCH 1/2] refactor: move link expiration rules to a helper method This is necessary because we need the method in more than one place in the future. Also, previously this was named "expiration date", although it defines rules for setting an expiration date for a link. Hence the rename to "expiration rules". --- .../components/SideBar/Shares/FileLinks.vue | 50 +++++-------------- .../SideBar/Shares/Links/CreateQuickLink.vue | 16 +++--- .../SideBar/Shares/Links/DetailsAndEdit.vue | 15 +++--- .../Shares/Links/DetailsAndEdit.spec.ts | 2 +- .../__snapshots__/DetailsAndEdit.spec.ts.snap | 2 +- packages/web-client/src/ocs/capabilities.ts | 10 ++-- packages/web-pkg/src/helpers/share/link.ts | 41 +++++++++++++++ .../tests/unit/helpers/share/link.spec.ts | 23 ++++++++- packages/web-runtime/src/App.vue | 2 +- 9 files changed, 103 insertions(+), 58 deletions(-) diff --git a/packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue b/packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue index d3a9dd05edc..7602fc4f36b 100644 --- a/packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue +++ b/packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue @@ -14,14 +14,14 @@ getExpirationRules({ store, currentLanguage })) + return { $store: store, ability, @@ -241,7 +246,8 @@ export default defineComponent({ configurationManager, passwordPolicyService, canCreateLinks, - canEditLink + canEditLink, + expirationRules } }, computed: { @@ -264,36 +270,6 @@ export default defineComponent({ return this.outgoingLinks.find((link) => link.quicklink === true && !link.indirect) }, - expirationDate() { - const expireDate = this.capabilities.files_sharing.public.expire_date - - let defaultExpireDate = null - let maxExpireDateFromCaps = null - - if (expireDate.days) { - const days = parseInt(expireDate.days) - defaultExpireDate = DateTime.now() - .setLocale(getLocaleFromLanguage(this.$language.current)) - .plus({ days }) - .toJSDate() - } - - if (expireDate.enforced) { - const days = parseInt(expireDate.days) - maxExpireDateFromCaps = DateTime.now() - .setLocale(getLocaleFromLanguage(this.$language.current)) - .plus({ days }) - .toJSDate() - } - - return { - enforced: expireDate.enforced, - default: defaultExpireDate, - min: DateTime.now().setLocale(getLocaleFromLanguage(this.$language.current)).toJSDate(), - max: maxExpireDateFromCaps - } - }, - helpersEnabled() { return this.configuration?.options?.contextHelpers }, @@ -415,7 +391,7 @@ export default defineComponent({ ability: this.ability, store: this.$store }).toString(), - expiration: this.expirationDate.default, + expiration: this.expirationRules.default, password: false } }) diff --git a/packages/web-app-files/src/components/SideBar/Shares/Links/CreateQuickLink.vue b/packages/web-app-files/src/components/SideBar/Shares/Links/CreateQuickLink.vue index 133fc766b2e..b045510bbed 100644 --- a/packages/web-app-files/src/components/SideBar/Shares/Links/CreateQuickLink.vue +++ b/packages/web-app-files/src/components/SideBar/Shares/Links/CreateQuickLink.vue @@ -26,16 +26,20 @@