Skip to content

Commit

Permalink
linagora#611: Fix calendar display when user can change event calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
renaudboyer committed Apr 13, 2022
1 parent 7ee7fe0 commit 7a608e7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function CalEventFormController(
}

if (calUIAuthorizationService
.canMoveEvent(_getCalendarByUniqueId($scope.editedEvent.calendarUniqueId), session.user._id)) {
.canMoveEvent(_getCalendarByUniqueId($scope.editedEvent.calendarUniqueId), $scope.editedEvent, session.user)) {
$scope.calendars = calendars.filter(calendar => calendar.isOwner(session.user._id));
}

Expand Down Expand Up @@ -212,7 +212,7 @@ function CalEventFormController(
return $q.all([
_canModifyEvent(),
calUIAuthorizationService.canModifyEventRecurrence(selectedCalendar, $scope.editedEvent, session.user._id),
calUIAuthorizationService.canMoveEvent(selectedCalendar, session.user._id)
calUIAuthorizationService.canMoveEvent(selectedCalendar, $scope.editedEvent, session.user)
]);
}).then(function([canModifyEventAuthorization, canModifyEventRecurrenceAuthorization, canMoveEventAuthorization]) {
$scope.canModifyEvent = canModifyEventAuthorization;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ form.event-form(role="form", name="form", aria-hidden="true", ng-class="{ 'reado
.fg-line
md-input-container(ng-click="changeBackdropZIndex()")
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 }")
md-option(ng-value="calendar.getUniqueId()" ng-repeat="calendar in calendars | filter: canMoveEvent ? { readOnly: false } : {}")
cal-select-calendar-item(calendar="calendar")
cal-event-date-edition(event="editedEvent", disabled='!canModifyEvent', use-24hour-format='use24hourFormat', on-date-change='onDateChange')
cal-entities-autocomplete-input.cal-user-autocomplete-input(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ function calUIAuthorizationService(
return !!calendar && (calendar.isOwner(userId) || calendar.isShared(userId) || calendar.isSubscription());
}

function canMoveEvent(calendar, userId) {
return calendar.isOwner(userId);
function canMoveEvent(calendar, event, user) {
return calendar.isOwner(user._id) && calEventUtils.isOrganizer(event, user);
}

function canShowDelegationTab(calendar, userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,25 +518,39 @@ describe('The calUIAuthorizationService service', function() {
});

describe('the canMoveEvent function', function() {
var calendar, userId = 'userId';
var calendar, event = 'event', user = { _id: 'userId' };

it('should return false if user is not the owner of the calendar', function() {
calendar = {
isOwner: sinon.stub().returns(false)
};
const result = calUIAuthorizationService.canMoveEvent(calendar, userId);
const result = calUIAuthorizationService.canMoveEvent(calendar, event, user);

expect(calendar.isOwner).to.have.been.calledWith(userId);
expect(calendar.isOwner).to.have.been.calledWith(user._id);
expect(calEventUtils.isOrganizer).to.not.have.been.called;
expect(result).to.be.false;
});

it('should return false if user is the owner of the calendar but user is not event organizer', function() {
calendar = {
isOwner: sinon.stub().returns(true)
};
const result = calUIAuthorizationService.canMoveEvent(calendar, event, user);

expect(calendar.isOwner).to.have.been.calledWith(user._id);
expect(calEventUtils.isOrganizer).to.have.been.calledWith(event, user);
expect(result).to.be.false;
});

it('should return true if user is the owner of the calendar', function() {
calendar = {
isOwner: sinon.stub().returns(true)
};
const result = calUIAuthorizationService.canMoveEvent(calendar, userId);
calEventUtils.isOrganizer = sinon.stub().returns(true);
const result = calUIAuthorizationService.canMoveEvent(calendar, event, user);

expect(calendar.isOwner).to.have.been.calledWith(userId);
expect(calendar.isOwner).to.have.been.calledWith(user._id);
expect(calEventUtils.isOrganizer).to.have.been.calledWith(event, user);
expect(result).to.be.true;
});
});
Expand Down

0 comments on commit 7a608e7

Please sign in to comment.