Skip to content

Commit aa9f0ec

Browse files
committed
issue linagora#180 fixed duplicate addressbooks showing up when an adressbook is publicly shared and delegated to a user
1 parent 93672f3 commit aa9f0ec

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

src/linagora.esn.contact/app/sidebar/sidebar.controller.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,23 @@ function ContactSidebarController(
150150
var categories = contactAddressbookDisplayService.categorizeDisplayShells(self.displayShells);
151151

152152
self.userAddressbooks = categories.userAddressbooks;
153-
self.sharedAddressbooks = categories.sharedAddressbooks;
153+
self.sharedAddressbooks = _getUniqueSharedAddressbooks(categories.sharedAddressbooks);
154154
self.virtualAddressbooks = categories.virtualAddressbooks;
155155
}
156+
157+
function _getUniqueSharedAddressbooks(addressbooks) {
158+
if (!addressbooks) return;
159+
160+
const uniqueAddressbookList = addressbooks.reduce((acc, current) => {
161+
const href = current.shell.source.href;
162+
163+
if (!acc[href]) {
164+
acc[href] = current;
165+
}
166+
167+
return acc;
168+
}, {});
169+
170+
return Object.values(uniqueAddressbookList);
171+
}
156172
}

src/linagora.esn.contact/app/sidebar/sidebar.controller.spec.js

+37-5
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,11 @@ describe('The ContactSidebarController controller', function() {
4646
userAPI = _userAPI_;
4747
userUtils = _userUtils_;
4848
CONTACT_ADDRESSBOOK_EVENTS = _CONTACT_ADDRESSBOOK_EVENTS_;
49-
50-
contactAddressbookDisplayService.categorizeDisplayShells = function() {
51-
return {
49+
contactAddressbookDisplayService.categorizeDisplayShells = sinon.stub()
50+
.returns({
5251
userAddressbooks: [],
5352
externalAddressbooks: []
54-
};
55-
};
53+
});
5654
});
5755
});
5856

@@ -260,6 +258,40 @@ describe('The ContactSidebarController controller', function() {
260258
]);
261259
});
262260

261+
it('should avoid listing duplicate entries when an adressbook is shared an delegated to the same user', () => {
262+
contactAddressbookService.listAddressbooks = sinon.stub().returns($q.when([]));
263+
contactAddressbookDisplayService.categorizeDisplayShells.returns({
264+
userAddressbooks: [
265+
{
266+
name: 'bookA',
267+
shell: {
268+
source: { bookId: 'user0', href: '0' }
269+
}
270+
}
271+
],
272+
sharedAddressbooks: [
273+
{
274+
name: 'bookB',
275+
shell: {
276+
source: { bookId: 'user1', href: '1' }
277+
}
278+
},
279+
{
280+
name: 'bookC',
281+
shell: {
282+
source: { bookId: 'user1', href: '1' }
283+
}
284+
}
285+
]
286+
});
287+
288+
const controller = initController();
289+
290+
$rootScope.$digest();
291+
292+
expect(controller.sharedAddressbooks.length).to.equal(1);
293+
});
294+
263295
describe('On updated address book event', function() {
264296
it('should update an address book when updated address book event is fired', function() {
265297
var addressbooks = [

0 commit comments

Comments
 (0)