From 57a7c7fa5401d940eabf9eb3aedcc5ee45dd161e Mon Sep 17 00:00:00 2001 From: Carlos Lopez Date: Fri, 5 Jun 2020 13:39:52 -0600 Subject: [PATCH] Approve/deny fixes --- crc/api/approval.py | 4 ++++ crc/services/approval_service.py | 13 +++++++------ crc/services/mails.py | 4 ---- crc/static/templates/mails/ramp_up_denied.html | 2 +- tests/test_approvals_api.py | 4 ++-- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/crc/api/approval.py b/crc/api/approval.py index 9c42c82e..5c403eec 100644 --- a/crc/api/approval.py +++ b/crc/api/approval.py @@ -111,5 +111,9 @@ def update_approval(approval_id, body): session.add(approval_model) session.commit() + # Called only to send emails + approver = body['approver']['uid'] + ApprovalService.update_approval(approval_id, approver) + result = ApprovalSchema().dump(approval_model) return result diff --git a/crc/services/approval_service.py b/crc/services/approval_service.py index 04b0db65..86547cb3 100644 --- a/crc/services/approval_service.py +++ b/crc/services/approval_service.py @@ -85,13 +85,14 @@ class ApprovalService(object): @staticmethod - def update_approval(approval_id, approver_uid, status): + def update_approval(approval_id, approver_uid): """Update a specific approval""" db_approval = session.query(ApprovalModel).get(approval_id) + status = db_approval.status if db_approval: - db_approval.status = status - session.add(db_approval) - session.commit() + # db_approval.status = status + # session.add(db_approval) + # session.commit() if status == ApprovalStatus.APPROVED.value: # second_approval = ApprovalModel().query.filter_by( # study_id=db_approval.study_id, workflow_id=db_approval.workflow_id, @@ -99,7 +100,7 @@ class ApprovalService(object): # if second_approval: # send rrp approval request for second approver ldap_service = LdapService() - pi_user_info = ldap_service.user_info(model.study.primary_investigator_id) + pi_user_info = ldap_service.user_info(db_approval.study.primary_investigator_id) approver_info = ldap_service.user_info(approver_uid) # send rrp submission send_ramp_up_approved_email( @@ -109,7 +110,7 @@ class ApprovalService(object): ) elif status == ApprovalStatus.DECLINED.value: ldap_service = LdapService() - pi_user_info = ldap_service.user_info(model.study.primary_investigator_id) + pi_user_info = ldap_service.user_info(db_approval.study.primary_investigator_id) approver_info = ldap_service.user_info(approver_uid) # send rrp submission send_ramp_up_denied_email( diff --git a/crc/services/mails.py b/crc/services/mails.py index d6de3ff6..2a80457c 100644 --- a/crc/services/mails.py +++ b/crc/services/mails.py @@ -11,7 +11,6 @@ def send_ramp_up_submission_email(sender, recipients, approver_1, approver_2=Non msg = Message('Research Ramp-up Plan Submitted', sender=sender, recipients=recipients) - from crc import env, mail template = env.get_template('ramp_up_submission.txt') template_vars = {'approver_1': approver_1, 'approver_2': approver_2} @@ -28,7 +27,6 @@ def send_ramp_up_approval_request_email(sender, recipients, primary_investigator msg = Message('Research Ramp-up Plan Approval Request', sender=sender, recipients=recipients) - from crc import env, mail template = env.get_template('ramp_up_approval_request.txt') template_vars = {'primary_investigator': primary_investigator} @@ -45,7 +43,6 @@ def send_ramp_up_approval_request_first_review_email(sender, recipients, primary msg = Message('Research Ramp-up Plan Approval Request', sender=sender, recipients=recipients) - from crc import env, mail template = env.get_template('ramp_up_approval_request_first_review.txt') template_vars = {'primary_investigator': primary_investigator} @@ -62,7 +59,6 @@ def send_ramp_up_approved_email(sender, recipients, approver_1, approver_2=None) msg = Message('Research Ramp-up Plan Approved', sender=sender, recipients=recipients) - from crc import env, mail template = env.get_template('ramp_up_approved.txt') template_vars = {'approver_1': approver_1, 'approver_2': approver_2} diff --git a/crc/static/templates/mails/ramp_up_denied.html b/crc/static/templates/mails/ramp_up_denied.html index 9c978a80..7a40c1ea 100644 --- a/crc/static/templates/mails/ramp_up_denied.html +++ b/crc/static/templates/mails/ramp_up_denied.html @@ -1 +1 @@ -

Your Research Ramp-up Plan has been denied by {{ approver_1 }}. Please return to the Research Ramp-up Plan application and review the comments from {{ approver_1 }} on the home page. Next, open the application and locate the first step where changes are needed. Continue to complete additional steps saving your work along the way. Review your revised Research Ramp-up Plan and res-submit for approval.

\ No newline at end of file +

Your Research Ramp-up Plan has been denied by {{ approver }}. Please return to the Research Ramp-up Plan application and review the comments from {{ approver }} on the home page. Next, open the application and locate the first step where changes are needed. Continue to complete additional steps saving your work along the way. Review your revised Research Ramp-up Plan and res-submit for approval.

\ No newline at end of file diff --git a/tests/test_approvals_api.py b/tests/test_approvals_api.py index 6d95be39..da1c2076 100644 --- a/tests/test_approvals_api.py +++ b/tests/test_approvals_api.py @@ -106,7 +106,7 @@ class TestApprovals(BaseTest): def test_accept_approval(self): approval = session.query(ApprovalModel).filter_by(approver_uid='dhf8r').first() data = {'id': approval.id, - "approver_uid": "dhf8r", + "approver": {"uid": "dhf8r"}, 'message': "Approved. I like the cut of your jib.", 'status': ApprovalStatus.APPROVED.value} @@ -127,7 +127,7 @@ class TestApprovals(BaseTest): def test_decline_approval(self): approval = session.query(ApprovalModel).filter_by(approver_uid='dhf8r').first() data = {'id': approval.id, - "approver_uid": "dhf8r", + "approver": {"uid": "dhf8r"}, 'message': "Approved. I find the cut of your jib lacking.", 'status': ApprovalStatus.DECLINED.value}