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)
| 986 | |
| 987 | |
| 988 | def get_pb2_record_update(params, rec, **kwargs): |
| 989 | # type: (KeeperParams, Record, ...) -> Optional[dict] |
| 990 | """Get an instance Protobuf RecordUpdate from an instance of Record (rec) |
| 991 | |
| 992 | Return a dictionary of necessary record items including the Protobuf RecordUpdate instance |
| 993 | """ |
| 994 | rec_data = prepare_record_v3(params, rec) |
| 995 | if rec_data is None: |
| 996 | return |
| 997 | record_rq, audit = rec_data |
| 998 | |
| 999 | links_by_uid = kwargs.get('record_links_by_uid') |
| 1000 | if links_by_uid: |
| 1001 | links_add_by_uid = links_by_uid.get('record_links_add') or {} |
| 1002 | links_add = links_add_by_uid.get(rec.record_uid) or [] |
| 1003 | links_del_by_uid = links_by_uid.get('record_links_remove') or {} |
| 1004 | links_remove = links_del_by_uid.get(rec.record_uid) or [] |
| 1005 | else: |
| 1006 | links = kwargs.get('record_links') or {} |
| 1007 | links_add = links.get('record_links_add') or [] |
| 1008 | links_remove = links.get('record_links_remove') or [] |
| 1009 | |
| 1010 | record_links_add = [] |
| 1011 | for link in links_add: |
| 1012 | rl = record_pb2.RecordLink() |
| 1013 | rl.record_uid = link.get('record_uid') |
| 1014 | rl.record_key = link.get('record_key') |
| 1015 | if rl.record_uid and rl.record_key: |
| 1016 | record_links_add.append(rl) |
| 1017 | |
| 1018 | record_links_remove = [x['record_uid'] or b'' for x in links_remove] |
| 1019 | |
| 1020 | ru = record_pb2.RecordUpdate() |
| 1021 | uid = loginv3.CommonHelperMethods.url_safe_str_to_bytes(record_rq['record_uid']) |
| 1022 | data = loginv3.CommonHelperMethods.url_safe_str_to_bytes(record_rq['data']) |
| 1023 | ru.record_uid = uid |
| 1024 | ru.client_modified_time = record_rq['client_modified_time'] |
| 1025 | ru.revision = record_rq['revision'] |
| 1026 | ru.data = data |
| 1027 | #ru.non_shared_data = b'' |
| 1028 | if record_links_add: |
| 1029 | ru.record_links_add.extend(record_links_add) |
| 1030 | if record_links_remove: |
| 1031 | ru.record_links_remove.extend(record_links_remove) |
| 1032 | if audit: |
| 1033 | ru.audit.data = audit |
| 1034 | ru = attach_security_data(params, rec.record_uid, ru) |
| 1035 | |
| 1036 | record_rq['pb2_record_update'] = ru |
| 1037 | return record_rq |
| 1038 | |
| 1039 | |
| 1040 | def get_record_v3_response(params, rq, endpoint, record_rq_by_uid, silent=True): |
no test coverage detected