|
1 | 1 | from py42.exceptions import Py42BadRequestError |
2 | 2 |
|
| 3 | +from code42cli.cmds.detectionlists.commands import DetectionListSubcommandLoader |
3 | 4 | from code42cli.bulk import generate_template, run_bulk_process |
4 | 5 | from code42cli.file_readers import create_csv_reader, create_flat_file_reader |
5 | 6 | from code42cli.errors import UserAlreadyAddedError, UserDoesNotExistError, UnknownRiskTagError |
6 | 7 | from code42cli.cmds.detectionlists.enums import DetectionLists, DetectionListUserKeys, RiskTags |
7 | | -from code42cli.cmds.detectionlists.commands import DetectionListCommandFactory |
8 | 8 | from code42cli.cmds.detectionlists.bulk import BulkDetectionList, BulkHighRiskEmployee |
9 | 9 |
|
10 | 10 |
|
@@ -46,13 +46,15 @@ class DetectionList(object): |
46 | 46 | given `classmethods`. |
47 | 47 | handlers (DetectionListHandlers): A DTO containing implementations for adding / removing |
48 | 48 | users from specific lists. |
49 | | - cmd_factory (DetectionListCommandFactory): A factory that creates detection list commands. |
| 49 | + cmd_factory (DetectionListSubcommandLoader): A factory that creates detection list commands. |
50 | 50 | """ |
51 | 51 |
|
52 | | - def __init__(self, list_name, handlers, cmd_factory=None): |
| 52 | + def __init__(self, list_name, handlers, subcommand_loader=None): |
53 | 53 | self.name = list_name |
54 | 54 | self.handlers = handlers |
55 | | - self.factory = cmd_factory or DetectionListCommandFactory(list_name) |
| 55 | + self.subcommand_loader = subcommand_loader or DetectionListSubcommandLoader(list_name) |
| 56 | + self.bulk_subcommand_loader = self.subcommand_loader.bulk_subcommand_loader |
| 57 | + self.bulk_subcommand_loader.load_commands = lambda: self._load_bulk_subcommands |
56 | 58 |
|
57 | 59 | @classmethod |
58 | 60 | def create_high_risk_employee_list(cls, handlers): |
@@ -82,39 +84,41 @@ def create_departing_employee_list(cls, handlers): |
82 | 84 |
|
83 | 85 | def load_subcommands(self): |
84 | 86 | """Loads high risk employee related subcommands""" |
85 | | - bulk = self.factory.create_bulk_command(lambda: self._load_bulk_subcommands()) |
86 | | - add = self.factory.create_add_command( |
| 87 | + bulk = self.subcommand_loader.create_bulk_command() |
| 88 | + bulk.subcommand_loader.load_commands = lambda: self._load_bulk_subcommands() |
| 89 | + add = self.subcommand_loader.create_add_command( |
87 | 90 | self.handlers.add_employee, self.handlers.load_add_description |
88 | 91 | ) |
89 | | - remove = self.factory.create_remove_command( |
| 92 | + remove = self.subcommand_loader.create_remove_command( |
90 | 93 | self.handlers.remove_employee, load_username_description |
91 | 94 | ) |
92 | 95 | return [bulk, add, remove] |
93 | 96 |
|
94 | 97 | def _load_bulk_subcommands(self): |
95 | | - |
96 | | - add = self.factory.create_bulk_add_command(self.bulk_add_employees) |
97 | | - remove = self.factory.create_bulk_remove_command(self.bulk_remove_employees) |
| 98 | + add = self.bulk_subcommand_loader.create_bulk_add_command(self.bulk_add_employees) |
| 99 | + remove = self.bulk_subcommand_loader.create_bulk_remove_command(self.bulk_remove_employees) |
98 | 100 | commands = [add, remove] |
99 | 101 |
|
100 | 102 | if self.name == DetectionLists.HIGH_RISK_EMPLOYEE: |
101 | 103 | commands.extend(self._get_risk_tags_bulk_subcommands()) |
102 | 104 | else: |
103 | | - generate_template_cmd = self.factory.create_bulk_generate_template_command( |
| 105 | + generate_template_cmd = self.bulk_subcommand_loader.create_bulk_generate_template_command( |
104 | 106 | self.generate_template_file |
105 | 107 | ) |
106 | 108 | commands.append(generate_template_cmd) |
107 | 109 | return commands |
108 | 110 |
|
109 | 111 | def _get_risk_tags_bulk_subcommands(self): |
110 | | - bulk_add_risk_tags = self.factory.create_bulk_add_risk_tags_command(self.bulk_add_risk_tags) |
111 | | - bulk_remove_risk_tags = self.factory.create_bulk_remove_risk_tags_command( |
| 112 | + bulk_add_risk_tags = self.bulk_subcommand_loader.create_bulk_add_risk_tags_command( |
| 113 | + self.bulk_add_risk_tags |
| 114 | + ) |
| 115 | + bulk_remove_risk_tags = self.bulk_subcommand_loader.create_bulk_remove_risk_tags_command( |
112 | 116 | self.bulk_remove_risk_tags |
113 | 117 | ) |
114 | 118 |
|
115 | 119 | self.handlers.add_handler(u"add_risk_tags", add_risk_tags) |
116 | 120 | self.handlers.add_handler(u"remove_risk_tags", remove_risk_tags) |
117 | | - generate_template_cmd = self.factory.create_hre_bulk_generate_template_command( |
| 121 | + generate_template_cmd = self.bulk_subcommand_loader.create_hre_bulk_generate_template_command( |
118 | 122 | self.generate_template_file |
119 | 123 | ) |
120 | 124 | return [bulk_add_risk_tags, bulk_remove_risk_tags, generate_template_cmd] |
|
0 commit comments