(self, params, **kwargs)
| 2306 | return trash_get_parser |
| 2307 | |
| 2308 | def execute(self, params, **kwargs): |
| 2309 | deleted_records = self.get_deleted_records(params) |
| 2310 | orphaned_records = self.get_orphaned_records(params) |
| 2311 | if len(deleted_records) == 0 and len(orphaned_records) == 0: |
| 2312 | logging.info('Trash is empty') |
| 2313 | return |
| 2314 | |
| 2315 | record_uid = kwargs.get('record') |
| 2316 | if not record_uid: |
| 2317 | logging.info('Record UID parameter is required') |
| 2318 | return |
| 2319 | |
| 2320 | is_shared = False |
| 2321 | rec = deleted_records.get(record_uid) |
| 2322 | if not rec: |
| 2323 | rec = orphaned_records.get(record_uid) |
| 2324 | is_shared = True |
| 2325 | if not rec: |
| 2326 | logging.info('%s is not a valid deleted record UID', record_uid) |
| 2327 | return |
| 2328 | |
| 2329 | record = vault.KeeperRecord.load(params, rec) |
| 2330 | if not record: |
| 2331 | logging.info('Cannot restore record %s', record_uid) |
| 2332 | return |
| 2333 | |
| 2334 | for name, value in record.enumerate_fields(): |
| 2335 | if value: |
| 2336 | if isinstance(value, list): |
| 2337 | value = '\n'.join(value) |
| 2338 | if len(value) > 100: |
| 2339 | value = value[:99] + '...' |
| 2340 | print('{0:>21s}: {1}'.format(name, value)) |
| 2341 | if is_shared: |
| 2342 | if 'shares' not in rec: |
| 2343 | rec['shares'] = {} |
| 2344 | shares = api.get_record_shares(params, (record_uid,), True) |
| 2345 | if isinstance(shares, list): |
| 2346 | record_shares = next(iter(x.get('shares') for x in shares if x.get('record_uid') == record_uid), None) |
| 2347 | if isinstance(record_shares, dict): |
| 2348 | rec['shares'] = record_shares |
| 2349 | |
| 2350 | if 'shares' in rec: |
| 2351 | if 'user_permissions' in rec['shares']: |
| 2352 | perm = rec['shares']['user_permissions'].copy() |
| 2353 | perm.sort(key=lambda r: (' 1' if r.get('owner') else |
| 2354 | ' 2' if r.get('editable') else |
| 2355 | ' 3' if r.get('shareable') else |
| 2356 | '') + r.get('username')) |
| 2357 | no = 0 |
| 2358 | for uo in perm: |
| 2359 | flags = '' |
| 2360 | if uo.get('owner'): |
| 2361 | continue |
| 2362 | if uo.get('editable'): |
| 2363 | flags = 'Can Edit' |
| 2364 | if uo.get('shareable'): |
| 2365 | if flags: |
nothing calls this directly
no test coverage detected