Exclude already shared groups from the sharees search

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2017-10-27 20:37:29 +02:00
parent a5d0150cef
commit 6eab3ecbd8
No known key found for this signature in database
GPG Key ID: FB5ACEED51955BF8
1 changed files with 18 additions and 7 deletions

View File

@ -84,17 +84,18 @@ angular.module('contactsApp')
itemType: 'principals'
}
).then(function(result) {
// Todo - filter out current user, existing sharees
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 userShares = ctrl.addressBook.sharedWith.users;
var userSharesLength = userShares.length;
var groupsShares = ctrl.addressBook.sharedWith.groups;
var groupsSharesLength = groupsShares.length;
var i, j;
// Filter out current user
var usersLength = users.length;
for (i = 0 ; i < usersLength; i++) {
for (i = 0 ; i < users.length; i++) {
if (users[i].value.shareWith === OC.currentUser) {
users.splice(i, 1);
break;
@ -103,16 +104,26 @@ angular.module('contactsApp')
// Now filter out all sharees that are already shared with
for (i = 0; i < userSharesLength; i++) {
var share = userShares[i];
usersLength = users.length;
for (j = 0; j < usersLength; j++) {
if (users[j].value.shareWith === share.id) {
var shareUser = userShares[i];
for (j = 0; j < users.length; j++) {
if (users[j].value.shareWith === shareUser.id) {
users.splice(j, 1);
break;
}
}
}
// Now filter out all groups that are already shared with
for (i = 0; i < groupsSharesLength; i++) {
var sharedGroup = groupsShares[i];
for (j = 0; j < groups.length; j++) {
if (groups[j].value.shareWith === sharedGroup.id) {
groups.splice(j, 1);
break;
}
}
}
// Combine users and groups
users = users.map(function(item) {
return {