From a103fd7a840d4c5c4ba531235b6276857d535ec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raimund=20Schl=C3=BC=C3=9Fler?= Date: Mon, 10 Feb 2020 22:42:58 +0100 Subject: [PATCH 1/2] Don't edit not public tasks in lists shared to me MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Raimund Schlüßler --- css/src/style.scss | 5 + src/App.vue | 45 +++--- .../AppNavigation/ListItemCalendar.vue | 53 +++++-- src/components/TheDetails.vue | 56 ++++--- src/models/principal.js | 67 ++++++++ src/store/calendars.js | 24 ++- src/store/principals.js | 148 ++++++++++++++++++ src/store/store.js | 2 + src/store/tasks.js | 29 +++- tests/javascript/unit/setupStore.js | 2 + 10 files changed, 376 insertions(+), 55 deletions(-) create mode 100644 src/models/principal.js create mode 100644 src/store/principals.js diff --git a/css/src/style.scss b/css/src/style.scss index ee6c10607..4ea8c3783 100644 --- a/css/src/style.scss +++ b/css/src/style.scss @@ -31,6 +31,11 @@ display: none; } } + + .app-navigation-entry__utils .icon-loading { + height: 32px; + width: 32px; + } } &.edit { diff --git a/src/App.vue b/src/App.vue index c1add7b67..c1c6ccbc7 100644 --- a/src/App.vue +++ b/src/App.vue @@ -61,27 +61,34 @@ export default { calendars: state => state.calendars.calendars, }), }, - beforeMount() { + async beforeMount() { // get calendars then get tasks - client.connect({ enableCalDAV: true }).then(() => { - this.$store.dispatch('getCalendars') - .then((calendars) => { - // No calendars? Create a new one! - if (calendars.length === 0) { - let color = '#0082C9' - if (this.$OCA.Theming) { - color = this.$OCA.Theming.color - } - this.$store.dispatch('appendCalendar', { displayName: this.$t('tasks', 'Tasks'), color }) - .then(() => { - this.fetchTasks() - }) - // else, let's get those tasks! - } else { - this.fetchTasks() - } - }) + await client.connect({ enableCalDAV: true }) + await this.$store.dispatch('fetchCurrentUserPrincipal') + const calendars = await this.$store.dispatch('getCalendars') + const owners = [] + calendars.forEach((calendar) => { + if (owners.indexOf(calendar.owner) === -1) { + owners.push(calendar.owner) + } + }) + owners.forEach((owner) => { + this.$store.dispatch('fetchPrincipalByUrl', { + url: owner, + }) }) + // No calendars? Create a new one! + if (calendars.length === 0) { + let color = '#0082C9' + if (this.$OCA.Theming) { + color = this.$OCA.Theming.color + } + await this.$store.dispatch('appendCalendar', { displayName: this.$t('tasks', 'Tasks'), color }) + this.fetchTasks() + // else, let's get those tasks! + } else { + this.fetchTasks() + } }, methods: { /** diff --git a/src/components/AppNavigation/ListItemCalendar.vue b/src/components/AppNavigation/ListItemCalendar.vue index 05dc7c217..48b1f2d2b 100644 --- a/src/components/AppNavigation/ListItemCalendar.vue +++ b/src/components/AppNavigation/ListItemCalendar.vue @@ -37,18 +37,18 @@ License along with this library. If not, see . @@ -130,6 +129,7 @@ import Colorpicker from './Colorpicker' import ShareCalendar from './CalendarShare' import ClickOutside from 'vue-click-outside' +import Avatar from '@nextcloud/vue/dist/Components/Avatar' import AppNavigationItem from '@nextcloud/vue/dist/Components/AppNavigationItem' import AppNavigationCounter from '@nextcloud/vue/dist/Components/AppNavigationCounter' import AppNavigationIconBullet from '@nextcloud/vue/dist/Components/AppNavigationIconBullet' @@ -143,6 +143,7 @@ export default { components: { Colorpicker, ShareCalendar, + Avatar, AppNavigationItem, AppNavigationCounter, AppNavigationIconBullet, @@ -190,16 +191,26 @@ export default { }, computed: { ...mapGetters({ - calendarCount: 'getCalendarCount', + getCalendarCount: 'getCalendarCount', isCalendarNameUsed: 'isCalendarNameUsed', getTask: 'getTaskByUri', + getPrincipalByUrl: 'getPrincipalByUrl', }), + calendarCount() { + return this.getCalendarCount(this.calendar.id) + }, + deleteMessage() { return !this.calendar.isSharedWithMe ? this.$t('tasks', 'This will delete the calendar "{calendar}" and all corresponding events and tasks.', { calendar: this.calendar.displayName }) : this.$t('tasks', 'This will unshare the calendar "{calendar}".', { calendar: this.calendar.displayName }) }, + undoDeleteMessage() { + return !this.calendar.isSharedWithMe + ? this.$n('tasks', 'Deleting the calendar in {countdown} second', 'Deleting the calendar in {countdown} seconds', this.countdown, { countdown: this.countdown }) + : this.$n('tasks', 'Unsharing the calendar in {countdown} second', 'Unsharing the calendar in {countdown} seconds', this.countdown, { countdown: this.countdown }) + }, sharingIconClass() { if (this.calendar.shares.length) { return 'icon-shared' @@ -233,6 +244,28 @@ export default { }) : '' // disable the tooltip }, + /** + * Whether or not the information about the owner principal was loaded + * + * @returns {Boolean} + */ + loadedOwnerPrincipal() { + return this.getPrincipalByUrl(this.calendar.owner) !== undefined + }, + ownerUserId() { + const principal = this.getPrincipalByUrl(this.calendar.owner) + if (principal) { + return principal.userId + } + return '' + }, + ownerDisplayname() { + const principal = this.getPrincipalByUrl(this.calendar.owner) + if (principal) { + return principal.displayname + } + return '' + }, }, methods: { ...mapActions([ diff --git a/src/components/TheDetails.vue b/src/components/TheDetails.vue index 676257760..03e4bc5d1 100644 --- a/src/components/TheDetails.vue +++ b/src/components/TheDetails.vue @@ -22,7 +22,7 @@ License along with this library. If not, see .