Skip to content

Commit

Permalink
linagora#611: Leverage canMoveEvent to have move event logic
Browse files Browse the repository at this point in the history
  • Loading branch information
renaudboyer committed Mar 25, 2022
1 parent 1d8118a commit 630521b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function CalEventFormController(
esnDatetimeService,
session,
calPathBuilder,
calPathParser,
esnI18nService,
usSpinnerService,
calFreebusyService,
Expand Down Expand Up @@ -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() };
Expand All @@ -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();

Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -1306,6 +1329,7 @@ describe('The CalEventFormController controller', function() {
etag: '123123'
};

scope.canMoveEvent = true;
scope.event = CalendarShell.fromIncompleteShell(fakeEvent);
initController();

Expand All @@ -1331,6 +1355,7 @@ describe('The CalEventFormController controller', function() {
etag: '123123'
};

scope.canMoveEvent = true;
scope.event = CalendarShell.fromIncompleteShell(fakeEvent);
initController();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 630521b

Please sign in to comment.