Skip to content

Commit

Permalink
(KC-718) compliance-report improvements: 1) added --deleted-items
Browse files Browse the repository at this point in the history
… and `--active-items` filter flags 2) added "in_trash" report column
  • Loading branch information
aaunario-keeper committed Dec 22, 2023
1 parent b85a429 commit 8be483c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions keepercommander/commands/compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from keepercommander.commands.enterprise_common import EnterpriseCommand
from keepercommander.sox.sox_types import RecordPermissions
from .. import sox, api
from ..error import Error
from ..error import Error, CommandError
from ..params import KeeperParams
from ..sox import sox_types, get_node_id
from ..sox.sox_data import SoxData
Expand Down Expand Up @@ -41,7 +41,12 @@
default_report_parser.add_argument('--url', action='append',
help='URL of record(s) to include in report (set once per URL)')
default_report_parser.add_argument('--shared', action='store_true',
help='flag for excluding non-shared records from report')
help='show shared records only')
deleted_status_group = default_report_parser.add_mutually_exclusive_group()
deleted_status_group.add_argument('--deleted-items', action='store_true',
help='show deleted records only (not valid with --active-items flag)')
deleted_status_group.add_argument('--active-items', action='store_true',
help='show active records only (not valid with --deleted-items flag)')

team_report_desc = 'Run a report showing which shared folders enterprise teams have access to'
team_report_parser = argparse.ArgumentParser(prog='compliance team-report', description=team_report_desc,
Expand Down Expand Up @@ -144,7 +149,7 @@ def execute(self, params, **kwargs): # type: (KeeperParams, any) -> any

class ComplianceReportCommand(BaseComplianceReportCommand):
def __init__(self):
headers = ['record_uid', 'title', 'type', 'username', 'permissions', 'url']
headers = ['record_uid', 'title', 'type', 'username', 'permissions', 'url', 'in_trash']
super(ComplianceReportCommand, self).__init__(headers, allow_no_opts=False)

def get_parser(self): # type: () -> Optional[argparse.ArgumentParser]
Expand Down Expand Up @@ -223,6 +228,14 @@ def title_match(title):

filtered = [r for r in filtered if r.record_uid in r_refs or title_match(r.data.get('title'))] if r_refs \
else filtered
deleted_items = kwargs.get('deleted_items')
active_items = kwargs.get('active_items')
if active_items and deleted_items:
error_msg = '--deleted-items and --active-items flags are mutually exclusive'
raise CommandError(self.get_parser().prog, error_msg)
filtered = [r for r in filtered if r.in_trash] if deleted_items \
else [r for r in filtered if not r.in_trash] if active_items \
else filtered
return filtered

owners = filter_owners(sox_data.get_users().values())
Expand Down Expand Up @@ -274,7 +287,7 @@ def format_table(rows):
formatted_rec_uid = rec_uid if report_fmt != 'table' or last_rec_uid != rec_uid else ''
u_email = row.get('email')
permissions = RecordPermissions.to_permissions_str(row.get('permissions'))
fmt_row = [formatted_rec_uid, r_title, r_type, u_email, permissions, r_url.rstrip('/')]
fmt_row = [formatted_rec_uid, r_title, r_type, u_email, permissions, r_url.rstrip('/'), rec.in_trash]
formatted_rows.append(fmt_row)
last_rec_uid = rec_uid
return formatted_rows
Expand Down

0 comments on commit 8be483c

Please sign in to comment.