Skip to content

Commit

Permalink
Add support view support for task workflow deletion (#1329)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpepper-trade authored Nov 18, 2024
1 parent 01db672 commit baf7f61
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tasks/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,6 @@ def __init__(self, *args, **kwargs):
class TaskTemplateUpdateForm(TaskTemplateFormBase):
def __init__(self, *args, **kwargs):
super().__init__(*args, submit_title="Update", **kwargs)


TaskTemplateDeleteForm = delete_form_for(TaskTemplate)
58 changes: 58 additions & 0 deletions tasks/jinja2/tasks/workflows/task_template_confirm_delete.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{% extends "layouts/confirm.jinja" %}

{% from "components/breadcrumbs/macro.njk" import govukBreadcrumbs %}
{% from "components/panel/macro.njk" import govukPanel %}
{% from "components/button/macro.njk" import govukButton %}

{% set page_title = "Task template deleted" %}


{% block breadcrumb %}
{{ breadcrumbs(
request,
[
{"text": "Find and view workflow templates", "href": "#TODO"},
{
"text": "Workflow template: " ~ task_workflow_template.title,
"href": url(
"workflow:task-workflow-template-ui-detail",
kwargs={"pk": task_workflow_template.pk},
),
},
{"text": page_title}
],
False,
) }}
{% endblock %}

{% block panel %}
{{ govukPanel({
"titleText": "Task template ID: " ~ deleted_pk,
"text": "Task template has been deleted",
"classes": "govuk-!-margin-bottom-7"
}) }}
{% endblock %}

{% block button_group %}
{{ govukButton({
"text": "View workflow template",
"href": url(
"workflow:task-workflow-template-ui-detail",
kwargs={"pk": task_workflow_template.pk},
),
"classes": "govuk-button"
}) }}
{{ govukButton({
"text": "Return to homepage",
"href": url("home"),
"classes": "govuk-button--secondary"
}) }}
{% endblock %}

{% block actions %}
<li>
<a class="govuk-link"
href="{{ url('workflow:task-template-ui-create', kwargs={'workflow_template_pk': task_workflow_template.pk}) }}"
>Create a task template</a>
</li>
{% endblock %}
40 changes: 40 additions & 0 deletions tasks/jinja2/tasks/workflows/task_template_delete.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% extends "common/delete.jinja" %}

{% from "components/breadcrumbs.jinja" import breadcrumbs %}
{% from "components/warning-text/macro.njk" import govukWarningText %}
{% from "components/button/macro.njk" import govukButton %}

{% set page_title = "Delete task template:" ~ object.title %}


{% block breadcrumb %}
{{ breadcrumbs(
request,
[
{"text": "Find and view workflow templates", "href": "#TODO"},
{
"text": "Workflow template: " ~ task_workflow_template.title,
"href": url("workflow:task-workflow-template-ui-detail", kwargs={"pk": task_workflow_template.pk}),
},
{"text": page_title}
],
False,
) }}
{% endblock %}

{% block form %}
{{ govukWarningText({
"text": "Are you sure you want to delete this task template?"
}) }}

{% call django_form(
action=url(
"workflow:task-template-ui-delete",
kwargs={
"workflow_template_pk": task_workflow_template.pk,
"pk": object.pk,
}),
) %}
{{ crispy(form) }}
{% endcall %}
{% endblock %}
9 changes: 8 additions & 1 deletion tasks/jinja2/tasks/workflows/task_template_detail.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@
<div class="govuk-button-group govuk-!-margin-top-6">
{{ govukButton({
"text": "Delete task template",
"href": "#TODO",
"href": url(
"workflow:task-template-ui-delete",
kwargs={
"workflow_template_pk": task_workflow_template.pk,
"pk": object.pk,
},
),

"classes": "govuk-button--warning"
}) }}
</div>
Expand Down
60 changes: 60 additions & 0 deletions tasks/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
from common.tests.factories import SubTaskFactory
from common.tests.factories import TaskFactory
from tasks.models import ProgressState
from tasks.models import TaskItemTemplate
from tasks.models import TaskLog
from tasks.models import TaskTemplate
from tasks.models import TaskWorkflowTemplate
from tasks.tests.factories import TaskItemTemplateFactory

