Skip to content

Commit

Permalink
Rename project status committed to draft (#3223)
Browse files Browse the repository at this point in the history
Fixes #3221 

Add a custom migration to update the status of committed projects to
avoid errors.

---------

Co-authored-by: Fredrik Jonsson <[email protected]>
  • Loading branch information
sandeepsajan0 and frjo authored May 2, 2023
1 parent cf73d75 commit 6e54aaf
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 26 deletions.
6 changes: 3 additions & 3 deletions hypha/apply/projects/forms/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

from ..models.project import (
CLOSING,
COMMITTED,
COMPLETE,
DRAFT,
IN_PROGRESS,
PAF_STATUS_CHOICES,
PROJECT_STATUS_CHOICES,
Expand Down Expand Up @@ -271,8 +271,8 @@ def save(self, commit=True):

class SetPendingForm(ApproversForm):
def clean(self):
if self.instance.status != COMMITTED:
raise forms.ValidationError(_('A Project can only be sent for Approval when Committed.'))
if self.instance.status != DRAFT:
raise forms.ValidationError(_('A Project can only be sent for Approval when Drafted.'))

cleaned_data = super().clean()
return cleaned_data
Expand Down
18 changes: 18 additions & 0 deletions hypha/apply/projects/migrations/0073_alter_project_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.18 on 2023-05-02 13:40

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('application_projects', '0072_pafapprovals_approved_at'),
]

operations = [
migrations.AlterField(
model_name='project',
name='status',
field=models.TextField(choices=[('draft', 'Draft'), ('waiting_for_approval', 'Waiting for Approval'), ('contracting', 'Contracting'), ('in_progress', 'In Progress'), ('closing', 'Closing'), ('complete', 'Complete')], default='draft'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.17 on 2023-02-16 12:42

from django.db import migrations


def update_committed_project_status_to_draft(apps, schema_editor):
Project = apps.get_model('application_projects', 'Project')

for project in Project.objects.filter(status='committed'):
project.status = 'draft'
project.save(update_fields={'status'})


class Migration(migrations.Migration):

dependencies = [
('application_projects', '0073_alter_project_status'),
]

operations = [
migrations.RunPython(update_committed_project_status_to_draft)
]
10 changes: 5 additions & 5 deletions hypha/apply/projects/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ def contract_document_path(instance, filename):
(REQUEST_CHANGE, 'Request Change')
)

COMMITTED = 'committed'
DRAFT = 'draft'
WAITING_FOR_APPROVAL = 'waiting_for_approval'
CONTRACTING = 'contracting'
IN_PROGRESS = 'in_progress'
CLOSING = 'closing'
COMPLETE = 'complete'
PROJECT_STATUS_CHOICES = [
(COMMITTED, _('Committed')),
(DRAFT, _('Draft')),
(WAITING_FOR_APPROVAL, _('Waiting for Approval')),
(CONTRACTING, _('Contracting')),
(IN_PROGRESS, _('In Progress')),
Expand Down Expand Up @@ -161,7 +161,7 @@ class Project(BaseStreamForm, AccessFormData, models.Model):
proposed_start = models.DateTimeField(_('Proposed Start Date'), null=True)
proposed_end = models.DateTimeField(_('Proposed End Date'), null=True)

status = models.TextField(choices=PROJECT_STATUS_CHOICES, default=COMMITTED)
status = models.TextField(choices=PROJECT_STATUS_CHOICES, default=DRAFT)

form_data = models.JSONField(encoder=StreamFieldDataEncoder, default=dict)
form_fields = StreamField(ProjectApprovalFormCustomFormFieldsBlock(), null=True, use_json_field=True)
Expand Down Expand Up @@ -321,7 +321,7 @@ def editable_by(self, user):
def editable(self):
if self.is_locked:
return False
elif self.status == COMMITTED: # locked condition is enough,it is just for double check
elif self.status == DRAFT: # locked condition is enough,it is just for double check
return True
return False

Expand Down Expand Up @@ -360,7 +360,7 @@ def can_send_for_approval(self):
we infer it from the current status being "Comitted" and the Project
being locked.
"""
correct_state = self.status == COMMITTED and not self.is_locked
correct_state = self.status == DRAFT and not self.is_locked
return correct_state and self.user_has_updated_details

def get_missing_document_categories(self):
Expand Down
6 changes: 3 additions & 3 deletions hypha/apply/projects/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from .models.project import (
CLOSING,
COMMITTED,
COMPLETE,
CONTRACTING,
DRAFT,
IN_PROGRESS,
WAITING_FOR_APPROVAL,
ProjectSettings,
Expand Down Expand Up @@ -170,9 +170,9 @@ def can_access_project(user, project):
if user.is_applicant and user == project.user:
return True, 'Applicant(project user) can view project in all statuses'

if project.status in [COMMITTED, WAITING_FOR_APPROVAL] and project.paf_approvals.exists() and \
if project.status in [DRAFT, WAITING_FOR_APPROVAL] and project.paf_approvals.exists() and \
user.id in project.paf_approvals.all().values_list('user', flat=True):
return True, 'PAF Approvers can access the project in Committed and Approval state'
return True, 'PAF Approvers can access the project in Draft and Approval state'

return False, 'Forbidden Error'

Expand Down
12 changes: 6 additions & 6 deletions hypha/apply/projects/templatetags/project_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

from hypha.apply.projects.models.project import (
CLOSING,
COMMITTED,
COMPLETE,
CONTRACTING,
DRAFT,
IN_PROGRESS,
WAITING_FOR_APPROVAL,
)
Expand All @@ -23,7 +23,7 @@ def project_can_have_report(project):

@register.simple_tag
def user_next_step_on_project(project, user):
if project.status == COMMITTED:
if project.status == DRAFT:
if user.is_apply_staff:
if not project.user_has_updated_details:
return "Fill in the Approval Form(PAF)"
Expand Down Expand Up @@ -103,7 +103,7 @@ def user_can_view_report(report, user):

@register.simple_tag
def project_can_have_contracting_section(project):
if project.status in [COMMITTED, WAITING_FOR_APPROVAL]:
if project.status in [DRAFT, WAITING_FOR_APPROVAL]:
return False
return True

Expand Down Expand Up @@ -142,16 +142,16 @@ def project_settings_url(instance):

@register.simple_tag
def allow_collapsible_header(project, header_type):
if header_type == 'project_documents' and project.status not in [COMMITTED, WAITING_FOR_APPROVAL]:
if header_type == 'project_documents' and project.status not in [DRAFT, WAITING_FOR_APPROVAL]:
return True
if header_type == 'contracting_documents' and project.status not in [COMMITTED, WAITING_FOR_APPROVAL, CONTRACTING]:
if header_type == 'contracting_documents' and project.status not in [DRAFT, WAITING_FOR_APPROVAL, CONTRACTING]:
return True
return False


@register.simple_tag
def user_can_remove_supporting_documents(project, user):
if user.is_apply_staff and project.status == COMMITTED:
if user.is_apply_staff and project.status == DRAFT:
return True
return False

Expand Down
6 changes: 3 additions & 3 deletions hypha/apply/projects/tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
)
from ..models.project import (
CLOSING,
COMMITTED,
COMPLETE,
CONTRACTING,
DRAFT,
IN_PROGRESS,
WAITING_FOR_APPROVAL,
)
Expand All @@ -31,7 +31,7 @@ class TestContractTools(TestCase):
def test_staff_cant_upload_contract(self):
staff = StaffFactory()

project = ProjectFactory(status=COMMITTED)
project = ProjectFactory(status=DRAFT)
self.assertFalse(user_can_upload_contract(project, staff))

project = ProjectFactory(status=WAITING_FOR_APPROVAL)
Expand All @@ -52,7 +52,7 @@ def test_staff_cant_upload_contract(self):
def test_owner_can_only_upload_during_contracting(self):
applicant = ApplicantFactory()

project = ProjectFactory(status=COMMITTED, user=applicant)
project = ProjectFactory(status=DRAFT, user=applicant)
self.assertFalse(user_can_upload_contract(project, applicant))

project = ProjectFactory(status=WAITING_FOR_APPROVAL, user=applicant)
Expand Down
8 changes: 4 additions & 4 deletions hypha/apply/projects/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
from ..models.project import (
APPROVE,
CLOSING,
COMMITTED,
COMPLETE,
CONTRACTING,
DRAFT,
IN_PROGRESS,
REQUEST_CHANGE,
WAITING_FOR_APPROVAL,
Expand Down Expand Up @@ -96,7 +96,7 @@ def test_send_for_approval_fails_when_project_is_locked(self):
form = SetPendingForm(instance=project)
self.assertFalse(form.is_valid())

def test_send_for_approval_fails_when_project_is_not_in_committed_state(self):
def test_send_for_approval_fails_when_project_is_not_in_draft_state(self):
project = ProjectFactory(status='in_progress')

# The view doesn't have any custom changes when form validation fails
Expand All @@ -105,7 +105,7 @@ def test_send_for_approval_fails_when_project_is_not_in_committed_state(self):
self.assertFalse(form.is_valid())

def test_send_for_approval_happy_path(self):
project = ProjectFactory(is_locked=False, status=COMMITTED)
project = ProjectFactory(is_locked=False, status=DRAFT)

response = self.post_page(project, {'form-submitted-request_approval_form': ''})
self.assertEqual(response.status_code, 200)
Expand Down Expand Up @@ -198,7 +198,7 @@ def test_assigned_approvers_can_reject_paf(self):

self.assertEqual(response.status_code, 200)
project.refresh_from_db()
self.assertEqual(project.status, COMMITTED)
self.assertEqual(project.status, DRAFT)
approval.refresh_from_db()
self.assertEqual(self.role.label, approval.paf_reviewer_role.label)
self.assertFalse(approval.approved)
Expand Down
4 changes: 2 additions & 2 deletions hypha/apply/projects/views/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
from ..models.payment import Invoice
from ..models.project import (
APPROVE,
COMMITTED,
CONTRACTING,
DRAFT,
IN_PROGRESS,
PROJECT_ACTION_MESSAGE_TAG,
PROJECT_STATUS_CHOICES,
Expand Down Expand Up @@ -489,7 +489,7 @@ def form_valid(self, form):
)

if paf_status == REQUEST_CHANGE:
self.object.status = COMMITTED
self.object.status = DRAFT
self.object.save(update_fields=['status'])

messenger(
Expand Down

0 comments on commit 6e54aaf

Please sign in to comment.