From 42346cf01ec5beb48e039cc0485e19df6c5306f8 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Thu, 7 Oct 2021 09:22:30 -0400 Subject: [PATCH] New get_email_data script. --- crc/scripts/get_email_data.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 crc/scripts/get_email_data.py diff --git a/crc/scripts/get_email_data.py b/crc/scripts/get_email_data.py new file mode 100644 index 00000000..4e64dcbb --- /dev/null +++ b/crc/scripts/get_email_data.py @@ -0,0 +1,33 @@ +from crc.scripts.script import Script +from crc.api.common import ApiError +from crc import session +from crc.models.email import EmailModel, EmailModelSchema +import json + + +class EmailData(Script): + + def get_description(self): + return """This is my description""" + + def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs): + if 'email_id' in kwargs or 'workflow_id' in kwargs: + return True + else: + return False + + def do_task(self, task, study_id, workflow_id, **kwargs): + email_models = None + if 'email_id' in kwargs: + email_models = session.query(EmailModel).filter(EmailModel.id == kwargs['email_id']).all() + elif 'workflow_id' in kwargs: + email_models = session.query(EmailModel).filter(EmailModel.workflow_id == kwargs['workflow_id']).all() + else: + raise ApiError.from_task(code='missing_email_id', + message='You must include an email_id with the get_email_data script.', + task=task) + + email_data = None + if email_models: + email_data = EmailModelSchema(many=True).dump(email_models) + return email_data