Don't overwrite the approval, just allow minor changes.

This commit is contained in:
Dan Funk 2020-06-02 19:36:06 -04:00
parent 2cd6311666
commit 2424b9d78c
2 changed files with 7 additions and 4 deletions

View File

@ -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

View File

@ -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