Skip to content

Commit

Permalink
Merge pull request #215 from nextcloud/bugfix/205/require_sharing_api
Browse files Browse the repository at this point in the history
require sharingAPI to create new shares
  • Loading branch information
georgehrke authored Dec 10, 2016
2 parents dfd6981 + f826aa1 commit 8ee92bb
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 7 deletions.
6 changes: 4 additions & 2 deletions js/app/controllers/calendarlistcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
* Description: Takes care of CalendarList in App Navigation.
*/

app.controller('CalendarListController', ['$scope', '$rootScope', '$window', 'CalendarService', 'WebCalService', 'is', 'CalendarListItem', 'Calendar', 'MailerService', 'ColorUtility',
function ($scope, $rootScope, $window, CalendarService, WebCalService, is, CalendarListItem, Calendar, MailerService, ColorUtility) {
app.controller('CalendarListController', ['$scope', '$rootScope', '$window', 'CalendarService', 'WebCalService', 'is', 'CalendarListItem', 'Calendar', 'MailerService', 'ColorUtility', 'isSharingAPI',
function ($scope, $rootScope, $window, CalendarService, WebCalService, is, CalendarListItem, Calendar, MailerService, ColorUtility, isSharingAPI) {
'use strict';

$scope.calendarListItems = [];
Expand All @@ -41,6 +41,8 @@ app.controller('CalendarListController', ['$scope', '$rootScope', '$window', 'Ca
$scope.publicdav = 'CalDAV';
$scope.publicdavdesc = t('calendar', 'CalDAV address for clients');

$scope.isSharingAPI = isSharingAPI;

$scope.$watchCollection('calendars', function(newCalendars, oldCalendars) {
newCalendars = newCalendars || [];
oldCalendars = oldCalendars || [];
Expand Down
23 changes: 22 additions & 1 deletion js/app/models/calendarListItemModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
*/

app.factory('CalendarListItem', function(Calendar, WebCal) {
app.factory('CalendarListItem', function(Calendar, WebCal, isSharingAPI) {
'use strict';

function CalendarListItem(calendar) {
Expand Down Expand Up @@ -73,6 +73,27 @@ app.factory('CalendarListItem', function(Calendar, WebCal) {
context.isDisplayingWebCalUrl = false;
};

iface.showSharingIcon = function() {
const isCalendarShareable = context.calendar.isShareable();
const isCalendarShared = context.calendar.isShared();
const isCalendarPublishable = context.calendar.isPublishable();

// Publishing does not depend on sharing API
// always show sharing icon in this case
if (isCalendarPublishable) {
return true;
}

// if the sharing API was disabled, but the calendar was
// previously shared, allow users to edit or remove
// existing shares
if (!isSharingAPI && isCalendarShared && isCalendarShareable) {
return true;
}

return (isSharingAPI && isCalendarShareable);
};

iface.isEditingShares = function() {
return context.isEditingShares;
};
Expand Down
4 changes: 2 additions & 2 deletions js/app/service/calendarService.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ app.service('CalendarService', function(DavClient, StringUtility, XMLUtility, Ca
order: 'a:calendar-order'
};

const SHARE_USER = OC.Share.SHARE_TYPE_USER;
const SHARE_GROUP = OC.Share.SHARE_TYPE_GROUP;
const SHARE_USER = OC.Share ? OC.Share.SHARE_TYPE_USER : 0;
const SHARE_GROUP = OC.Share ? OC.Share.SHARE_TYPE_GROUP : 1;

context.bootPromise = (function() {
if (isPublic) {
Expand Down
3 changes: 3 additions & 0 deletions js/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,8 @@ app.config(['$provide', '$httpProvider',

const isPublic = (angular.element('#fullcalendar').attr('data-isPublic') === '1');
$provide.constant('isPublic', isPublic);

const isSharingAPI = (typeof OC.Share === 'object');
$provide.constant('isSharingAPI', isSharingAPI);
}
]);
3 changes: 2 additions & 1 deletion templates/part.calendarlist.item.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
class="calendarlist-icon share permanent"
ng-class="{'icon-shared': item.calendar.isShared() && !item.calendar.isPublished(), 'icon-public': item.calendar.isPublished(), 'icon-share': !item.calendar.isShared() && !item.calendar.isPublished()}"
ng-click="item.toggleEditingShares()"
ng-if="item.calendar.isShareable()"
ng-if="item.showSharingIcon()"
title="<?php p($l->t('Share Calendar')) ?>"
role="button">
</span>
Expand Down Expand Up @@ -154,6 +154,7 @@ class="app-navigation-entry-menu hidden">
ng-show="loadingSharees">
</i>
<input class="shareeInput"
ng-if="isSharingAPI"
ng-model="item.selectedSharee"
placeholder="<?php p($l->t('Share with users or groups')); ?>"
type="text"
Expand Down
4 changes: 3 additions & 1 deletion tests/js/unit/controllers/calendarlistcontrollerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ describe('CalendarListController', function() {

var controller, $scope, $rootScope, Calendar, CalendarService, $window, calendar, deferred;

beforeEach(module('Calendar'));
beforeEach(module('Calendar', function($provide) {
$provide.value('isSharingAPI', true);
}));

beforeEach(inject(function ($controller, _$rootScope_, _$window_, $q) {
$scope = _$rootScope_.$new();
Expand Down
198 changes: 198 additions & 0 deletions tests/js/unit/models/calendarListItemModelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('The calendarListItem factory', function () {

Calendar.isCalendar = jasmine.createSpy().and.returnValue(true);
$provide.value('Calendar', Calendar);
$provide.value('isSharingAPI', null);
}));

beforeEach(inject(function(_CalendarListItem_) {
Expand Down Expand Up @@ -219,3 +220,200 @@ describe('The calendarListItem factory', function () {
expect(CalendarListItem.isCalendarListItem(item)).toBe(true);
});
});

describe('The calendarListItem factory - sharingAPI enabled', function () {
'use strict';

let CalendarListItem, Calendar;

beforeEach(module('Calendar', function($provide) {
Calendar = {};

Calendar.isCalendar = jasmine.createSpy().and.returnValue(true);
$provide.value('Calendar', Calendar);
$provide.value('isSharingAPI', true);
}));

beforeEach(inject(function(_CalendarListItem_) {
CalendarListItem = _CalendarListItem_;
}));

it ('should correctly determine whether to display the sharing api - 1', () => {
const calendar = {};
calendar.isShareable = jasmine.createSpy().and.returnValue(false);
calendar.isShared = jasmine.createSpy().and.returnValue(false);
calendar.isPublishable = jasmine.createSpy().and.returnValue(false);

const calendarListItem = CalendarListItem(calendar);
expect(calendarListItem.showSharingIcon()).toEqual(false);
});

it ('should correctly determine whether to display the sharing api - 2', () => {
const calendar = {};
calendar.isShareable = jasmine.createSpy().and.returnValue(false);
calendar.isShared = jasmine.createSpy().and.returnValue(false);
calendar.isPublishable = jasmine.createSpy().and.returnValue(true);

const calendarListItem = CalendarListItem(calendar);
expect(calendarListItem.showSharingIcon()).toEqual(true);
});

it ('should correctly determine whether to display the sharing api - 3', () => {
const calendar = {};
calendar.isShareable = jasmine.createSpy().and.returnValue(false);
calendar.isShared = jasmine.createSpy().and.returnValue(true);
calendar.isPublishable = jasmine.createSpy().and.returnValue(false);

const calendarListItem = CalendarListItem(calendar);
expect(calendarListItem.showSharingIcon()).toEqual(false);
});

it ('should correctly determine whether to display the sharing api - 4', () => {
const calendar = {};
calendar.isShareable = jasmine.createSpy().and.returnValue(false);
calendar.isShared = jasmine.createSpy().and.returnValue(true);
calendar.isPublishable = jasmine.createSpy().and.returnValue(true);

const calendarListItem = CalendarListItem(calendar);
expect(calendarListItem.showSharingIcon()).toEqual(true);
});

it ('should correctly determine whether to display the sharing api - 5', () => {
const calendar = {};
calendar.isShareable = jasmine.createSpy().and.returnValue(true);
calendar.isShared = jasmine.createSpy().and.returnValue(false);
calendar.isPublishable = jasmine.createSpy().and.returnValue(false);

const calendarListItem = CalendarListItem(calendar);
expect(calendarListItem.showSharingIcon()).toEqual(true);
});

it ('should correctly determine whether to display the sharing api - 6', () => {
const calendar = {};
calendar.isShareable = jasmine.createSpy().and.returnValue(true);
calendar.isShared = jasmine.createSpy().and.returnValue(false);
calendar.isPublishable = jasmine.createSpy().and.returnValue(true);

const calendarListItem = CalendarListItem(calendar);
expect(calendarListItem.showSharingIcon()).toEqual(true);
});

it ('should correctly determine whether to display the sharing api - 7', () => {
const calendar = {};
calendar.isShareable = jasmine.createSpy().and.returnValue(true);
calendar.isShared = jasmine.createSpy().and.returnValue(true);
calendar.isPublishable = jasmine.createSpy().and.returnValue(false);

const calendarListItem = CalendarListItem(calendar);
expect(calendarListItem.showSharingIcon()).toEqual(true);
});

it ('should correctly determine whether to display the sharing api - 8', () => {
const calendar = {};
calendar.isShareable = jasmine.createSpy().and.returnValue(true);
calendar.isShared = jasmine.createSpy().and.returnValue(true);
calendar.isPublishable = jasmine.createSpy().and.returnValue(true);

const calendarListItem = CalendarListItem(calendar);
expect(calendarListItem.showSharingIcon()).toEqual(true);
});
});

describe('The calendarListItem factory - sharingAPI disabled', function () {
'use strict';

let CalendarListItem, Calendar;

beforeEach(module('Calendar', function($provide) {
Calendar = {};

Calendar.isCalendar = jasmine.createSpy().and.returnValue(true);
$provide.value('Calendar', Calendar);
$provide.value('isSharingAPI', false);
}));

beforeEach(inject(function(_CalendarListItem_) {
CalendarListItem = _CalendarListItem_;
}));

it ('should correctly determine whether to display the sharing api - 1', () => {
const calendar = {};
calendar.isShareable = jasmine.createSpy().and.returnValue(false);
calendar.isShared = jasmine.createSpy().and.returnValue(false);
calendar.isPublishable = jasmine.createSpy().and.returnValue(false);

const calendarListItem = CalendarListItem(calendar);
expect(calendarListItem.showSharingIcon()).toEqual(false);
});

it ('should correctly determine whether to display the sharing api - 2', () => {
const calendar = {};
calendar.isShareable = jasmine.createSpy().and.returnValue(false);
calendar.isShared = jasmine.createSpy().and.returnValue(false);
calendar.isPublishable = jasmine.createSpy().and.returnValue(true);

const calendarListItem = CalendarListItem(calendar);
expect(calendarListItem.showSharingIcon()).toEqual(true);
});

it ('should correctly determine whether to display the sharing api - 3', () => {
const calendar = {};
calendar.isShareable = jasmine.createSpy().and.returnValue(false);
calendar.isShared = jasmine.createSpy().and.returnValue(true);
calendar.isPublishable = jasmine.createSpy().and.returnValue(false);

const calendarListItem = CalendarListItem(calendar);
expect(calendarListItem.showSharingIcon()).toEqual(false);
});

it ('should correctly determine whether to display the sharing api - 4', () => {
const calendar = {};
calendar.isShareable = jasmine.createSpy().and.returnValue(false);
calendar.isShared = jasmine.createSpy().and.returnValue(true);
calendar.isPublishable = jasmine.createSpy().and.returnValue(true);

const calendarListItem = CalendarListItem(calendar);
expect(calendarListItem.showSharingIcon()).toEqual(true);
});

it ('should correctly determine whether to display the sharing api - 5', () => {
const calendar = {};
calendar.isShareable = jasmine.createSpy().and.returnValue(true);
calendar.isShared = jasmine.createSpy().and.returnValue(false);
calendar.isPublishable = jasmine.createSpy().and.returnValue(false);

const calendarListItem = CalendarListItem(calendar);
expect(calendarListItem.showSharingIcon()).toEqual(false);
});

it ('should correctly determine whether to display the sharing api - 6', () => {
const calendar = {};
calendar.isShareable = jasmine.createSpy().and.returnValue(true);
calendar.isShared = jasmine.createSpy().and.returnValue(false);
calendar.isPublishable = jasmine.createSpy().and.returnValue(true);

const calendarListItem = CalendarListItem(calendar);
expect(calendarListItem.showSharingIcon()).toEqual(true);
});

it ('should correctly determine whether to display the sharing api - 7', () => {
const calendar = {};
calendar.isShareable = jasmine.createSpy().and.returnValue(true);
calendar.isShared = jasmine.createSpy().and.returnValue(true);
calendar.isPublishable = jasmine.createSpy().and.returnValue(false);

const calendarListItem = CalendarListItem(calendar);
expect(calendarListItem.showSharingIcon()).toEqual(true);
});

it ('should correctly determine whether to display the sharing api - 8', () => {
const calendar = {};
calendar.isShareable = jasmine.createSpy().and.returnValue(true);
calendar.isShared = jasmine.createSpy().and.returnValue(true);
calendar.isPublishable = jasmine.createSpy().and.returnValue(true);

const calendarListItem = CalendarListItem(calendar);
expect(calendarListItem.showSharingIcon()).toEqual(true);
});
});

0 comments on commit 8ee92bb

Please sign in to comment.