Skip to content

Commit 4a5519a

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 4a5519a

File tree

3 files changed

+67
-12
lines changed

3 files changed

+67
-12
lines changed

src/linagora.esn.contact/app/addressbook/settings/main/contact-addressbook-settings-main.controller.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,16 @@ function contactAddressbookSettingsMainController(
6262
}
6363

6464
function _initShareAccess() {
65-
self.shareAccess = _.find(
66-
CONTACT_SHARING_SHARE_ACCESS_CHOICES, {
67-
value: self.addressbook.shareAccess
68-
}
69-
);
65+
const access = Object.values(CONTACT_SHARING_SHARE_ACCESS_CHOICES)
66+
.find(({ value }) => value === self.addressbook.shareAccess);
67+
68+
const { public: publicRights } = self.addressbook.source.rights;
69+
70+
if (publicRights === '{DAV:}write') {
71+
self.shareAccess = CONTACT_SHARING_SHARE_ACCESS_CHOICES.READWRITE;
72+
} else {
73+
self.shareAccess = access;
74+
}
7075
}
7176

7277
function _getShareOwner(sharees) {

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

+20-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ function ContactSidebarController(
1212
userUtils,
1313
contactAddressbookDisplayService,
1414
contactAddressbookService,
15-
CONTACT_ADDRESSBOOK_EVENTS
15+
CONTACT_ADDRESSBOOK_EVENTS,
16+
CONTACT_SHARING_SUBSCRIPTION_TYPE
1617
) {
1718
var self = this;
1819
var LOADING_STATUS = {
@@ -150,7 +151,24 @@ function ContactSidebarController(
150151
var categories = contactAddressbookDisplayService.categorizeDisplayShells(self.displayShells);
151152

152153
self.userAddressbooks = categories.userAddressbooks;
153-
self.sharedAddressbooks = categories.sharedAddressbooks;
154+
self.sharedAddressbooks = _getUniqueSharedAddressbooks(categories.sharedAddressbooks);
154155
self.virtualAddressbooks = categories.virtualAddressbooks;
155156
}
157+
158+
function _getUniqueSharedAddressbooks(addressbooks) {
159+
if (!addressbooks) return;
160+
161+
const uniqueAddressbookList = addressbooks.reduce((acc, current) => {
162+
const { source: { href }, subscriptionType } = current.shell;
163+
const { delegation } = CONTACT_SHARING_SUBSCRIPTION_TYPE;
164+
165+
if (!acc[href] || subscriptionType === delegation) {
166+
acc[href] = current;
167+
}
168+
169+
return acc;
170+
}, {});
171+
172+
return Object.values(uniqueAddressbookList);
173+
}
156174
}

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)