From 06c8982ef60cc222bed9fea9a7ca49bfe9b833f2 Mon Sep 17 00:00:00 2001 From: Robert Latta <robert.latta@geant.org> Date: Thu, 5 Mar 2020 16:21:45 +0000 Subject: [PATCH] updated to build organisation as users from different source --- inventory_provider/db/ims_data.py | 83 ++++++++++++++++++------------- 1 file changed, 48 insertions(+), 35 deletions(-) diff --git a/inventory_provider/db/ims_data.py b/inventory_provider/db/ims_data.py index cc397d07..e6cbdb7e 100644 --- a/inventory_provider/db/ims_data.py +++ b/inventory_provider/db/ims_data.py @@ -141,9 +141,8 @@ def otrs_get_customer_users_rows(ds): # TODO - check the rules for validation once model has been confirmed def _is_valid_customer(cus): - # commented out as no contact details are in IMS - # if not cus['email']: - # return False + if not cus['email']: + return False return True # TODO - check this rule for getting the customer_id2 once model has been confirmed # noqa @@ -158,30 +157,38 @@ def otrs_get_customer_users_rows(ds): ims.CUSTOMER_PROPERTIES['CustomerRelatedContacts'], ims.CUSTOMER_PROPERTIES['CustomerType'] ]): - # Org as User - org_customer = OrderedDict({ - 'type': customer['CustomerType']['Name'] if customer[ - 'CustomerType'] else '', - 'email': customer['AccountEmail'], - 'username': customer['AccountEmail'], - 'customer_id': customer['Name'], - 'customer_id_2': _get_customer_id2(customer), - 'title': '', - 'firstname': customer['Name'], - 'lastname': '-', - 'phone': '', - 'fax': '', - 'mobile': '', - 'street': '', - 'zip': '', - 'city': '', - 'country': '', - 'comments': '' - }) - if _is_valid_customer(org_customer): - del org_customer['type'] - yield org_customer.values() - # end of Org as User + # # Org as User + # org_customer = OrderedDict({ + # 'type': customer['CustomerType']['Name'] if customer[ + # 'CustomerType'] else '', + # 'email': customer['AccountEmail'], + # 'username': customer['AccountEmail'], + # 'customer_id': customer['Name'], + # 'customer_id_2': _get_customer_id2(customer), + # 'title': '', + # 'firstname': customer['Name'], + # 'lastname': '-', + # 'phone': '', + # 'fax': '', + # 'mobile': '', + # 'street': '', + # 'zip': '', + # 'city': '', + # 'country': '', + # 'comments': 'Organisation imported as a user' + # }) + # if _is_valid_customer(org_customer): + # del org_customer['type'] + # + # # todo - remove from here after testing + # # dummy_email = f'dumy_{dummy_counter}@geant.org' + # # org_customer['email'] = dummy_email + # # org_customer['username'] = dummy_email + # # dummy_counter += 1 + # # todo - remove up to here after testing + # + # yield list(org_customer.values()) + # # end of Org as User # Contacts as Users if customer['CustomerRelatedContacts']: @@ -198,7 +205,11 @@ def otrs_get_customer_users_rows(ds): 'customer_id_2': _get_customer_id2(customer), 'title': '', 'firstname': contact['Contact']['Name'], - 'lastname': contact['Contact']['LastName'], + 'lastname': + ' '.join(filter(None, [ + contact['Contact']['InFix'], + contact['Contact']['LastName'] + ])), 'phone': '', 'fax': '', 'mobile': '', @@ -210,13 +221,15 @@ def otrs_get_customer_users_rows(ds): }) if not _is_valid_customer(t_customer_user): continue - customer_user = _choose_customer_user( - t_customer_user, - customer_user - ) - if customer_user: - del customer_user['type'] - yield customer_user.values() + if contact['Contact']['IsGroup']: + t_customer_user['comments'] = \ + 'Organisation imported as a user' + + del t_customer_user['type'] + yield list(t_customer_user.values()) + # if customer_user: + # del customer_user['type'] + # yield list(customer_user.values()) # end of Contact as User -- GitLab