diff --git a/src/esn.calendar.libs/app/components/event/form/event-form.controller.js b/src/esn.calendar.libs/app/components/event/form/event-form.controller.js index 866ae427..6fc506ed 100644 --- a/src/esn.calendar.libs/app/components/event/form/event-form.controller.js +++ b/src/esn.calendar.libs/app/components/event/form/event-form.controller.js @@ -43,6 +43,7 @@ function CalEventFormController( esnDatetimeService, session, calPathBuilder, + calPathParser, esnI18nService, usSpinnerService, calFreebusyService, @@ -179,15 +180,12 @@ function CalEventFormController( _.find(calendars, 'selected'); } - return calUIAuthorizationService - .canModifyEvent(_getCalendarByUniqueId($scope.editedEvent.calendarUniqueId), $scope.editedEvent, session.user._id) - .then(editable => { - if (editable) { - $scope.calendars = calendars.filter(calendar => calendar.isOwner(session.user._id)); - } + if (calUIAuthorizationService + .canMoveEvent(_getCalendarByUniqueId($scope.editedEvent.calendarUniqueId), session.user._id)) { + $scope.calendars = calendars.filter(calendar => calendar.isOwner(session.user._id)); + } - return _getCalendarByUniqueId($scope.editedEvent.calendarUniqueId); - }); + return _getCalendarByUniqueId($scope.editedEvent.calendarUniqueId); }) .then(function(selectedCalendar) { $scope.selectedCalendar = { uniqueId: selectedCalendar.getUniqueId() }; @@ -214,11 +212,13 @@ function CalEventFormController( return $q.all([ _canModifyEvent(), - calUIAuthorizationService.canModifyEventRecurrence(selectedCalendar, $scope.editedEvent, session.user._id) + calUIAuthorizationService.canModifyEventRecurrence(selectedCalendar, $scope.editedEvent, session.user._id), + calUIAuthorizationService.canMoveEvent(selectedCalendar, session.user._id) ]); - }).then(function(uiAuthorizations) { - $scope.canModifyEvent = uiAuthorizations[0]; - $scope.canModifyEventRecurrence = uiAuthorizations[1]; + }).then(function([canModifyEventAuthorization, canModifyEventRecurrenceAuthorization, canMoveEventAuthorization]) { + $scope.canModifyEvent = canModifyEventAuthorization; + $scope.canModifyEventRecurrence = canModifyEventRecurrenceAuthorization; + $scope.canMoveEvent = canMoveEventAuthorization; $scope.isAnAttendeeCalendar = calEventUtils.canSuggestChanges($scope.editedEvent, session.user) && !$scope.canModifyEvent; setExcludeCurrentUser(); @@ -694,7 +694,7 @@ function CalEventFormController( * @returns {Promise} */ function canPerformCalendarMove(success) { - if (!success) return $q.when(false); + if (!success || !$scope.canMoveEvent) return $q.when(false); return _calendarHasChanged() ? changeCalendar() : $q.when(); } diff --git a/src/esn.calendar.libs/app/components/event/form/event-form.controller.spec.js b/src/esn.calendar.libs/app/components/event/form/event-form.controller.spec.js index 9d105db0..6a80989f 100644 --- a/src/esn.calendar.libs/app/components/event/form/event-form.controller.spec.js +++ b/src/esn.calendar.libs/app/components/event/form/event-form.controller.spec.js @@ -1297,6 +1297,29 @@ describe('The CalEventFormController controller', function() { expect(calOpenEventFormMock).to.have.been.calledWith(sinon.match.any, scope.editedEvent); }); + it('should not attempt to move the event to another calendar if user is not allowed to move event', function() { + const fakeEvent = { + start: start, + end: end, + title: 'oldtitle', + path: '/calendars/owner/id.json', + etag: '123123' + }; + + scope.canMoveEvent = false; + scope.event = CalendarShell.fromIncompleteShell(fakeEvent); + initController(); + + scope.editedEvent = CalendarShell.fromIncompleteShell({ ...fakeEvent, title: 'new title', path: `/calendars/owner/id2/${scope.editedEvent.uid}.ics` }); + scope.selectedCalendar.uniqueId = '/calendars/owner/id2.json'; + scope.calendarHomeId = 'owner'; + + scope.modifyEvent(); + scope.$digest(); + + expect(calEventServiceMock.moveEvent).to.have.not.been.called; + }); + it('should attempt to move the event to another calendar if the organizer changed it', function() { const fakeEvent = { start: start, @@ -1306,6 +1329,7 @@ describe('The CalEventFormController controller', function() { etag: '123123' }; + scope.canMoveEvent = true; scope.event = CalendarShell.fromIncompleteShell(fakeEvent); initController(); @@ -1331,6 +1355,7 @@ describe('The CalEventFormController controller', function() { etag: '123123' }; + scope.canMoveEvent = true; scope.event = CalendarShell.fromIncompleteShell(fakeEvent); initController(); diff --git a/src/esn.calendar.libs/app/components/event/form/event-form.pug b/src/esn.calendar.libs/app/components/event/form/event-form.pug index 03d40fd2..7823772c 100644 --- a/src/esn.calendar.libs/app/components/event/form/event-form.pug +++ b/src/esn.calendar.libs/app/components/event/form/event-form.pug @@ -46,7 +46,7 @@ form.event-form(role="form", name="form", aria-hidden="true", ng-class="{ 'reado i.mdi.mdi-calendar-multiple .fg-line md-input-container(ng-click="changeBackdropZIndex()") - md-select(ng-disabled="!canModifyEvent", ng-model="selectedCalendar.uniqueId", md-container-class="cal-select-dropdown" aria-label="calendar") + md-select(ng-disabled="!canMoveEvent", ng-model="selectedCalendar.uniqueId", md-container-class="cal-select-dropdown" aria-label="calendar") md-option(ng-value="calendar.getUniqueId()" ng-repeat="calendar in calendars | filter: { readOnly: false }") cal-select-calendar-item(calendar="calendar") cal-event-date-edition(event="editedEvent", disabled='!canModifyEvent', use-24hour-format='use24hourFormat', on-date-change='onDateChange') @@ -167,7 +167,7 @@ form.event-form(role="form", name="form", aria-hidden="true", ng-class="{ 'reado span {{ 'Duplicate this event' | translate }} i.mdi.mdi-library-plus .flex-vertical-centered.flex-end - button.btn.btn-link.color-default.close-button(type='button', ng-click="shouldShowMoreOptions = !shouldShowMoreOptions") + button.btn.btn-link.color-default.close-button(type='button', ng-click="shouldShowMoreOptions = !shouldShowMoreOptions") i.mdi.mdi-chevron-down(ng-if="!shouldShowMoreOptions") span(ng-if="!shouldShowMoreOptions") {{ 'More options' | translate }} i.mdi.mdi-chevron-up(ng-if="shouldShowMoreOptions")