Skip to content

Commit f0dd40f

Browse files
PR Updates
1 parent 0f0fbd8 commit f0dd40f

File tree

7 files changed

+113
-40
lines changed

7 files changed

+113
-40
lines changed

feedback/forms.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django import forms
22
from django.forms.widgets import RadioSelect, Textarea, TextInput
33

4-
from .models import Feedback, ReportIssue
4+
from .models import Feedback, Issue
55

66

77
def formfield(field, **kwargs):
@@ -25,9 +25,9 @@ class Meta:
2525
formfield_callback = formfield
2626

2727

28-
class ReportIssueForm(forms.ModelForm):
28+
class IssueForm(forms.ModelForm):
2929
class Meta:
30-
model = ReportIssue
30+
model = Issue
3131
fields = [
3232
"reason",
3333
"additional_info",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Generated by Django 5.1.2 on 2024-10-22 09:23
2+
3+
import uuid
4+
5+
import django.core.validators
6+
from django.db import migrations, models
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
("feedback", "0009_alter_reportissue_additional_info_and_more"),
13+
]
14+
15+
operations = [
16+
migrations.CreateModel(
17+
name="Issue",
18+
fields=[
19+
(
20+
"id",
21+
models.UUIDField(
22+
default=uuid.uuid4,
23+
editable=False,
24+
primary_key=True,
25+
serialize=False,
26+
unique=True,
27+
),
28+
),
29+
("created", models.DateTimeField(auto_now_add=True)),
30+
("modified", models.DateTimeField(auto_now=True)),
31+
(
32+
"reason",
33+
models.CharField(
34+
choices=[
35+
("Link is broken", "Broken Link"),
36+
("Owner is incorrect", "Incorrect Owner"),
37+
("Contact is outdated", "Outdated Contact"),
38+
("Other", "Other"),
39+
],
40+
max_length=50,
41+
verbose_name="What is wrong with this page?",
42+
),
43+
),
44+
(
45+
"additional_info",
46+
models.TextField(
47+
validators=[django.core.validators.MinLengthValidator(10)],
48+
verbose_name="Can you provide more detail?",
49+
),
50+
),
51+
("entity_name", models.CharField(max_length=250)),
52+
("entity_url", models.CharField(max_length=250)),
53+
("data_owner_email", models.CharField(max_length=250)),
54+
(
55+
"user_email",
56+
models.CharField(
57+
blank=True,
58+
max_length=250,
59+
validators=[django.core.validators.EmailValidator()],
60+
),
61+
),
62+
],
63+
),
64+
migrations.DeleteModel(
65+
name="ReportIssue",
66+
),
67+
]

feedback/models.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class Feedback(models.Model):
2626
)
2727

2828

29-
class ReportIssue(models.Model):
29+
class Issue(models.Model):
3030
class IssueChoices(models.TextChoices):
31-
BROKEN_LINK = "Broken link"
32-
INCORRECT_OWNER = "Incorrect owner"
33-
OUTDATED_CONTACT = "Outdated contact"
31+
BROKEN_LINK = "Link is broken"
32+
INCORRECT_OWNER = "Owner is incorrect"
33+
OUTDATED_CONTACT = "Contact is outdated"
3434
OTHER = "Other"
3535

3636
id = models.UUIDField(
@@ -42,7 +42,7 @@ class IssueChoices(models.TextChoices):
4242
reason = models.CharField(
4343
max_length=50,
4444
choices=IssueChoices.choices,
45-
verbose_name=_("Reason"),
45+
verbose_name=_("What is wrong with this page?"),
4646
null=False,
4747
blank=False,
4848
)

feedback/service.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import logging
2+
import threading
23

34
from django.conf import settings
45
from notifications_python_client.notifications import NotificationsAPIClient
56

6-
from feedback.models import ReportIssue
7+
from feedback.models import Issue
78

89
log = logging.getLogger(__name__)
910

@@ -12,7 +13,15 @@
1213
)
1314

1415

15-
def send_notifications(issue: ReportIssue) -> None:
16+
def send_notifications(issue: Issue) -> None:
17+
if settings.NOTIFY_ENABLED:
18+
# Spawn a thread to process the sending of notifcations and avoid potential delays
19+
# returning a response to the user.
20+
t = threading.Thread(target=send, args=(issue,))
21+
t.start()
22+
23+
24+
def send(issue: Issue) -> None:
1625

