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 4a5519a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,16 @@ function contactAddressbookSettingsMainController(
}

function _initShareAccess() {
self.shareAccess = _.find(
CONTACT_SHARING_SHARE_ACCESS_CHOICES, {
value: self.addressbook.shareAccess
}
);
const access = Object.values(CONTACT_SHARING_SHARE_ACCESS_CHOICES)
.find(({ value }) => value === self.addressbook.shareAccess);

const { public: publicRights } = self.addressbook.source.rights;

if (publicRights === '{DAV:}write') {
self.shareAccess = CONTACT_SHARING_SHARE_ACCESS_CHOICES.READWRITE;
} else {
self.shareAccess = 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 4a5519a

Please sign in to comment.