Get an instance Protobuf RecordUpdate from an instance of Record (rec) Return a dictionary of necessary record items including the Protobuf RecordUpdate instance
(params, rec, **kwargs)
| 961 | |
| 962 | |
| 963 | def get_pb2_record_update(params, rec, **kwargs): |
| 964 | # type: (KeeperParams, Record, ...) -> Optional[dict] |
| 965 | """Get an instance Protobuf RecordUpdate from an instance of Record (rec) |
| 966 | |
| 967 | Return a dictionary of necessary record items including the Protobuf RecordUpdate instance |
| 968 | """ |
| 969 | rec_data = prepare_record_v3(params, rec) |
| 970 | if rec_data is None: |
| 971 | return |
| 972 | record_rq, audit = rec_data |
| 973 | |
| 974 | links_by_uid = kwargs.get('record_links_by_uid') |
| 975 | if links_by_uid: |
| 976 | links_add_by_uid = links_by_uid.get('record_links_add') or {} |
| 977 | links_add = links_add_by_uid.get(rec.record_uid) or [] |
| 978 | links_del_by_uid = links_by_uid.get('record_links_remove') or {} |
| 979 | links_remove = links_del_by_uid.get(rec.record_uid) or [] |
| 980 | else: |
| 981 | links = kwargs.get('record_links') or {} |
| 982 | links_add = links.get('record_links_add') or [] |
| 983 | links_remove = links.get('record_links_remove') or [] |
| 984 | |
| 985 | record_links_add = [] |
| 986 | for link in links_add: |
| 987 | rl = record_pb2.RecordLink() |
| 988 | rl.record_uid = link.get('record_uid') |
| 989 | rl.record_key = link.get('record_key') |
| 990 | if rl.record_uid and rl.record_key: |
| 991 | record_links_add.append(rl) |
| 992 | |
| 993 | record_links_remove = [x['record_uid'] or b'' for x in links_remove] |
| 994 | |
| 995 | ru = record_pb2.RecordUpdate() |
| 996 | uid = loginv3.CommonHelperMethods.url_safe_str_to_bytes(record_rq['record_uid']) |
| 997 | data = loginv3.CommonHelperMethods.url_safe_str_to_bytes(record_rq['data']) |
| 998 | ru.record_uid = uid |
| 999 | ru.client_modified_time = record_rq['client_modified_time'] |
| 1000 | ru.revision = record_rq['revision'] |
| 1001 | ru.data = data |
| 1002 | #ru.non_shared_data = b'' |
| 1003 | if record_links_add: |
| 1004 | ru.record_links_add.extend(record_links_add) |
| 1005 | if record_links_remove: |
| 1006 | ru.record_links_remove.extend(record_links_remove) |
| 1007 | if audit: |
| 1008 | ru.audit.data = audit |
| 1009 | ru = attach_security_data(params, rec.record_uid, ru) |
| 1010 | |
| 1011 | record_rq['pb2_record_update'] = ru |
| 1012 | return record_rq |
| 1013 | |
| 1014 | |
| 1015 | def get_record_v3_response(params, rq, endpoint, record_rq_by_uid, silent=True): |
no test coverage detected