pytestmark = pytest.mark.django_db
Expand Down Expand Up @@ -307,3 +310,60 @@ def test_update_task_template_view(

assert confirmation_response.status_code == 200
assert updated_task_template.title in soup.select("h1.govuk-panel__title")[0].text


def test_delete_task_template_view(
valid_user_client,
task_workflow_template_single_task_template_item,
):
"""Test the view for deleting TaskTemplates and the confirmation view that a
successful deletion redirects to."""

assert (
task_workflow_template_single_task_template_item.get_task_templates().count()
== 1
)
assert task_workflow_template_single_task_template_item.get_items().count() == 1

task_template_pk = (
task_workflow_template_single_task_template_item.get_task_templates().get().pk
)
task_item_template_pk = (
task_workflow_template_single_task_template_item.get_items().get().pk
)
delete_url = reverse(
"workflow:task-template-ui-delete",
kwargs={
"workflow_template_pk": task_workflow_template_single_task_template_item.pk,
"pk": task_template_pk,
},
)

delete_response = valid_user_client.post(delete_url)
task_workflow_template_after = TaskWorkflowTemplate.objects.get(
pk=task_workflow_template_single_task_template_item.pk,
)

confirmation_url = reverse(
"workflow:task-template-ui-confirm-delete",
kwargs={
"workflow_template_pk": task_workflow_template_single_task_template_item.pk,
"pk": task_template_pk,
},
)

assert delete_response.status_code == 302
assert delete_response.url == confirmation_url
assert task_workflow_template_after.get_task_templates().count() == 0
assert not TaskTemplate.objects.filter(pk=task_template_pk)
assert not TaskItemTemplate.objects.filter(pk=task_item_template_pk)

confirmation_response = valid_user_client.get(confirmation_url)

soup = BeautifulSoup(str(confirmation_response.content), "html.parser")

assert confirmation_response.status_code == 200
assert (
f"Task template ID: {task_template_pk}"
in soup.select(".govuk-panel__title")[0].text
)
10 changes: 10 additions & 0 deletions tasks/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@
views.TaskTemplateConfirmUpdateView.as_view(),
name="task-template-ui-confirm-update",
),
path(
"<int:workflow_template_pk>/task-templates/<int:pk>/delete/",
views.TaskTemplateDeleteView.as_view(),
name="task-template-ui-delete",
),
path(
"<int:workflow_template_pk>/task-templates/<int:pk>/confirm-delete/",
views.TaskTemplateConfirmDeleteView.as_view(),
name="task-template-ui-confirm-delete",
),
]

urlpatterns = [
Expand Down
44 changes: 44 additions & 0 deletions tasks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from tasks.forms import TaskCreateForm
from tasks.forms import TaskDeleteForm
from tasks.forms import TaskTemplateCreateForm
from tasks.forms import TaskTemplateDeleteForm
from tasks.forms import TaskTemplateUpdateForm
from tasks.forms import TaskUpdateForm
from tasks.models import Task
Expand Down Expand Up @@ -340,3 +341,46 @@ def get_context_data(self, **kwargs) -> dict:
context["task_workflow_template"] = self.get_object().taskitemtemplate.queue

return context


class TaskTemplateDeleteView(PermissionRequiredMixin, DeleteView):
model = TaskTemplate
template_name = "tasks/workflows/task_template_delete.jinja"
permission_required = "tasks.delete_tasktemplate"
form_class = TaskTemplateDeleteForm

def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs["instance"] = self.object
return kwargs

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

context["task_workflow_template"] = self.get_object().taskitemtemplate.queue

return context

def get_success_url(self):
return reverse(
"workflow:task-template-ui-confirm-delete",
kwargs={
"workflow_template_pk": self.kwargs["workflow_template_pk"],
"pk": self.object.pk,
},
)


class TaskTemplateConfirmDeleteView(PermissionRequiredMixin, TemplateView):
template_name = "tasks/workflows/task_template_confirm_delete.jinja"
permission_required = "tasks.delete_tasktemplate"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

context["deleted_pk"] = self.kwargs["pk"]
context["task_workflow_template"] = TaskWorkflowTemplate.objects.get(
pk=self.kwargs["workflow_template_pk"],
)

return context

0 comments on commit baf7f61

Please sign in to comment.