From 6e54aafcc8c3fa3fafd02269c6183cb49d636efc Mon Sep 17 00:00:00 2001 From: Sandeep Chauhan Date: Tue, 2 May 2023 19:51:44 +0530 Subject: [PATCH] Rename project status committed to draft (#3223) Fixes #3221 Add a custom migration to update the status of committed projects to avoid errors. --------- Co-authored-by: Fredrik Jonsson --- hypha/apply/projects/forms/project.py | 6 ++--- .../migrations/0073_alter_project_status.py | 18 +++++++++++++++ ...date_projects_status_committed_to_draft.py | 22 +++++++++++++++++++ hypha/apply/projects/models/project.py | 10 ++++----- hypha/apply/projects/permissions.py | 6 ++--- .../projects/templatetags/project_tags.py | 12 +++++----- .../apply/projects/tests/test_templatetags.py | 6 ++--- hypha/apply/projects/tests/test_views.py | 8 +++---- hypha/apply/projects/views/project.py | 4 ++-- 9 files changed, 66 insertions(+), 26 deletions(-) create mode 100644 hypha/apply/projects/migrations/0073_alter_project_status.py create mode 100644 hypha/apply/projects/migrations/0074_update_projects_status_committed_to_draft.py diff --git a/hypha/apply/projects/forms/project.py b/hypha/apply/projects/forms/project.py index b95088d68d..2a3db20997 100644 --- a/hypha/apply/projects/forms/project.py +++ b/hypha/apply/projects/forms/project.py @@ -12,8 +12,8 @@ from ..models.project import ( CLOSING, - COMMITTED, COMPLETE, + DRAFT, IN_PROGRESS, PAF_STATUS_CHOICES, PROJECT_STATUS_CHOICES, @@ -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 diff --git a/hypha/apply/projects/migrations/0073_alter_project_status.py b/hypha/apply/projects/migrations/0073_alter_project_status.py new file mode 100644 index 0000000000..8f88000aa1 --- /dev/null +++ b/hypha/apply/projects/migrations/0073_alter_project_status.py @@ -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'), + ), + ] diff --git a/hypha/apply/projects/migrations/0074_update_projects_status_committed_to_draft.py b/hypha/apply/projects/migrations/0074_update_projects_status_committed_to_draft.py new file mode 100644 index 0000000000..66dbbd60f7 --- /dev/null +++ b/hypha/apply/projects/migrations/0074_update_projects_status_committed_to_draft.py @@ -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) + ] diff --git a/hypha/apply/projects/models/project.py b/hypha/apply/projects/models/project.py index 8b232bbaad..812216dfbe 100644 --- a/hypha/apply/projects/models/project.py +++ b/hypha/apply/projects/models/project.py @@ -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')), @@ -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) @@ -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 @@ -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): diff --git a/hypha/apply/projects/permissions.py b/hypha/apply/projects/permissions.py index 18b4c69b54..d7548b885c 100644 --- a/hypha/apply/projects/permissions.py +++ b/hypha/apply/projects/permissions.py @@ -2,9 +2,9 @@ from .models.project import ( CLOSING, - COMMITTED, COMPLETE, CONTRACTING, + DRAFT, IN_PROGRESS, WAITING_FOR_APPROVAL, ProjectSettings, @@ -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' diff --git a/hypha/apply/projects/templatetags/project_tags.py b/hypha/apply/projects/templatetags/project_tags.py index 341dbd8f93..7b20c9ac99 100644 --- a/hypha/apply/projects/templatetags/project_tags.py +++ b/hypha/apply/projects/templatetags/project_tags.py @@ -3,9 +3,9 @@ from hypha.apply.projects.models.project import ( CLOSING, - COMMITTED, COMPLETE, CONTRACTING, + DRAFT, IN_PROGRESS, WAITING_FOR_APPROVAL, ) @@ -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)" @@ -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 @@ -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 diff --git a/hypha/apply/projects/tests/test_templatetags.py b/hypha/apply/projects/tests/test_templatetags.py index 61b0ff11d1..1b8b87826a 100644 --- a/hypha/apply/projects/tests/test_templatetags.py +++ b/hypha/apply/projects/tests/test_templatetags.py @@ -16,9 +16,9 @@ ) from ..models.project import ( CLOSING, - COMMITTED, COMPLETE, CONTRACTING, + DRAFT, IN_PROGRESS, WAITING_FOR_APPROVAL, ) @@ -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) @@ -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) diff --git a/hypha/apply/projects/tests/test_views.py b/hypha/apply/projects/tests/test_views.py index 373397909d..d654542ff9 100644 --- a/hypha/apply/projects/tests/test_views.py +++ b/hypha/apply/projects/tests/test_views.py @@ -28,9 +28,9 @@ from ..models.project import ( APPROVE, CLOSING, - COMMITTED, COMPLETE, CONTRACTING, + DRAFT, IN_PROGRESS, REQUEST_CHANGE, WAITING_FOR_APPROVAL, @@ -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 @@ -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) @@ -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) diff --git a/hypha/apply/projects/views/project.py b/hypha/apply/projects/views/project.py index b7a46e1fea..9399e1120f 100644 --- a/hypha/apply/projects/views/project.py +++ b/hypha/apply/projects/views/project.py @@ -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, @@ -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(