(self, params, **kwargs)
| 2595 | return trash_unshare_parser |
| 2596 | |
| 2597 | def execute(self, params, **kwargs): |
| 2598 | orphaned_records = self.get_orphaned_records(params) |
| 2599 | if len(orphaned_records) == 0: |
| 2600 | logging.info('Trash is empty') |
| 2601 | return |
| 2602 | |
| 2603 | records = kwargs.get('records') |
| 2604 | if not isinstance(records, (tuple, list)): |
| 2605 | records = None |
| 2606 | if not records: |
| 2607 | logging.info('records parameter is empty.') |
| 2608 | return |
| 2609 | |
| 2610 | to_restore = set() |
| 2611 | for rec in records: |
| 2612 | if rec in orphaned_records: |
| 2613 | to_restore.add(rec) |
| 2614 | else: |
| 2615 | title_pattern = re.compile(fnmatch.translate(rec), re.IGNORECASE) |
| 2616 | for record_uid, del_rec in orphaned_records.items(): |
| 2617 | if record_uid in to_restore: |
| 2618 | continue |
| 2619 | record = vault.KeeperRecord.load(params, del_rec) |
| 2620 | if title_pattern.match(record.title): |
| 2621 | to_restore.add(record_uid) |
| 2622 | |
| 2623 | if len(to_restore) == 0: |
| 2624 | logging.info('There are no records to unshare') |
| 2625 | return |
| 2626 | |
| 2627 | if not kwargs.get('force'): |
| 2628 | answer = base.user_choice(f'Do you want to remove shares from {len(to_restore)} record(s)?', 'yn', default='n') |
| 2629 | if answer.lower() == 'y': |
| 2630 | answer = 'yes' |
| 2631 | if answer.lower() != 'yes': |
| 2632 | return |
| 2633 | |
| 2634 | record_shares = api.get_record_shares(params, to_restore, True) |
| 2635 | if record_shares: |
| 2636 | remove_shares = [] # type: List[record_pb2.SharedRecord] |
| 2637 | for record_share in record_shares: |
| 2638 | if 'shares' in record_share: |
| 2639 | shares = record_share['shares'] |
| 2640 | if 'user_permissions' in shares: |
| 2641 | for user_permission in shares['user_permissions']: |
| 2642 | if user_permission.get('owner') is False: |
| 2643 | rs_rq = record_pb2.SharedRecord() |
| 2644 | rs_rq.toUsername = user_permission['username'] |
| 2645 | rs_rq.recordUid = utils.base64_url_decode(record_share['record_uid']) |
| 2646 | remove_shares.append(rs_rq) |
| 2647 | |
| 2648 | while len(remove_shares) > 0: |
| 2649 | chunk = remove_shares[:900] |
| 2650 | remove_shares = remove_shares[900:] |
| 2651 | rsu_rq = record_pb2.RecordShareUpdateRequest() |
| 2652 | rsu_rq.removeSharedRecord.extend(chunk) |
| 2653 | |
| 2654 | rsu_rs = api.communicate_rest(params, rsu_rq, 'vault/records_share_update', |
nothing calls this directly
no test coverage detected