Share calendar to a circle.

Changes in the interface to allow:

* Calendar to be shared with a circle
* Show calendars (and events) that are shared with current user's circles

This need that the commit f45624f1819833086368d95f0173bd55a3fb8dae is applied in nextcloud core.

Signed-off-by: Vinicius Cubas Brand <viniciuscb@gmail.com>
This commit is contained in:
Vinicius Cubas Brand 2019-02-07 21:30:00 -02:00
parent 91b76a3d52
commit 8b0603803f
7 changed files with 112 additions and 14 deletions

View File

@ -3,8 +3,12 @@
*
* @author Raghu Nayyar
* @author Georg Ehrke
* @author Vinicius Cubas Brand
* @author Daniel Tygel
* @copyright 2016 Raghu Nayyar <hey@raghunayyar.com>
* @copyright 2016 Georg Ehrke <oc.list@georgehrke.com>
* @copyright 2017 Vinicius Cubas Brand <vinicius@eita.org.br>
* @copyright 2017 Daniel Tygel <dtygel@eita.org.br>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@ -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 = '';
@ -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();
@ -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',
@ -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
@ -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),
@ -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);
});
};

View File

@ -2,7 +2,11 @@
* Calendar App
*
* @author Georg Ehrke
* @author Vinicius Cubas Brand
* @author Daniel Tygel
* @copyright 2016 Georg Ehrke <oc.list@georgehrke.com>
* @copyright 2017 Vinicius Cubas Brand <vinicius@eita.org.br>
* @copyright 2017 Daniel Tygel <dtygel@eita.org.br>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@ -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'] || [];
@ -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;
@ -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;
@ -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
});
}
});

View File

@ -2,7 +2,11 @@
* Nextcloud - Calendar App
*
* @author Georg Ehrke
* @author Vinicius Cubas Brand
* @author Daniel Tygel
* @copyright 2016 Georg Ehrke <oc.list@georgehrke.com>
* @copyright 2017 Vinicius Cubas Brand <vinicius@eita.org.br>
* @copyright 2017 Daniel Tygel <dtygel@eita.org.br>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@ -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() {

View File

@ -3,8 +3,12 @@
*
* @author Raghu Nayyar
* @author Georg Ehrke
* @author Vinicius Cubas Brand
* @author Daniel Tygel
* @copyright 2016 Raghu Nayyar <hey@raghunayyar.com>
* @copyright 2016 Georg Ehrke <oc.list@georgehrke.com>
* @copyright 2017 Vinicius Cubas Brand <vinicius@eita.org.br>
* @copyright 2017 Daniel Tygel <dtygel@eita.org.br>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@ -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) {
@ -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;
@ -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
});
}
});
};
@ -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);
}
});
};

View File

@ -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
});
}
]);

View File

@ -4,8 +4,12 @@
*
* @author Raghu Nayyar
* @author Georg Ehrke
* @author Vinicius Cubas Brand
* @author Daniel Tygel
* @copyright 2016 Raghu Nayyar <hey@raghunayyar.com>
* @copyright 2016 Georg Ehrke <oc.list@georgehrke.com>
* @copyright 2017 Vinicius Cubas Brand <vinicius@eita.org.br>
* @copyright 2017 Daniel Tygel <dtygel@eita.org.br>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@ -127,7 +131,7 @@
<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"
@ -188,6 +192,33 @@
</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"

View File

@ -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) {