1726
personalisation = {
1827
"assetOwner": (

feedback/views.py

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import logging
2-
import threading
32

4-
from django.conf import settings
53
from django.http import HttpResponse
64
from django.shortcuts import redirect, render
75
from django.utils.translation import gettext as _
86

9-
from .forms import FeedbackForm, ReportIssueForm
7+
from .forms import FeedbackForm, IssueForm
108
from .service import send_notifications
119

1210
log = logging.getLogger(__name__)
@@ -43,19 +41,16 @@ def thank_you_view(request) -> HttpResponse:
4341

4442
def report_issue_view(request) -> HttpResponse:
4543
if request.method == "POST":
46-
form = ReportIssueForm(request.POST)
44+
form = IssueForm(request.POST)
4745
if form.is_valid():
4846
issue = form.save(commit=False)
4947
issue.entity_name = request.session.get("entity_name")
5048
issue.entity_url = request.session.get("entity_url")
5149
issue.data_owner_email = request.session.get("data_owner_email")
5250
issue.save()
5351

54-
if settings.NOTIFY_ENABLED:
55-
# Spawn a thread to process the sending of notifcations and avoid potential delays
56-
# returning a response to the user.
57-
t = threading.Thread(target=send_notifications, args=(issue,))
58-
t.start()
52+
# Call the send notifications service
53+
send_notifications(issue=issue)
5954

6055
return redirect("feedback:thanks")
6156

@@ -65,7 +60,9 @@ def report_issue_view(request) -> HttpResponse:
6560
request,
6661
"report_issue.html",
6762
{
68-
"h1_value": _("Report an issue on Find MOJ data"),
63+
"h1_value": _(
64+
f"Report an issue with {request.session.get('entity_name')}"
65+
),
6966
"form": form,
7067
},
7168
)
@@ -77,13 +74,13 @@ def report_issue_view(request) -> HttpResponse:
7774
request.session["entity_url"] = entity_url
7875
request.session["data_owner_email"] = _(request.GET.get("data_owner_email", ""))
7976

80-
form = ReportIssueForm()
77+
form = IssueForm()
8178

8279
return render(
8380
request,
8481
"report_issue.html",
8582
{
86-
"h1_value": _("Report an issue on Find MOJ data"),
83+
"h1_value": _(f"Report an issue with {entity_name}"),
8784
"form": form,
8885
"entity_name": entity_name,
8986
"entity_url": entity_url,

tests/feedback/test_forms.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

3-
from feedback.forms import FeedbackForm, ReportIssueForm
4-
from feedback.models import Feedback, ReportIssue
3+
from feedback.forms import FeedbackForm, IssueForm
4+
from feedback.models import Feedback, Issue
55

66

77
def test_invalid_feedback_form():
@@ -27,16 +27,16 @@ def test_feedback_form_saves_to_db():
2727

2828

2929
def test_valid_report_issue_form():
30-
assert ReportIssueForm(
30+
assert IssueForm(
3131
{
3232
"reason": "Other",
3333
"additional_info": "a" * 10,
3434
}
35-
).is_valid
35+
).is_valid()
3636

3737

3838
def test_report_issue_form_invalid_additinal_info_length():
39-
form = ReportIssueForm(
39+
form = IssueForm(
4040
{
4141
"reason": "Other",
4242
"additional_info": "a" * 9,
@@ -50,7 +50,7 @@ def test_report_issue_form_invalid_additinal_info_length():
5050

5151

5252
def test_report_issue_form_invalid_user_email():
53-
form = ReportIssueForm(
53+
form = IssueForm(
5454
{"reason": "Other", "additional_info": "a" * 10, "user_email": "invalid_email"}
5555
)
5656
assert not form.is_valid()
@@ -59,15 +59,15 @@ def test_report_issue_form_invalid_user_email():
5959

6060
@pytest.mark.django_db
6161
def test_report_issue_form_saves_to_db():
62-
form = ReportIssueForm(
62+
form = IssueForm(
6363
{
6464
"reason": "Other",
6565
"additional_info": "a" * 10,
6666
}
6767
)
6868
form.save()
6969

70-
saved = ReportIssue.objects.first()
70+
saved = Issue.objects.first()
7171
assert saved
7272
assert saved.reason == "Other"
7373
assert saved.additional_info == "a" * 10

tests/feedback/test_notify_service.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import pytest
44

5-
from feedback.models import ReportIssue
6-
from feedback.service import send_notifications
5+
from feedback.models import Issue
6+
from feedback.service import send
77

88

99
@pytest.mark.django_db
@@ -18,10 +18,10 @@ def test_send_all_notifications(mock_notifications_client):
1818
"user_email": "userx@justice.gov.uk",
1919
}
2020

21-
issue = ReportIssue.objects.create(**data)
21+
issue = Issue.objects.create(**data)
2222
assert issue
2323

24-
send_notifications(issue=issue)
24+
send(issue=issue)
2525

2626
assert mock_notifications_client.call_count == 3
2727

@@ -37,10 +37,10 @@ def test_send_notifications_no_data_owner_email(mock_notifications_client):
3737
"user_email": "userx@justice.gov.uk",
3838
}
3939

40-
issue = ReportIssue.objects.create(**data)
40+
issue = Issue.objects.create(**data)
4141
assert issue
4242

43-
send_notifications(issue=issue)
43+
send(issue=issue)
4444

4545
assert mock_notifications_client.call_count == 2
4646

@@ -56,10 +56,10 @@ def test_send_all_notifications_no_user_email(mock_notifications_client):
5656
"data_owner_email": "entity_owner@justice.gov.uk",
5757
}
5858

59-
issue = ReportIssue.objects.create(**data)
59+
issue = Issue.objects.create(**data)
6060
assert issue
6161

62-
send_notifications(issue=issue)
62+
send(issue=issue)
6363

6464
assert mock_notifications_client.call_count == 2
6565

@@ -74,9 +74,9 @@ def test_send_all_notifications_no_user_or_data_owner_email(mock_notifications_c
7474
"entity_url": "http://localhost/my_entity",
7575
}
7676

77-
issue = ReportIssue.objects.create(**data)
77+
issue = Issue.objects.create(**data)
7878
assert issue
7979

80-
send_notifications(issue=issue)
80+
send(issue=issue)
8181

8282
assert mock_notifications_client.call_count == 1

0 commit comments

Comments
 (0)