Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a calendar to be shared with circles. #602

Merged
merged 1 commit into from
Mar 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions js/app/controllers/calendarlistcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
*
* @author Raghu Nayyar
* @author Georg Ehrke
* @author Vinicius Cubas Brand
* @author Daniel Tygel
* @copyright 2016 Raghu Nayyar <[email protected]>
* @copyright 2016 Georg Ehrke <[email protected]>
* @copyright 2017 Vinicius Cubas Brand <[email protected]>
* @copyright 2017 Daniel Tygel <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
Expand Down Expand Up @@ -220,7 +224,7 @@ app.controller('CalendarListController', ['$scope', '$rootScope', '$window', 'Ha

$scope.onSelectSharee = function (item, model, label, calendarItem) {
const calendar = calendarItem.calendar;
// Create a default share with the user/group, read only
// Create a default share with the user/group/circle, read only
calendar.share(item.type, item.identifier, item.displayname, false, false).then(function() {
// Remove content from text box
calendarItem.selectedSharee = '';
Expand All @@ -241,6 +245,12 @@ app.controller('CalendarListController', ['$scope', '$rootScope', '$window', 'Ha
});
};

$scope.updateExistingCircleShare = function(calendar, circleId, displayname, writable) {
calendar.share(constants.SHARE_TYPE_CIRCLE, circleId, displayname, writable, true).then(function() {
$scope.$apply();
});
};

$scope.unshareFromUser = function(calendar, userId) {
calendar.unshare(constants.SHARE_TYPE_USER, userId).then(function() {
$scope.$apply();
Expand All @@ -253,6 +263,12 @@ app.controller('CalendarListController', ['$scope', '$rootScope', '$window', 'Ha
});
};

$scope.unshareFromCircle = function(calendar, circleId) {
calendar.unshare(constants.SHARE_TYPE_CIRCLE, circleId).then(function() {
$scope.$apply();
});
};

$scope.findSharee = function (val, calendar) {
return $.get(
OC.linkToOCS('apps/files_sharing/api/v1') + 'sharees',
Expand All @@ -265,11 +281,14 @@ app.controller('CalendarListController', ['$scope', '$rootScope', '$window', 'Ha
).then(function(result) {
var users = result.ocs.data.exact.users.concat(result.ocs.data.users);
var groups = result.ocs.data.exact.groups.concat(result.ocs.data.groups);
var circles = result.ocs.data.exact.circles.concat(result.ocs.data.circles);

var userShares = calendar.shares.users;
var groupShares = calendar.shares.groups;
var circleShares = calendar.shares.circles;
var userSharesLength = userShares.length;
var groupSharesLength = groupShares.length;
var circleSharesLength = circleShares.length;
var i, j;

// Filter out current user
Expand All @@ -293,7 +312,7 @@ app.controller('CalendarListController', ['$scope', '$rootScope', '$window', 'Ha
}
}

// Combine users and groups
// Combine users, groups and circles
users = users.map(function(item){
return {
display: _.escape(item.label),
Expand All @@ -312,7 +331,16 @@ app.controller('CalendarListController', ['$scope', '$rootScope', '$window', 'Ha
};
});

return groups.concat(users);
circles = circles.map(function(item){
return {
display: item.label + ' (' + t('calendar', 'circle') + ')',
displayname: item.label,
type: constants.SHARE_TYPE_CIRCLE,
identifier: item.value.shareWith
};
});

return circles.concat(groups).concat(users);
});
};

Expand Down
18 changes: 16 additions & 2 deletions js/app/factory/calendarFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
* Calendar App
*
* @author Georg Ehrke
* @author Vinicius Cubas Brand
* @author Daniel Tygel
* @copyright 2016 Georg Ehrke <[email protected]>
* @copyright 2017 Vinicius Cubas Brand <[email protected]>
* @copyright 2017 Daniel Tygel <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
Expand All @@ -26,6 +30,7 @@ app.service('CalendarFactory', function(DavClient, Calendar, WebCal, constants)

const SHARE_USER_PREFIX = 'principal:principals/users/';
const SHARE_GROUP_PREFIX = 'principal:principals/groups/';
const SHARE_CIRCLE_PREFIX = 'principal:principals/circles/';

context.acl = function(props, userPrincipal) {
const acl = props['{' + DavClient.NS_DAV + '}acl'] || [];
Expand Down Expand Up @@ -125,7 +130,8 @@ app.service('CalendarFactory', function(DavClient, Calendar, WebCal, constants)
const shareProp = props['{' + DavClient.NS_OWNCLOUD + '}invite'];
const shares = {
users: [],
groups: []
groups: [],
circles: []
};
let ownerDisplayname = null;

Expand All @@ -149,8 +155,10 @@ app.service('CalendarFactory', function(DavClient, Calendar, WebCal, constants)
if (displayName.length === 0) {
if (href.startsWith(SHARE_USER_PREFIX)) {
displayName = href.substr(SHARE_USER_PREFIX.length);
} else {
} else if (href.startsWith(SHARE_GROUP_PREFIX)) {
displayName = href.substr(SHARE_GROUP_PREFIX.length);
} else {
displayName = href.substr(SHARE_CIRCLE_PREFIX.length);
}
} else {
displayName = displayName[0].textContent;
Expand Down Expand Up @@ -184,6 +192,12 @@ app.service('CalendarFactory', function(DavClient, Calendar, WebCal, constants)
displayname: displayName,
writable: writable
});
} else if (href.startsWith(SHARE_CIRCLE_PREFIX)) {
shares.circles.push({
id: href.substr(SHARE_CIRCLE_PREFIX.length),
displayname: displayName,
writable: writable
});
}
});

Expand Down
9 changes: 7 additions & 2 deletions js/app/models/calendarmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
* Nextcloud - Calendar App
*
* @author Georg Ehrke
* @author Vinicius Cubas Brand
* @author Daniel Tygel
* @copyright 2016 Georg Ehrke <[email protected]>
* @copyright 2017 Vinicius Cubas Brand <[email protected]>
* @copyright 2017 Daniel Tygel <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
Expand Down Expand Up @@ -297,8 +301,9 @@ app.factory('Calendar', function($window, Hook, VEventService, TimezoneService,
};

iface.isShared = function() {
return context.shares.groups.length !== 0 ||
context.shares.users.length !== 0;
return context.shares.circles.length !== 0 ||
context.shares.groups.length !== 0 ||
context.shares.users.length !== 0;
};

iface.isPublished = function() {
Expand Down
26 changes: 22 additions & 4 deletions js/app/service/calendarService.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
*
* @author Raghu Nayyar
* @author Georg Ehrke
* @author Vinicius Cubas Brand
* @author Daniel Tygel
* @copyright 2016 Raghu Nayyar <[email protected]>
* @copyright 2016 Georg Ehrke <[email protected]>
* @copyright 2017 Vinicius Cubas Brand <[email protected]>
* @copyright 2017 Daniel Tygel <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
Expand Down Expand Up @@ -73,6 +77,7 @@ app.service('CalendarService', function(DavClient, StringUtility, XMLUtility, Ca

const SHARE_USER = constants.SHARE_TYPE_USER;
const SHARE_GROUP = constants.SHARE_TYPE_GROUP;
const SHARE_CIRCLE = constants.SHARE_TYPE_CIRCLE;

context.bootPromise = (function() {
if (isPublic) {
Expand Down Expand Up @@ -138,15 +143,17 @@ app.service('CalendarService', function(DavClient, StringUtility, XMLUtility, Ca
};

context.getShareValue = function(shareType, shareWith) {
if (shareType !== SHARE_USER && shareType !== SHARE_GROUP) {
if (shareType !== SHARE_USER && shareType !== SHARE_GROUP && shareType !== SHARE_CIRCLE) {
throw new Error('Unknown shareType given');
}

let hrefValue;
if (shareType === SHARE_USER) {
hrefValue = 'principal:principals/users/';
} else {
} else if (shareType === SHARE_GROUP) {
hrefValue = 'principal:principals/groups/';
} else {
hrefValue = 'principal:principals/circles/';
}
hrefValue += shareWith;

Expand Down Expand Up @@ -559,12 +566,18 @@ app.service('CalendarService', function(DavClient, StringUtility, XMLUtility, Ca
displayname: shareWithDisplayname,
writable: writable
});
} else {
} else if (shareType === SHARE_GROUP) {
calendar.shares.groups.push({
id: shareWith,
displayname: shareWithDisplayname,
writable: writable
});
} else {
calendar.shares.circles.push({
id: shareWith,
displayname: shareWithDisplayname,
writable: writable
});
}
});
};
Expand Down Expand Up @@ -604,11 +617,16 @@ app.service('CalendarService', function(DavClient, StringUtility, XMLUtility, Ca
return user.id === shareWith;
});
calendar.shares.users.splice(index, 1);
} else {
} else if (shareType === SHARE_GROUP) {
const index = calendar.shares.groups.findIndex(function(group) {
return group.id === shareWith;
});
calendar.shares.groups.splice(index, 1);
} else {
const index = calendar.shares.circles.findIndex(function(circle) {
return circle.id === shareWith;
});
calendar.shares.circles.splice(index, 1);
}
});
};
Expand Down
3 changes: 2 additions & 1 deletion js/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ app.config(['$provide', '$httpProvider',
shareeCanEditCalendarProperties,
canSharePublicLink,
SHARE_TYPE_USER: 0,
SHARE_TYPE_GROUP: 1
SHARE_TYPE_GROUP: 1,
SHARE_TYPE_CIRCLE: 7
});
}
]);
33 changes: 32 additions & 1 deletion templates/part.calendarlist.item.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
*
* @author Raghu Nayyar
* @author Georg Ehrke
* @author Vinicius Cubas Brand
* @author Daniel Tygel
* @copyright 2016 Raghu Nayyar <[email protected]>
* @copyright 2016 Georg Ehrke <[email protected]>
* @copyright 2017 Vinicius Cubas Brand <[email protected]>
* @copyright 2017 Daniel Tygel <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
Expand Down Expand Up @@ -127,7 +131,7 @@ class="app-navigation-entry-menu hidden">
<input class="shareeInput"
ng-if="isSharingAPI"
ng-model="item.selectedSharee"
placeholder="<?php p($l->t('Share with users or groups')); ?>"
placeholder="<?php p($l->t('Share with users, groups or circles')); ?>"
type="text"
typeahead-on-select="onSelectSharee($item, $model, $label, item)"
typeahead-loading="loadingSharees"
Expand Down Expand Up @@ -188,6 +192,33 @@ class="checkbox"
</span>
</span>
</li>
<li class="calendar-share-item"
ng-repeat="circleShare in item.calendar.shares.circles"
title="{{ circleShare.displayname }} (<?php p($l->t('circle')); ?>)">
{{ circleShare.displayname }} (<?php p($l->t('circle')); ?>) -
<span>
<input id="checkbox_sharedWithCircle_{{ $parent.$index }}_{{ $id }}"
name="editable"
class="checkbox"
ng-change="updateExistingCircleShare(item.calendar, circleShare.id, circleShare.displayname, circleShare.writable)"
ng-model="circleShare.writable"
type="checkbox"
value="edit">
<label for="checkbox_sharedWithCircle_{{ $parent.$index }}_{{ $id }}">
<?php p($l->t('can edit')); ?>
</label>
</span>
<span class="utils hide">
<span class="action">
<span class="icon-delete"
href="#"
id="calendarlist-icon delete"
ng-click="unshareFromCircle(item.calendar, circleShare.id)"
title="<?php p($l->t('Delete')); ?>">
</span>
</span>
</span>
</li>
</ul>
<div class="publishing" ng-if="item.calendar.isPublishable() && canSharePublicLink">
<input type="checkbox" name="publish"
Expand Down
3 changes: 2 additions & 1 deletion tests/js/stubs/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ window.OC = {

Share: {
SHARE_TYPE_USER: 42,
SHARE_TYPE_GROUP: 1337
SHARE_TYPE_GROUP: 1337,
SHARE_TYPE_CIRCLE: 4932
},

linkToRemote: function (url) {
Expand Down