Skip to content

Commit

Permalink
issue #180 fixed duplicate addressbooks showing up when an adressbook…
Browse files Browse the repository at this point in the history
… is publicly shared and delegated to a user
  • Loading branch information
rezk2ll committed Dec 21, 2021
1 parent 93672f3 commit 448cb03
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/esn.contact.libs/app/addressBook/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ angular.module('esn.contact.libs')
public: 'public'
})

.constant('CONTACT_SHARING_SHARE_PRIVILEGE', '{DAV:}share');
.constant('CONTACT_SHARING_SHARE_PRIVILEGE', '{DAV:}share')
.constant('CONTACT_SHARING_WRITE_PRIVILEGE', '{DAV:}write');
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ function contactAddressbookSettingsMainController(
CONTACT_SHARING_SHARE_ACCESS,
CONTACT_SHARING_SUBSCRIPTION_TYPE,
CONTACT_SHARING_SHARE_ACCESS_CHOICES,
CONTACT_ADDRESSBOOK_MEMBERS_RIGHTS
CONTACT_ADDRESSBOOK_MEMBERS_RIGHTS,
CONTACT_SHARING_WRITE_PRIVILEGE
) {
var self = this;

Expand Down Expand Up @@ -62,11 +63,22 @@ function contactAddressbookSettingsMainController(
}

function _initShareAccess() {
self.shareAccess = _.find(
CONTACT_SHARING_SHARE_ACCESS_CHOICES, {
value: self.addressbook.shareAccess
}
);
const { READWRITE } = CONTACT_SHARING_SHARE_ACCESS_CHOICES;

const access = Object.values(CONTACT_SHARING_SHARE_ACCESS_CHOICES)
.find(({ value }) => value === self.addressbook.shareAccess);

if (!access) return;

if (access.value >= READWRITE.value) {
self.shareAccess = access;

return;
}

self.shareAccess = self.addressbook.source.rights.public === CONTACT_SHARING_WRITE_PRIVILEGE ?
READWRITE :
access;
}

function _getShareOwner(sharees) {
Expand Down
22 changes: 20 additions & 2 deletions src/linagora.esn.contact/app/sidebar/sidebar.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function ContactSidebarController(
userUtils,
contactAddressbookDisplayService,
contactAddressbookService,
CONTACT_ADDRESSBOOK_EVENTS
CONTACT_ADDRESSBOOK_EVENTS,
CONTACT_SHARING_SUBSCRIPTION_TYPE
) {
var self = this;
var LOADING_STATUS = {
Expand Down Expand Up @@ -150,7 +151,24 @@ function ContactSidebarController(
var categories = contactAddressbookDisplayService.categorizeDisplayShells(self.displayShells);

self.userAddressbooks = categories.userAddressbooks;
self.sharedAddressbooks = categories.sharedAddressbooks;
self.sharedAddressbooks = _getUniqueSharedAddressbooks(categories.sharedAddressbooks);
self.virtualAddressbooks = categories.virtualAddressbooks;
}

function _getUniqueSharedAddressbooks(addressbooks) {
if (!addressbooks) return;

const uniqueAddressbookList = addressbooks.reduce((acc, current) => {
const { source: { href }, subscriptionType } = current.shell;
const { delegation } = CONTACT_SHARING_SUBSCRIPTION_TYPE;

if (!acc[href] || subscriptionType === delegation) {
acc[href] = current;
}

return acc;
}, {});

return Object.values(uniqueAddressbookList);
}
}
42 changes: 37 additions & 5 deletions src/linagora.esn.contact/app/sidebar/sidebar.controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ describe('The ContactSidebarController controller', function() {
userAPI = _userAPI_;
userUtils = _userUtils_;
CONTACT_ADDRESSBOOK_EVENTS = _CONTACT_ADDRESSBOOK_EVENTS_;

contactAddressbookDisplayService.categorizeDisplayShells = function() {
return {
contactAddressbookDisplayService.categorizeDisplayShells = sinon.stub()
.returns({
userAddressbooks: [],
externalAddressbooks: []
};
};
});
});
});

Expand Down Expand Up @@ -260,6 +258,40 @@ describe('The ContactSidebarController controller', function() {
]);
});

it('should avoid listing duplicate entries when an adressbook is shared an delegated to the same user', () => {
contactAddressbookService.listAddressbooks = sinon.stub().returns($q.when([]));
contactAddressbookDisplayService.categorizeDisplayShells.returns({
userAddressbooks: [
{
name: 'bookA',
shell: {
source: { bookId: 'user0', href: '0' }
}
}
],
sharedAddressbooks: [
{
name: 'bookB',
shell: {
source: { bookId: 'user1', href: '1' }
}
},
{
name: 'bookC',
shell: {
source: { bookId: 'user1', href: '1' }
}
}
]
});

const controller = initController();

$rootScope.$digest();

expect(controller.sharedAddressbooks.length).to.equal(1);
});

describe('On updated address book event', function() {
it('should update an address book when updated address book event is fired', function() {
var addressbooks = [
Expand Down

0 comments on commit 448cb03

Please sign in to comment.