Merge pull request #428 from dod-ccpo/auto-approval-logs-#160420024
Auto approval logs #160420024
This commit is contained in:
commit
7c6aa5d238
@ -0,0 +1,32 @@
|
|||||||
|
"""make user_id nullable for request_review
|
||||||
|
|
||||||
|
Revision ID: ea8b5681b37c
|
||||||
|
Revises: e1081cf01780
|
||||||
|
Create Date: 2018-11-05 14:42:42.175939
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = 'ea8b5681b37c'
|
||||||
|
down_revision = 'e1081cf01780'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.alter_column('request_reviews', 'user_id',
|
||||||
|
existing_type=postgresql.UUID(),
|
||||||
|
nullable=True)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.alter_column('request_reviews', 'user_id',
|
||||||
|
existing_type=postgresql.UUID(),
|
||||||
|
nullable=False)
|
||||||
|
# ### end Alembic commands ###
|
@ -7,6 +7,7 @@ from atst.models.request_review import RequestReview
|
|||||||
from atst.models.request_internal_comment import RequestInternalComment
|
from atst.models.request_internal_comment import RequestInternalComment
|
||||||
from atst.utils import deep_merge
|
from atst.utils import deep_merge
|
||||||
from atst.queue import queue
|
from atst.queue import queue
|
||||||
|
from atst.filters import dollars
|
||||||
|
|
||||||
from .query import RequestsQuery
|
from .query import RequestsQuery
|
||||||
from .authorization import RequestsAuthorization
|
from .authorization import RequestsAuthorization
|
||||||
@ -62,13 +63,24 @@ class Requests(object):
|
|||||||
def submit(cls, request):
|
def submit(cls, request):
|
||||||
request = Requests.set_status(request, RequestStatus.SUBMITTED)
|
request = Requests.set_status(request, RequestStatus.SUBMITTED)
|
||||||
|
|
||||||
new_status = None
|
|
||||||
if Requests.should_auto_approve(request):
|
if Requests.should_auto_approve(request):
|
||||||
new_status = RequestStatus.PENDING_FINANCIAL_VERIFICATION
|
request = Requests.set_status(
|
||||||
|
request, RequestStatus.PENDING_FINANCIAL_VERIFICATION
|
||||||
|
)
|
||||||
|
Requests._add_review(
|
||||||
|
user=None,
|
||||||
|
request=request,
|
||||||
|
review_data={
|
||||||
|
"comment": "Auto-acceptance for dollar value below {}".format(
|
||||||
|
dollars(Requests.AUTO_APPROVE_THRESHOLD)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
new_status = RequestStatus.PENDING_CCPO_ACCEPTANCE
|
request = Requests.set_status(
|
||||||
|
request, RequestStatus.PENDING_CCPO_ACCEPTANCE
|
||||||
|
)
|
||||||
|
|
||||||
request = Requests.set_status(request, new_status)
|
|
||||||
request = RequestsQuery.add_and_commit(request)
|
request = RequestsQuery.add_and_commit(request)
|
||||||
|
|
||||||
return request
|
return request
|
||||||
@ -95,6 +107,18 @@ class Requests(object):
|
|||||||
|
|
||||||
return workspace
|
return workspace
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def auto_approve_and_create_workspace(
|
||||||
|
cls,
|
||||||
|
request,
|
||||||
|
reason="Financial verification information found in Electronic Document Access API",
|
||||||
|
):
|
||||||
|
workspace = Requests.approve_and_create_workspace(request)
|
||||||
|
Requests._add_review(
|
||||||
|
user=None, request=request, review_data={"comment": reason}
|
||||||
|
)
|
||||||
|
return workspace
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_status(cls, request, status: RequestStatus):
|
def set_status(cls, request, status: RequestStatus):
|
||||||
old_status = request.status
|
old_status = request.status
|
||||||
@ -178,7 +202,7 @@ class Requests(object):
|
|||||||
return request
|
return request
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _add_review(cls, user, request, review_data):
|
def _add_review(cls, user=None, request=None, review_data=None):
|
||||||
request.latest_status.review = RequestReview(reviewer=user, **review_data)
|
request.latest_status.review = RequestReview(reviewer=user, **review_data)
|
||||||
request = RequestsQuery.add_and_commit(request)
|
request = RequestsQuery.add_and_commit(request)
|
||||||
return request
|
return request
|
||||||
@ -190,7 +214,7 @@ class Requests(object):
|
|||||||
elif request.status == RequestStatus.PENDING_CCPO_APPROVAL:
|
elif request.status == RequestStatus.PENDING_CCPO_APPROVAL:
|
||||||
Requests.approve_and_create_workspace(request)
|
Requests.approve_and_create_workspace(request)
|
||||||
|
|
||||||
return Requests._add_review(user, request, review_data)
|
return Requests._add_review(user=user, request=request, review_data=review_data)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def request_changes(cls, user, request, review_data):
|
def request_changes(cls, user, request, review_data):
|
||||||
@ -199,7 +223,7 @@ class Requests(object):
|
|||||||
elif request.status == RequestStatus.PENDING_CCPO_APPROVAL:
|
elif request.status == RequestStatus.PENDING_CCPO_APPROVAL:
|
||||||
Requests.set_status(request, RequestStatus.CHANGES_REQUESTED_TO_FINVER)
|
Requests.set_status(request, RequestStatus.CHANGES_REQUESTED_TO_FINVER)
|
||||||
|
|
||||||
return Requests._add_review(user, request, review_data)
|
return Requests._add_review(user=user, request=request, review_data=review_data)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_internal_comment(cls, user, request, comment_text):
|
def add_internal_comment(cls, user, request, comment_text):
|
||||||
|
@ -10,7 +10,7 @@ class RequestReview(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
|
|||||||
id = types.Id()
|
id = types.Id()
|
||||||
status = relationship("RequestStatusEvent", uselist=False, back_populates="review")
|
status = relationship("RequestStatusEvent", uselist=False, back_populates="review")
|
||||||
|
|
||||||
user_id = Column(ForeignKey("users.id"), nullable=False)
|
user_id = Column(ForeignKey("users.id"))
|
||||||
reviewer = relationship("User")
|
reviewer = relationship("User")
|
||||||
|
|
||||||
comment = Column(String)
|
comment = Column(String)
|
||||||
@ -23,7 +23,10 @@ class RequestReview(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def full_name_reviewer(self):
|
def full_name_reviewer(self):
|
||||||
return self.reviewer.full_name
|
if self.reviewer:
|
||||||
|
return self.reviewer.full_name
|
||||||
|
else:
|
||||||
|
return "System"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def full_name_mao(self):
|
def full_name_mao(self):
|
||||||
|
@ -241,7 +241,7 @@ def update_financial_verification(request_id):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if updated_request.task_order.verified:
|
if updated_request.task_order.verified:
|
||||||
workspace = Requests.approve_and_create_workspace(updated_request)
|
workspace = Requests.auto_approve_and_create_workspace(updated_request)
|
||||||
return redirect(
|
return redirect(
|
||||||
url_for(
|
url_for(
|
||||||
"workspaces.new_project", workspace_id=workspace.id, newWorkspace=True
|
"workspaces.new_project", workspace_id=workspace.id, newWorkspace=True
|
||||||
|
@ -44,6 +44,8 @@ def test_auto_approve_less_than_1m():
|
|||||||
request = Requests.submit(new_request)
|
request = Requests.submit(new_request)
|
||||||
|
|
||||||
assert request.status == RequestStatus.PENDING_FINANCIAL_VERIFICATION
|
assert request.status == RequestStatus.PENDING_FINANCIAL_VERIFICATION
|
||||||
|
assert request.reviews
|
||||||
|
assert request.reviews[0].full_name_reviewer == "System"
|
||||||
|
|
||||||
|
|
||||||
def test_dont_auto_approve_if_dollar_value_is_1m_or_above():
|
def test_dont_auto_approve_if_dollar_value_is_1m_or_above():
|
||||||
@ -222,6 +224,14 @@ def test_random_user_cannot_view_request():
|
|||||||
assert not RequestsAuthorization(user, request).can_view
|
assert not RequestsAuthorization(user, request).can_view
|
||||||
|
|
||||||
|
|
||||||
|
def test_auto_approve_and_create_workspace():
|
||||||
|
request = RequestFactory.create()
|
||||||
|
workspace = Requests.auto_approve_and_create_workspace(request)
|
||||||
|
assert workspace
|
||||||
|
assert request.reviews[0]
|
||||||
|
assert request.reviews[0].full_name_reviewer == "System"
|
||||||
|
|
||||||
|
|
||||||
class TestStatusNotifications(object):
|
class TestStatusNotifications(object):
|
||||||
def _assert_job(self, queue, request):
|
def _assert_job(self, queue, request):
|
||||||
assert len(queue.get_queue()) == 1
|
assert len(queue.get_queue()) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user