def store_iyo_info_in_userdata(username, user_detail): logging.info('Getting the user\'s info from IYO') iyo_user = get_user(username) api_key = get_rogerthat_api_key() user_data_keys = ['name', 'email', 'phone', 'address'] current_user_data = system.get_user_data(api_key, user_detail.email, user_detail.app_id, user_data_keys) user_data = dict() if not current_user_data.get('name') and iyo_user.firstname and iyo_user.lastname: user_data['name'] = '%s %s' % (iyo_user.firstname, iyo_user.lastname) if not current_user_data.get('email') and iyo_user.validatedemailaddresses: user_data['email'] = iyo_user.validatedemailaddresses[0].emailaddress if not current_user_data.get('phone') and iyo_user.validatedphonenumbers: user_data['phone'] = iyo_user.validatedphonenumbers[0].phonenumber if not current_user_data.get('address') and iyo_user.addresses: user_data['address'] = '%s %s' % (iyo_user.addresses[0].street, iyo_user.addresses[0].nr) user_data['address'] += '\n%s %s' % (iyo_user.addresses[0].postalcode, iyo_user.addresses[0].city) user_data['address'] += '\n%s' % iyo_user.addresses[0].country if iyo_user.addresses[0].other: user_data['address'] += '\n\n%s' % iyo_user.addresses[0].other if user_data: system.put_user_data(api_key, user_detail.email, user_detail.app_id, user_data)
def store_invitation_code_in_userdata(username, user_detail): def trans(): profile_key = TffProfile.create_key(username) profile = profile_key.get() if not profile: profile = TffProfile(key=profile_key, app_user=create_app_user_by_email(user_detail.email, user_detail.app_id)) pp_key = ProfilePointer.create_key(username) pp = pp_key.get() if pp: logging.error("Failed to save invitation code of user '%s', we have a duplicate", user_detail.email) deferred.defer(store_invitation_code_in_userdata, username, user_detail, _countdown=10 * 60, _transactional=True) return False profile.put() pp = ProfilePointer(key=pp_key, username=username) pp.put() return True if not ndb.transaction(trans, xg=True): return user_data = { 'invitation_code': user_code(username) } api_key = get_rogerthat_api_key() system.put_user_data(api_key, user_detail.email, user_detail.app_id, user_data)
def store_chat_id_in_user_data(rogerthat_chat_id, user_detail): user_data = { 'support_chat_id': rogerthat_chat_id } api_key = get_rogerthat_api_key() system.put_user_data(api_key, user_detail.email, user_detail.app_id, user_data)
def store_referral_in_user_data(profile_key): profile = profile_key.get() user_data = { 'has_referrer': profile.referrer_user is not None } email, app_id = get_app_user_tuple(profile.app_user) api_key = get_rogerthat_api_key() system.put_user_data(api_key, email.email(), app_id, user_data)
def set_hoster_status_in_user_data(app_user, can_order=None): # type: (users.User, bool) -> None if not isinstance(can_order, bool): can_order = all(o.status == NodeOrderStatus.CANCELED for o in NodeOrder.list_by_user(app_user)) user_data = {'hoster': {'can_order': can_order}} api_key = get_rogerthat_api_key() email, app_id = get_app_user_tuple(app_user) current_user_data = system.get_user_data(api_key, email.email(), app_id, ['hoster']) if current_user_data != user_data: system.put_user_data(api_key, email.email(), app_id, user_data)
def _remove_list(email, app_id, list_id): user_data_keys = ['todo_lists'] api_key = get_rogerthat_api_key() current_user_data = system.get_user_data(api_key, email, app_id, user_data_keys) todo_lists = current_user_data.get('todo_lists') or [] if list_id in todo_lists: todo_lists.remove(list_id) user_data = {'todo_lists': todo_lists} system.put_user_data(api_key, email, app_id, user_data) system.del_user_data(api_key, email, app_id, ['todo_%s' % list_id])
def _update_list(email, app_id, list_id, progress): user_data_keys = ['todo_lists'] api_key = get_rogerthat_api_key() current_user_data = system.get_user_data(api_key, email, app_id, user_data_keys) user_data = {} if not current_user_data.get('todo_lists'): user_data['todo_lists'] = [list_id] elif list_id not in current_user_data.get('todo_lists'): user_data['todo_lists'] = current_user_data.get('todo_lists') + [ list_id ] user_data['todo_%s' % list_id] = progress system.put_user_data(api_key, email, app_id, user_data)
def _update_user_data(sik, service_identity, email, app_id, address, notifications, collections): settings = RogerthatSettings.create_key(sik).get() user_data = dict() user_data["trash"] = {} user_data["trash"]["address"] = address activities = {} for collection in collections: activities[collection.activity.number] = collection.activity user_data["trash"]["collections"] = serialize_complex_value(collections, CollectionTO, True) user_data["trash"]["notifications"] = notifications user_data["trash"]["notification_types"] = serialize_complex_value(sorted(activities.values(), key=lambda a: a.name), ActivityTO, True) try: system.put_user_data(settings.api_key, email, app_id, user_data, service_identity) except RogerthatApiException, e: if e.code != ROGERTHAT_EXCEPTION_CODE_SERVICE_USER_NOT_FOUND: raise e logging.debug("Ignoring _update_user_data user de-friended")
def store_kyc_in_user_data(app_user): username = get_iyo_username(app_user) profile = get_tff_profile(username) user_data = { 'kyc': { 'status': profile.kyc.status, 'verified': profile.kyc.status == KYCStatus.VERIFIED } } email, app_id = get_app_user_tuple(app_user) api_key = get_rogerthat_api_key() return system.put_user_data(api_key, email.email(), app_id, user_data)
def _put_node_status_user_data(tff_profile_key): tff_profile = tff_profile_key.get() user, app_id = get_app_user_tuple(tff_profile.app_user) data = {'nodes': [n.to_dict() for n in tff_profile.nodes]} system.put_user_data(get_rogerthat_api_key(), user.email(), app_id, data)
def put_user_data(app_user, updated_user_data): api_key = get_rogerthat_api_key() email, app_id = get_app_user_tuple(app_user) system.put_user_data(api_key, email.email(), app_id, updated_user_data)