in gatekeeper.py [0:0]
def offboard_post(session_id):
log.info("publish: %s" % session_id)
lost_asset = False
admin_api_actions = []
gmail_api_actions = []
gcal_api_actions = []
pagerduty_actions = []
duo_actions = []
user_id = request.form.get("USER_ID")
for (k, v) in request.form.items():
if k in GOOGLE_ADMIN_ACTIONS:
admin_api_actions.append(k.lower())
elif k in GOOGLE_GMAIL_ACTIONS:
gmail_api_actions.append(k.lower())
elif k in GOOGLE_CALENDAR_ACTIONS:
gcal_api_actions.append(k.lower())
elif k in PAGERDUTY_ACTIONS:
pagerduty_actions.append(k.lower())
elif k in DUO_ACTIONS:
duo_actions.append(k.lower())
elif k == "LOST_ASSET":
lost_asset = True
def run(runner, connector, action, kwargs):
if session_id not in subscriptions:
subscriptions[session_id] = Queue()
log.info("adding new queue to map: %s" % subscriptions)
sub = subscriptions[session_id]
params = {"runner": runner, "connector": connector, "action": action, "params": kwargs}
sub.put(params)
log.info("adding to queue: %s" % params)
# TODO(): move this logic on the runner.
def change_events_ownership(runner, grantee_user_id):
if session_id not in subscriptions:
subscriptions[session_id] = Queue()
log.info("adding new queue to map: %s" % subscriptions)
sub = subscriptions[session_id]
runner_grantee = Runner(user=grantee_user_id)
if runner_grantee.is_suspended_user:
runner_grantee.suspend_user(False)
moved_events = {}
calendar_id = runner.calendar_api.get_calendar_id()
grantee_calendar_id = runner_grantee.calendar_api.get_calendar_id()
if calendar_id is not None and grantee_calendar_id is not None:
runner.calendar_api.move_calendar_ownership(grantee_calendar_id)
runner_grantee.calendar_api.move_calendar_ownership(calendar_id)
events = runner.calendar_api.list_events(calendar_id)
if events:
for event in events:
result = runner.calendar_api.move_event(event, grantee_calendar_id)
if result is True:
value = "<span class='text-success'>%s</span>" % result
elif v is False:
value = "<span class='text-danger'>%s</span>" % result
else:
value = result
moved_events[event] = value
sub.put({"change_events_ownership": moved_events})
log.info("adding to queue: %s" % moved_events)
runner = Runner(user=user_id)
if lost_asset:
runner.suspend_user(True)
runner.suspend_user(False)
log.info("lost_asset - resetting sign-in cookies")
gevent.spawn(run, runner, "admin_api", "lost_asset", {})
for action in admin_api_actions:
gevent.spawn(run, runner, "admin_api", action, {})
log.info("spawned action: %s" % action)
for action in gmail_api_actions:
if action == "set_ooo_msg":
ooo_msg_text = request.form.get("OOO_MSG_TEXT")
params = {"text": ooo_msg_text}
gevent.spawn(run, runner, "gmail_api", action, params)
else:
gevent.spawn(run, runner, "gmail_api", action, {})
log.info("spawned action: %s" % action)
for action in gcal_api_actions:
if action == "change_events_ownership":
grantee_user_id = request.form.get("GCAL_NEW_OWNER")
if grantee_user_id:
grantee_user_id_is_valid = ldap_client.is_valid_user(grantee_user_id)
if grantee_user_id_is_valid:
gevent.spawn(change_events_ownership(runner, grantee_user_id))
else:
gevent.spawn(run, runner, "calendar_api", action, {})
log.info("spawned action: %s" % action)
for action in pagerduty_actions:
gevent.spawn(run, runner, "pagerduty_api", action, {})
log.info("spawned action: %s" % action)
for action in duo_actions:
gevent.spawn(run, runner, "duo_api", action, {})
log.info("spawned action: %s" % action)
return "OK"