From 25430a8128004a04727e4f667fa0785e98cdeb14 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Fri, 3 Mar 2017 10:35:23 -0500 Subject: [PATCH] Fix handling of contact organizations Fixes #4028 --- NEWS | 1 + SoObjects/Contacts/NGVCard+SOGo.h | 5 +- SoObjects/Contacts/NGVCard+SOGo.m | 67 ++++++++++++++++--- UI/Contacts/UIxContactEditor.m | 34 +++------- UI/Contacts/UIxContactView.m | 59 ++++++---------- .../ContactsUI/UIxContactEditorTemplate.wox | 14 ++-- .../js/Contacts/Card.service.js | 36 +++++----- .../js/Contacts/CardController.js | 8 +-- 8 files changed, 121 insertions(+), 103 deletions(-) diff --git a/NEWS b/NEWS index 49efd029f..a495284a8 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,7 @@ Bug fixes - [web] SOGoCalendarWeekdays must now be defined before saving preferences - [web] fixed CAS session timeout handling during XHR requests (#1456) - [web] exposed default value of SOGoMailAutoSave (#4053) + - [web] fixed handling of contact organizations (#4028) 3.2.7 (2017-02-14) ------------------ diff --git a/SoObjects/Contacts/NGVCard+SOGo.h b/SoObjects/Contacts/NGVCard+SOGo.h index 16a36ec37..12968cf75 100644 --- a/SoObjects/Contacts/NGVCard+SOGo.h +++ b/SoObjects/Contacts/NGVCard+SOGo.h @@ -1,6 +1,6 @@ /* NGVCard+SOGo.h - this file is part of SOGo * - * Copyright (C) 2009-2016 Inverse inc. + * Copyright (C) 2009-2017 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -43,6 +43,9 @@ - (NSArray *) emails; - (NSArray *) secondaryEmails; +- (void) setOrganizations: (NSArray *) newOrganizations; +- (NSArray *) organizations; + - (NSString *) workPhone; - (NSString *) homePhone; - (NSString *) fax; diff --git a/SoObjects/Contacts/NGVCard+SOGo.m b/SoObjects/Contacts/NGVCard+SOGo.m index e5adc3c01..10e8455fb 100644 --- a/SoObjects/Contacts/NGVCard+SOGo.m +++ b/SoObjects/Contacts/NGVCard+SOGo.m @@ -261,9 +261,9 @@ convention: NSInteger year, yearOfToday, month, day; CardElement *element; NSCalendarDate *now; - NSArray *units; - NSString *fn, *ou; - id o; + NSMutableArray *units; + NSString *fn; + id o, ou; [self setNWithFamily: [ldifRecord objectForKey: @"sn"] given: [ldifRecord objectForKey: @"givenname"] @@ -306,13 +306,17 @@ convention: ou = [ldifRecord objectForKey: @"ou"]; if ([ou isKindOfClass: [NSArray class]]) - units = [NSArray arrayWithArray: (NSArray *)ou]; + units = [NSMutableArray arrayWithArray: (NSArray *)ou]; else if (ou) - units = [NSArray arrayWithObject: ou]; + units = [NSMutableArray arrayWithObject: ou]; else - units = nil; - [self setOrg: [ldifRecord objectForKey: @"o"] - units: units]; + units = [NSMutableArray array]; + o = [ldifRecord objectForKey: @"o"]; + if ([o isKindOfClass: [NSArray class]]) + [units addObjectsFromArray: (NSArray *)o]; + else if (ou) + [units addObject: o]; + [self setOrganizations: units]; [self _setPhoneValues: ldifRecord]; [self _setEmails: ldifRecord]; @@ -712,6 +716,53 @@ convention: return company; } +- (void) setOrganizations: (NSArray *) newOrganizations +{ + CardElement *org; + NSArray *elements; + NSUInteger count, max; + + // First remove all current org properties + elements = [self childrenWithTag: @"org"]; + [self removeChildren: elements]; + + org = [self uniqueChildWithTag: @"org"]; + max = [newOrganizations count]; + for (count = 0; count < max; count++) + { + [org setSingleValue: [newOrganizations objectAtIndex: count] + atIndex: count forKey: @""]; + } +} + +- (NSArray *) organizations +{ + CardElement *org; + NSArray *organizations; + NSEnumerator *orgs; + NSMutableArray *flattenedOrganizations; + NSString *value; + NSUInteger count, max; + + // Get all org properties + orgs = [[self childrenWithTag: @"org"] objectEnumerator]; + flattenedOrganizations = [NSMutableArray array]; + while ((org = [orgs nextObject])) + { + // Get all values of each org property + organizations = [org valuesForKey: @""]; + max = [organizations count]; + for (count = 0; count < max; count++) + { + value = [[organizations objectAtIndex: count] lastObject]; + if ([value length]) + [flattenedOrganizations addObject: value]; + } + } + + return flattenedOrganizations; +} + - (NSString *) fullName { CardElement *n; diff --git a/UI/Contacts/UIxContactEditor.m b/UI/Contacts/UIxContactEditor.m index 519cecbf1..52851f87f 100644 --- a/UI/Contacts/UIxContactEditor.m +++ b/UI/Contacts/UIxContactEditor.m @@ -1,6 +1,6 @@ /* Copyright (C) 2004-2005 SKYRIX Software AG - Copyright (C) 2005-2015 Inverse inc. + Copyright (C) 2005-2017 Inverse inc. This file is part of SOGo @@ -339,7 +339,7 @@ static Class SOGoContactGCSEntryK = Nil; { CardElement *element; NSArray *elements, *values; - NSMutableArray *units, *categories; + NSMutableArray *orgs, *categories; NSCalendarDate *date; id o; unsigned int i, year, month, day; @@ -398,27 +398,13 @@ static Class SOGoContactGCSEntryK = Nil; } } - if ([[attributes objectForKey: @"orgUnits"] isKindOfClass: [NSArray class]]) - { - elements = [card childrenWithTag: @"org"]; - [card removeChildren: elements]; - values = [attributes objectForKey: @"orgUnits"]; - units = [NSMutableArray arrayWithCapacity: [values count]]; - for (i = 0; i < [values count]; i++) - { - o = [values objectAtIndex: i]; - if ([o isKindOfClass: [NSDictionary class]]) - { - [units addObject: [o objectForKey: @"value"]]; - } - } - } + if ([[attributes objectForKey: @"orgs"] isKindOfClass: [NSArray class]]) + orgs = [NSMutableArray arrayWithArray: [attributes objectForKey: @"orgs"]]; else - { - units = nil; - } - [card setOrg: [attributes objectForKey: @"c_org"] - units: units]; + orgs = [NSMutableArray array]; + if ([[attributes objectForKey: @"org"] length]) + [orgs insertObject: [attributes objectForKey: @"org"] atIndex: 0]; + [card setOrganizations: orgs]; elements = [card childrenWithTag: @"tel"]; [card removeChildren: elements]; @@ -520,7 +506,9 @@ static Class SOGoContactGCSEntryK = Nil; * @apiParam {String} c_cn Fullname * @apiParam {String} c_screenname Screen Name (X-AIM for now) * @apiParam {String} tz Timezone - * @apiParam {String} note Note + * @apiParam {String} org Main organization + * @apiParam {String[]} orgs Additional organizations + * @apiParam {String[]} notes Notes * @apiParam {String[]} allCategories All available categories * @apiParam {Object[]} categories Categories assigned to the card * @apiParam {String} categories.value Category name diff --git a/UI/Contacts/UIxContactView.m b/UI/Contacts/UIxContactView.m index fa8afb59f..b84b99cc2 100644 --- a/UI/Contacts/UIxContactView.m +++ b/UI/Contacts/UIxContactView.m @@ -1,18 +1,18 @@ /* - Copyright (C) 2005-2016 Inverse inc. + Copyright (C) 2005-2017 Inverse inc. This file is part of SOGo. - + SOGo is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + SOGo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with OGo; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA @@ -69,7 +69,7 @@ categoryLabels = [[self labelForKey: @"contacts_category_labels"] componentsSeparatedByString: @","]; if (!categoryLabels) categoryLabels = [NSArray array]; - + return [categoryLabels trimmedComponents]; } @@ -101,33 +101,6 @@ return cats; } -- (NSArray *) orgUnits -{ - NSMutableArray *orgUnits; - NSArray *values; - CardElement *org; - NSString *service; - NSUInteger count, max; - - org = [card org]; - values = [org valuesForKey: @""]; - max = [values count]; - if (max > 1) - { - orgUnits = [NSMutableArray arrayWithCapacity: max]; - for (count = 1; count < max; count++) - { - service = [org flattenedValueAtIndex: count forKey: @""]; - if ([service length] > 0) - [orgUnits addObject: [NSDictionary dictionaryWithObject: service forKey: @"value"]]; - } - } - else - orgUnits = nil; - - return orgUnits; -} - - (NSArray *) categories { NSMutableArray *categories; @@ -267,9 +240,13 @@ * @apiSuccess (Success 200) {String} [nickname] Nickname * @apiSuccess (Success 200) {String} [c_sn] Lastname * @apiSuccess (Success 200) {String} [c_fn] Fullname + * @apiSuccess (Success 200) {String} [title] Title + * @apiSuccess (Success 200) {String} [role] Role * @apiSuccess (Success 200) {String} [c_screenname] Screen Name (X-AIM for now) * @apiSuccess (Success 200) {String} [tz] Timezone - * @apiSuccess (Success 200) {String} [notes] Notes + * @apiSuccess (Success 200) {String} [org] Main organization + * @apiSuccess (Success 200) {String[]} [orgs] Additional organizations + * @apiSuccess (Success 200) {String[]} [notes] Notes * @apiSuccess (Success 200) {String[]} allCategories All available categories * @apiSuccess (Success 200) {Object[]} [categories] Categories assigned to the card * @apiSuccess (Success 200) {String} categories.value Category name @@ -297,6 +274,7 @@ id result; id o; SOGoObject *contact; + NSArray *values; NSMutableDictionary *data; contact = [self clientObject]; @@ -341,12 +319,13 @@ o = [card role]; if ([o length] > 0) [data setObject: o forKey: @"role"]; - o = [self orgUnits]; - if ([o count] > 0) - [data setObject: o forKey: @"orgUnits"]; - o = [card workCompany]; - if ([o length] > 0) - [data setObject: o forKey: @"c_org"]; + values = [card organizations]; + if ([values count]) + { + [data setObject: [values objectAtIndex: 0] forKey: @"org"]; + if ([values count] > 1) + [data setObject: [values subarrayWithRange: NSMakeRange(1, [values count] - 1)] forKey: @"orgs"]; + } o = [card birthday]; if (o) @@ -376,7 +355,7 @@ result = [self responseWithStatus: 200 andString: [data jsonRepresentation]]; - + return result; } diff --git a/UI/Templates/ContactsUI/UIxContactEditorTemplate.wox b/UI/Templates/ContactsUI/UIxContactEditorTemplate.wox index 20a35a0e7..acebfd8d1 100644 --- a/UI/Templates/ContactsUI/UIxContactEditorTemplate.wox +++ b/UI/Templates/ContactsUI/UIxContactEditorTemplate.wox @@ -78,7 +78,7 @@ - + - -
+ +
- + remove_circle - +
- + add_circle