Don't overwrite the approval, just allow minor changes.
This commit is contained in:
parent
2cd6311666
commit
2424b9d78c
|
@ -1,3 +1,4 @@
|
||||||
|
import json
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from flask import g
|
from flask import g
|
||||||
|
@ -33,13 +34,14 @@ def update_approval(approval_id, body):
|
||||||
if approval_model is None:
|
if approval_model is None:
|
||||||
raise ApiError('unknown_approval', 'The approval "' + str(approval_id) + '" is not recognized.')
|
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:
|
if approval_model.approver_uid != g.user.uid:
|
||||||
raise ApiError("not_your_approval", "You may not modify this approval. It belongs to another user.")
|
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()
|
approval_model.date_approved = datetime.now()
|
||||||
|
session.add(approval_model)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
result = ApprovalSchema().dump(approval)
|
result = ApprovalSchema().dump(approval_model)
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -64,6 +64,7 @@ class Approval(object):
|
||||||
instance.status = model.status
|
instance.status = model.status
|
||||||
instance.message = model.message
|
instance.message = model.message
|
||||||
instance.date_created = model.date_created
|
instance.date_created = model.date_created
|
||||||
|
instance.date_approved = model.date_approved
|
||||||
instance.version = model.version
|
instance.version = model.version
|
||||||
instance.title = ''
|
instance.title = ''
|
||||||
instance.related_approvals = []
|
instance.related_approvals = []
|
||||||
|
@ -110,7 +111,7 @@ class ApprovalSchema(ma.Schema):
|
||||||
|
|
||||||
approver = fields.Nested(LdapSchema, dump_only=True)
|
approver = fields.Nested(LdapSchema, dump_only=True)
|
||||||
primary_investigator = 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:
|
class Meta:
|
||||||
model = Approval
|
model = Approval
|
||||||
|
|
Loading…
Reference in New Issue