Skip to content

fix: expiration dates defined in capabilities #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: cernbox
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
</template>
<script lang="ts">
import { defineComponent, inject, ref } from 'vue'
import { DateTime } from 'luxon'
import { DateTime, Duration } from 'luxon'
import { mapGetters, mapActions, mapState, mapMutations } from 'vuex'
import {
useStore,
Expand Down Expand Up @@ -190,29 +190,28 @@ export default defineComponent({
const expireDate = this.capabilities.files_sharing.public.expire_date

let defaultExpireDate = null
let maxExpireDateFromCaps = null
let maxExpireDate = null

if (expireDate.days) {
const days = parseInt(expireDate.days)
if (expireDate.default_rw_folders) {
const expireDateDefault = Duration.fromObject(expireDate.default_rw_folders).toObject()
defaultExpireDate = DateTime.now()
.setLocale(getLocaleFromLanguage(this.$language.current))
.plus({ days })
.plus(expireDateDefault)
.toJSDate()
}

if (expireDate.enforced) {
const days = parseInt(expireDate.max)
maxExpireDateFromCaps = DateTime.now()
if (expireDate.max_rw_folders) {
const expireDateMax = Duration.fromObject(expireDate.max_rw_folders).toObject()
maxExpireDate = DateTime.now()
.setLocale(getLocaleFromLanguage(this.$language.current))
.plus({ days })
.plus(expireDateMax)
.toJSDate()
}

return {
enforced: expireDate.enforced,
default: defaultExpireDate,
min: DateTime.now().setLocale(getLocaleFromLanguage(this.$language.current)).toJSDate(),
max: maxExpireDateFromCaps
max: maxExpireDate
}
},

Expand Down Expand Up @@ -377,7 +376,6 @@ export default defineComponent({
link: {
name: this.$gettext('Link'),
permissions: 1,
expiration: this.expirationDate.default,
password: false
}
})
Expand Down Expand Up @@ -408,17 +406,21 @@ export default defineComponent({
},

getExpireDate(currentDate) {
const expireDate = this.capabilities.files_sharing.public.expire_date

if (!currentDate) {
const expireDateDefault = Duration.fromObject(expireDate.default_rw_folders).toObject()
return DateTime.now()
.setLocale(getLocaleFromLanguage(this.$language.current))
.plus({ days: 30 })
.plus(expireDateDefault)
.endOf('day')
.toFormat("yyyy-MM-dd'T'HH:mm:ssZZZ")
}

const expireDateMax = Duration.fromObject(expireDate.max_rw_folders).toObject()
const maxDate = DateTime.now()
.setLocale(getLocaleFromLanguage(this.$language.current))
.plus({ years: 3 })
.plus(expireDateMax)
.endOf('day')
.toFormat("yyyy-MM-dd'T'HH:mm:ssZZZ")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export default defineComponent({
link: {
name: this.$gettext('Quicklink'),
permissions: 1,
expiration: this.expirationDate.enforced ? this.expirationDate.default : null,
quicklink: true,
password: false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,17 @@
class="link-expiry-picker"
:min-date="expirationDate.min"
:max-date="
link.file.type === 'folder' && link.description.toLowerCase() === 'editor'
? new Date(Date.now()).setFullYear(new Date(Date.now()).getFullYear() + 3)
: expirationDate.max
link.file.type === 'folder' &&
link.description.toLowerCase() === 'editor' &&
expirationDate.max
? expirationDate.max
: null
"
:locale="$language.current"
:is-required="
expirationDate.enforce ||
(link.description.toLowerCase() === 'editor' && link.file.type === 'folder')
link.file.type === 'folder' &&
link.description.toLowerCase() === 'editor' &&
expirationDate.max
"
>
<template #default="{ togglePopover }">
Expand Down Expand Up @@ -224,7 +227,7 @@ export default defineComponent({
},
expirationDate: {
type: Object,
default: () => ({}),
default: () => {},
required: true
},
isFolderShare: {
Expand Down Expand Up @@ -294,8 +297,11 @@ export default defineComponent({
showDatepicker: true
})
if (
!this.expirationDate.enforced &&
!(this.link.file.type === 'folder' && this.link.description.toLowerCase() === 'editor')
!(
this.link.file.type === 'folder' &&
this.link.description.toLowerCase() === 'editor' &&
this.expirationDate.max
)
) {
result.push({
id: 'remove-expiration',
Expand Down
2 changes: 2 additions & 0 deletions packages/web-client/src/ocs/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export interface Capabilities {
enabled: boolean
expire_date: {
enabled: boolean
default_rw_folders: object
max_rw_folders: object
}
multiple: boolean
password: {
Expand Down