summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/src
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@protonmail.com>2022-11-16 12:19:35 +0100
committernextcloud-command <nextcloud-command@users.noreply.github.com>2022-11-16 22:41:08 +0000
commita994472e47eaf7028c02ed16811ba17bf1c32862 (patch)
tree6f63b28085bb28f539af24878a36deabde7a7fa9 /apps/files_sharing/src
parent42140fe8e11791d3f7a69620186bd50544c38a86 (diff)
downloadnextcloud-server-a994472e47eaf7028c02ed16811ba17bf1c32862.tar.gz
nextcloud-server-a994472e47eaf7028c02ed16811ba17bf1c32862.zip
Fix date handling and saving
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com> Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
Diffstat (limited to 'apps/files_sharing/src')
-rw-r--r--apps/files_sharing/src/components/SharingEntry.vue12
-rw-r--r--apps/files_sharing/src/components/SharingEntryLink.vue50
-rw-r--r--apps/files_sharing/src/mixins/SharesMixin.js41
-rw-r--r--apps/files_sharing/src/models/Share.js4
4 files changed, 69 insertions, 38 deletions
diff --git a/apps/files_sharing/src/components/SharingEntry.vue b/apps/files_sharing/src/components/SharingEntry.vue
index 7cc283e705c..932f65c20b2 100644
--- a/apps/files_sharing/src/components/SharingEntry.vue
+++ b/apps/files_sharing/src/components/SharingEntry.vue
@@ -99,7 +99,7 @@
:hide-label="true"
:class="{ error: errors.expireDate}"
:disabled="saving"
- :value="share.expireDate"
+ :value="new Date(share.expireDate)"
type="date"
:min="dateTomorrow"
:max="dateMaxEnforced"
@@ -149,7 +149,7 @@ import NcActionInput from '@nextcloud/vue/dist/Components/NcActionInput'
import NcActionTextEditable from '@nextcloud/vue/dist/Components/NcActionTextEditable'
import Tooltip from '@nextcloud/vue/dist/Directives/Tooltip'
-import SharesMixin from '../mixins/SharesMixin'
+import SharesMixin from '../mixins/SharesMixin.js'
export default {
name: 'SharingEntry',
@@ -374,12 +374,10 @@ export default {
return this.config.isDefaultInternalExpireDateEnforced || !!this.share.expireDate
},
set(enabled) {
- let defaultExpirationDate = this.config.defaultInternalExpirationDate
- if (!defaultExpirationDate) {
- defaultExpirationDate = new Date()
- }
+ const defaultExpirationDate = this.config.defaultInternalExpirationDate
+ || new Date(new Date().setDate(new Date().getDate() + 1))
this.share.expireDate = enabled
- ? defaultExpirationDate
+ ? this.formatDateToString(defaultExpirationDate)
: ''
console.debug('Expiration date status', enabled, this.share.expireDate)
},
diff --git a/apps/files_sharing/src/components/SharingEntryLink.vue b/apps/files_sharing/src/components/SharingEntryLink.vue
index e1118e680c0..207db7d8514 100644
--- a/apps/files_sharing/src/components/SharingEntryLink.vue
+++ b/apps/files_sharing/src/components/SharingEntryLink.vue
@@ -97,14 +97,15 @@
{{ t('files_sharing', 'Expiration date (enforced)') }}
</NcActionText>
<NcActionInput v-if="pendingExpirationDate"
- v-model="share.expireDate"
class="share-link-expire-date"
:disabled="saving"
:is-native-picker="true"
:hide-label="true"
+ :value="new Date(share.expireDate)"
type="date"
:min="dateTomorrow"
- :max="dateMaxEnforced">
+ :max="dateMaxEnforced"
+ @input="onExpirationChange">
<!-- let's not submit when picked, the user
might want to still edit or copy the password -->
{{ t('files_sharing', 'Enter a date') }}
@@ -218,7 +219,7 @@
class="share-link-expire-date"
:class="{ error: errors.expireDate}"
:disabled="saving"
- :value="share.expireDate"
+ :value="new Date(share.expireDate)"
type="date"
:min="dateTomorrow"
:max="dateMaxEnforced"
@@ -298,6 +299,7 @@
<script>
import { generateUrl } from '@nextcloud/router'
+import { showError } from '@nextcloud/dialogs'
import { Type as ShareTypes } from '@nextcloud/sharing'
import Vue from 'vue'
@@ -312,11 +314,11 @@ import NcActions from '@nextcloud/vue/dist/Components/NcActions'
import NcAvatar from '@nextcloud/vue/dist/Components/NcAvatar'
import Tooltip from '@nextcloud/vue/dist/Directives/Tooltip'
-import ExternalShareAction from './ExternalShareAction'
-import SharePermissionsEditor from './SharePermissionsEditor'
-import GeneratePassword from '../utils/GeneratePassword'
-import Share from '../models/Share'
-import SharesMixin from '../mixins/SharesMixin'
+import ExternalShareAction from './ExternalShareAction.vue'
+import SharePermissionsEditor from './SharePermissionsEditor.vue'
+import GeneratePassword from '../utils/GeneratePassword.js'
+import Share from '../models/Share.js'
+import SharesMixin from '../mixins/SharesMixin.js'
export default {
name: 'SharingEntryLink',
@@ -422,12 +424,10 @@ export default {
|| !!this.share.expireDate
},
set(enabled) {
- let defaultExpirationDate = this.config.defaultExpirationDate
- if (!defaultExpirationDate) {
- defaultExpirationDate = new Date()
- }
- this.share.state.expiration = enabled
- ? defaultExpirationDate
+ const defaultExpirationDate = this.config.defaultExpirationDate
+ || new Date(new Date().setDate(new Date().getDate() + 1))
+ this.share.expireDate = enabled
+ ? this.formatDateToString(defaultExpirationDate)
: ''
console.debug('Expiration date status', enabled, this.share.expireDate)
},
@@ -435,7 +435,7 @@ export default {
dateMaxEnforced() {
if (this.config.isDefaultExpireDateEnforced) {
- return new Date(new Date().setDate(new Date().getDate() + 1 + this.config.defaultExpireDate))
+ return new Date(new Date().setDate(new Date().getDate() + this.config.defaultExpireDate))
}
return null
},
@@ -620,7 +620,7 @@ export default {
if (this.config.isDefaultExpireDateEnforced) {
// default is empty string if not set
// expiration is the share object key, not expireDate
- shareDefaults.expiration = this.config.defaultExpirationDate
+ shareDefaults.expiration = this.formatDateToString(this.config.defaultExpirationDate)
}
if (this.config.enableLinkPasswordByDefault) {
shareDefaults.password = await GeneratePassword()
@@ -687,7 +687,7 @@ export default {
this.errors = {}
const path = (this.fileInfo.path + '/' + this.fileInfo.name).replace('//', '/')
- const newShare = await this.createShare({
+ const options = {
path,
shareType: ShareTypes.SHARE_TYPE_LINK,
password: share.password,
@@ -698,10 +698,12 @@ export default {
// Todo: We also need to fix the createShare method in
// lib/Controller/ShareAPIController.php to allow file drop
// (currently not supported on create, only update)
- })
+ }
- this.open = false
+ console.debug('Creating link share with options', options)
+ const newShare = await this.createShare(options)
+ this.open = false
console.debug('Link share created', newShare)
// if share already exists, copy link directly on next tick
@@ -728,8 +730,14 @@ export default {
component.copyLink()
}
- } catch ({ response }) {
- const message = response.data.ocs.meta.message
+ } catch (data) {
+ const message = data?.response?.data?.ocs?.meta?.message
+ if (!message) {
+ showError(t('sharing', 'Error while creating the share'))
+ console.error(data)
+ return
+ }
+
if (message.match(/password/i)) {
this.onSyncError('password', message)
} else if (message.match(/date/i)) {
diff --git a/apps/files_sharing/src/mixins/SharesMixin.js b/apps/files_sharing/src/mixins/SharesMixin.js
index cdedd213aff..68468d76de4 100644
--- a/apps/files_sharing/src/mixins/SharesMixin.js
+++ b/apps/files_sharing/src/mixins/SharesMixin.js
@@ -25,15 +25,15 @@
*
*/
+import { getCurrentUser } from '@nextcloud/auth'
// eslint-disable-next-line import/no-unresolved, node/no-missing-import
import PQueue from 'p-queue'
import debounce from 'debounce'
-import Share from '../models/Share'
-import SharesRequests from './ShareRequests'
-import ShareTypes from './ShareTypes'
-import Config from '../services/ConfigService'
-import { getCurrentUser } from '@nextcloud/auth'
+import Share from '../models/Share.js'
+import SharesRequests from './ShareRequests.js'
+import ShareTypes from './ShareTypes.js'
+import Config from '../services/ConfigService.js'
export default {
mixins: [SharesRequests, ShareTypes],
@@ -151,12 +151,35 @@ export default {
},
/**
+ * @param {string} date a date with YYYY-MM-DD format
+ * @return {Date} date
+ */
+ parseDateString(date) {
+ if (!date) {
+ return
+ }
+ const regex = /([0-9]{4}-[0-9]{2}-[0-9]{2})/i
+ return new Date(date.match(regex)?.pop())
+ },
+
+ /**
+ * @param {Date} date
+ * @return {string} date a date with YYYY-MM-DD format
+ */
+ formatDateToString(date) {
+ // Force utc time. Drop time information to be timezone-less
+ const utcDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()))
+ // Format to YYYY-MM-DD
+ return utcDate.toISOString().split('T')[0]
+ },
+
+ /**
* Save given value to expireDate and trigger queueUpdate
*
* @param {Date} date
*/
onExpirationChange(date) {
- this.share.expireDate = date
+ this.share.expireDate = this.formatDateToString(date)
this.queueUpdate('expireDate')
},
@@ -258,9 +281,11 @@ export default {
this.saving = false
}
})
- } else {
- console.error('Cannot update share.', this.share, 'No valid id')
+ return
}
+
+ // This share does not exists on the server yet
+ console.debug('Updated local share', this.share)
},
/**
diff --git a/apps/files_sharing/src/models/Share.js b/apps/files_sharing/src/models/Share.js
index bc35cefb1a7..9b1535184a0 100644
--- a/apps/files_sharing/src/models/Share.js
+++ b/apps/files_sharing/src/models/Share.js
@@ -250,7 +250,7 @@ export default class Share {
/**
* Get the expiration date
*
- * @return {Date|null}
+ * @return {string} date with YYYY-MM-DD format
* @readonly
* @memberof Share
*/
@@ -261,7 +261,7 @@ export default class Share {
/**
* Set the expiration date
*
- * @param {Date|null} date the share expiration date
+ * @param {string} date the share expiration date with YYYY-MM-DD format
* @memberof Share
*/
set expireDate(date) {