prevent redundant invitations for task order officers
This commit is contained in:
parent
55bfbc4696
commit
33de14caaf
@ -63,3 +63,21 @@ class Workspace(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
|
|||||||
return "<Workspace(name='{}', request='{}', user_count='{}', id='{}')>".format(
|
return "<Workspace(name='{}', request='{}', user_count='{}', id='{}')>".format(
|
||||||
self.name, self.request_id, self.user_count, self.id
|
self.name, self.request_id, self.user_count, self.id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _find_by_role(self, role):
|
||||||
|
try:
|
||||||
|
return [member for member in self.members if member.role.name == role]
|
||||||
|
except StopIteration:
|
||||||
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def contracting_officer(self):
|
||||||
|
return self._find_by_role("contracting_officer")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def contracting_officer_representative(self):
|
||||||
|
return self._find_by_role("contracting_officer_representative")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def security_officer(self):
|
||||||
|
return self._find_by_role("security_officer")
|
||||||
|
@ -112,6 +112,11 @@ class UpdateTaskOrderWorkflow(ShowTaskOrderWorkflow):
|
|||||||
def form(self):
|
def form(self):
|
||||||
return self._section["form"](self.form_data)
|
return self._section["form"](self.form_data)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def workspace(self):
|
||||||
|
if self.task_order:
|
||||||
|
return self.task_order.workspace
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
return self.form.validate()
|
return self.form.validate()
|
||||||
|
|
||||||
@ -152,7 +157,11 @@ class UpdateTaskOrderWorkflow(ShowTaskOrderWorkflow):
|
|||||||
def _update_invitations(self):
|
def _update_invitations(self):
|
||||||
for officer_type in self.OFFICER_INVITATIONS:
|
for officer_type in self.OFFICER_INVITATIONS:
|
||||||
field = officer_type["field"]
|
field = officer_type["field"]
|
||||||
if hasattr(self.form, field) and self.form[field].data:
|
if (
|
||||||
|
hasattr(self.form, field)
|
||||||
|
and self.form[field].data
|
||||||
|
and not getattr(self.workspace, officer_type["role"])
|
||||||
|
):
|
||||||
prefix = officer_type["prefix"]
|
prefix = officer_type["prefix"]
|
||||||
officer_data = {
|
officer_data = {
|
||||||
field: getattr(self.task_order, prefix + "_" + field)
|
field: getattr(self.task_order, prefix + "_" + field)
|
||||||
|
@ -152,3 +152,23 @@ def test_invite_officers_to_task_order(queue):
|
|||||||
assert "contracting_officer_representative" in roles
|
assert "contracting_officer_representative" in roles
|
||||||
assert "security_officer" in roles
|
assert "security_officer" in roles
|
||||||
assert len(queue.get_queue()) == 3
|
assert len(queue.get_queue()) == 3
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_does_not_resend_invitation():
|
||||||
|
user = UserFactory.create()
|
||||||
|
contracting_officer = UserFactory.create()
|
||||||
|
workspace = WorkspaceFactory.create(owner=user)
|
||||||
|
task_order = TaskOrderFactory.create(
|
||||||
|
creator=user,
|
||||||
|
workspace=workspace,
|
||||||
|
ko_first_name=contracting_officer.first_name,
|
||||||
|
ko_last_name=contracting_officer.last_name,
|
||||||
|
ko_dod_id=contracting_officer.dod_id,
|
||||||
|
)
|
||||||
|
to_data = {**task_order.to_dictionary(), "ko_invite": True}
|
||||||
|
workflow = UpdateTaskOrderWorkflow(
|
||||||
|
to_data, user, screen=3, task_order_id=task_order.id
|
||||||
|
)
|
||||||
|
for i in range(2):
|
||||||
|
workflow.update()
|
||||||
|
assert len(contracting_officer.invitations) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user