@@ -35,7 +35,7 @@ def on_domain_selected(ack, body, client, logger):
3535 domain_id = get_selected_action (body )
3636 domain_name = get_selected_action_text (body )
3737
38- envs = SwitcherService ().get_environments (team_id , domain_id )
38+ envs = SwitcherService ().get_environments (team_id , domain_id or "" ) or []
3939
4040 # Clear previous selection
4141 populate_selection (body ["view" ], "Group" , NEW_SELECTION )
@@ -82,7 +82,7 @@ def on_environment_selected(ack, body, client, logger):
8282 team_id = body ["team" ]["id" ]
8383 domain_id = read_request_metadata (body ["view" ])["domain_id" ]
8484
85- groups = SwitcherService ().get_groups (team_id , domain_id , env_selected )
85+ groups = SwitcherService ().get_groups (team_id , domain_id , env_selected or "" ) or []
8686
8787 # Clear previous selection
8888 populate_selection (body ["view" ], "Group" , NEW_SELECTION )
@@ -120,15 +120,15 @@ def on_group_selected(ack, body, client, logger):
120120
121121 try :
122122 # Collect args
123- env_selected = get_state_value (body ["view" ], "selection_environment" )
123+ env_selected = get_state_value (body ["view" ], "selection_environment" ) or ""
124124 group_selected = get_selected_action (body )
125125 group_status = get_selected_action_status (body )
126126 team_id = body ["team" ]["id" ]
127127 domain_id = read_request_metadata (body ["view" ])["domain_id" ]
128128
129129 switchers = SwitcherService ().get_switchers (
130- team_id , domain_id , env_selected , group_selected
131- )
130+ team_id , domain_id , env_selected , group_selected or ""
131+ ) or []
132132
133133 # Clear previous selection
134134 populate_selection (body ["view" ], "Switcher" , NEW_SELECTION )
@@ -191,11 +191,11 @@ def on_change_request_review(ack, body, client, view, logger):
191191 """ Populate context with selections, validate via Switcher API then publish view for review """
192192
193193 ack ()
194+ user = body ["user" ]
195+ team_id = body ["team" ]["id" ]
194196
195197 try :
196198 # Collect args
197- user = body ["user" ]
198- team_id = body ["team" ]["id" ]
199199 environment = get_state_value (view , "selection_environment" )
200200
201201 # Create context and validate
@@ -249,7 +249,9 @@ def on_submit(ack, body, client, logger):
249249 """ Create ticket, return to home view then publish approval message """
250250
251251 ack ()
252-
252+ user = body ["user" ]
253+ team_id = body ["team" ]["id" ]
254+
253255 try :
254256 # Collect args
255257 observation = get_state_value (body ["view" ], "selection_observation" )
@@ -259,8 +261,6 @@ def on_submit(ack, body, client, logger):
259261 }
260262
261263 domain_id = context ["domain_id" ]
262- user = body ["user" ]
263- team_id = body ["team" ]["id" ]
264264
265265 # Return to initial state
266266 client .views_publish (
@@ -306,13 +306,11 @@ def on_request_approved(ack, body, client, logger):
306306 """ Approve ticket through Switcher API and update chat message """
307307
308308 ack ()
309+ message_ts = body ["message" ]["ts" ]
310+ team_id = body ["team" ]["id" ]
311+ channel_id = body ["channel" ]["id" ]
309312
310313 try :
311- # Collect args
312- message_ts = body ["message" ]["ts" ]
313- team_id = body ["team" ]["id" ]
314- channel_id = body ["channel" ]["id" ]
315-
316314 ticket_payload = json .loads (body ["actions" ][0 ]["value" ])
317315 domain_id = ticket_payload ["domain_id" ]
318316 ticket_id = ticket_payload ["id" ]
@@ -343,13 +341,11 @@ def on_request_denied(ack, body, client, logger):
343341 """ Deny ticket through Switcher API and update chat message """
344342
345343 ack ()
344+ message_ts = body ["message" ]["ts" ]
345+ team_id = body ["team" ]["id" ]
346+ channel_id = body ["channel" ]["id" ]
346347
347348 try :
348- # Collect args
349- message_ts = body ["message" ]["ts" ]
350- team_id = body ["team" ]["id" ]
351- channel_id = body ["channel" ]["id" ]
352-
353349 ticket_payload = json .loads (body ["actions" ][0 ]["value" ])
354350 domain_id = ticket_payload ["domain_id" ]
355351 ticket_id = ticket_payload ["id" ]
0 commit comments