diff --git a/crc/api/approval.py b/crc/api/approval.py index db895176..cb3246e4 100644 --- a/crc/api/approval.py +++ b/crc/api/approval.py @@ -1,3 +1,4 @@ +import json from datetime import datetime from flask import g @@ -33,13 +34,14 @@ def update_approval(approval_id, body): if approval_model is None: raise ApiError('unknown_approval', 'The approval "' + str(approval_id) + '" is not recognized.') - approval: Approval = ApprovalSchema().load(body) if approval_model.approver_uid != g.user.uid: raise ApiError("not_your_approval", "You may not modify this approval. It belongs to another user.") - approval.update_model(approval_model) + approval_model.status = body['status'] + approval_model.message = body['message'] approval_model.date_approved = datetime.now() + session.add(approval_model) session.commit() - result = ApprovalSchema().dump(approval) + result = ApprovalSchema().dump(approval_model) return result diff --git a/crc/models/approval.py b/crc/models/approval.py index 7f819bcb..d2597e5e 100644 --- a/crc/models/approval.py +++ b/crc/models/approval.py @@ -64,6 +64,7 @@ class Approval(object): instance.status = model.status instance.message = model.message instance.date_created = model.date_created + instance.date_approved = model.date_approved instance.version = model.version instance.title = '' instance.related_approvals = [] @@ -110,7 +111,7 @@ class ApprovalSchema(ma.Schema): approver = fields.Nested(LdapSchema, dump_only=True) primary_investigator = fields.Nested(LdapSchema, dump_only=True) - related_approvals = fields.List(fields.Nested('ApprovalSchema', dump_only=True)) + related_approvals = fields.List(fields.Nested('ApprovalSchema', allow_none=True, dump_only=True)) class Meta: model = Approval