Skip to content

Commit

Permalink
Merge branch 'dev' into LTD-4661-HCSAT
Browse files Browse the repository at this point in the history
  • Loading branch information
Tllew authored Feb 12, 2024
2 parents 502176c + fd86a5c commit 64bd791
Show file tree
Hide file tree
Showing 52 changed files with 1,173 additions and 162 deletions.
9 changes: 5 additions & 4 deletions caseworker/cases/forms/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@

class CloseQueryForm(forms.Form):
reason_for_closing_query = forms.CharField(
label="",
label="Why are you closing the query? This will not be visible to the exporter.",
widget=forms.Textarea,
help_text="Why are you closing the query? This will not be visible to the exporter.",
required=False,
error_messages={"required": "Enter a reason why you are closing the query"},
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.layout = Layout("reason_for_closing_query", Button("submit", "Submit"))
self.helper.layout = Layout(
"reason_for_closing_query", Button("submit", "Submit", css_class="govuk-!-margin-bottom-0")
)
2 changes: 1 addition & 1 deletion caseworker/cases/helpers/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def _transform_data(self):
for queue_detail in self.case.queue_details:
queue_detail["days_on_queue_elapsed"] = (timezone.now() - parse(queue_detail["joined_queue_at"])).days

def get(self, request, **kwargs):
def get(self, request, *args, **kwargs):
self.case_id = str(kwargs["pk"])
self.case = get_case(request, self.case_id)
self.queue_id = kwargs["queue_pk"]
Expand Down
28 changes: 13 additions & 15 deletions caseworker/cases/views/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
from django.urls import reverse, reverse_lazy
from django.utils import timezone
from django.utils.functional import cached_property
from django.views.generic import FormView, TemplateView
from django.views.generic import FormView, TemplateView, View

from requests.exceptions import HTTPError

from core.auth.views import LoginRequiredMixin
from core.builtins.custom_tags import filter_advice_by_level
from core.decorators import expect_status
from core.file_handler import s3_client
from core.exceptions import APIError
from core.helpers import get_document_data
from core.file_handler import download_document_from_s3

from lite_content.lite_internal_frontend import cases
from lite_content.lite_internal_frontend.cases import (
Expand Down Expand Up @@ -523,37 +525,33 @@ def post(self, request, **kwargs):
file = files[0]
data.append(
{
"name": file.original_name,
"s3_key": file.name,
"size": int(file.size // 1024) if file.size else 0, # in kilobytes
"description": request.POST["description"],
**get_document_data(file),
}
)

# Send LITE API the file information
case_documents, _ = post_case_documents(request, case_id, data)

if "errors" in case_documents:
if settings.DEBUG:
raise APIError(case_documents["errors"])
return error_page(None, "We had an issue uploading your files. Try again later.")

return redirect(
reverse("cases:case", kwargs={"queue_pk": kwargs["queue_pk"], "pk": case_id, "tab": "documents"})
)


class Document(TemplateView):
class Document(View):
def get(self, request, **kwargs):
document, _ = get_document(request, pk=kwargs["file_pk"])
client = s3_client()
signed_url = client.generate_presigned_url(
"get_object",
Params={
"Bucket": settings.AWS_STORAGE_BUCKET_NAME,
"Key": document["document"]["s3_key"],
},
ExpiresIn=15,
document = document["document"]

return download_document_from_s3(
document["s3_key"],
document["name"],
)
return redirect(signed_url)


class CaseOfficer(SingleFormView):
Expand Down
22 changes: 22 additions & 0 deletions caseworker/cases/views/queries.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from django.http import Http404
from django.urls import reverse
from django.views.generic import FormView

from caseworker.cases.forms.queries import CloseQueryForm
from caseworker.cases.helpers.ecju_queries import get_ecju_queries
from caseworker.cases.services import put_ecju_query
from core.auth.views import LoginRequiredMixin


class CloseQueryView(LoginRequiredMixin, FormView):
form_class = CloseQueryForm
template_name = "case/close-query.html"

def dispatch(self, request, *args, **kwargs):
self.lite_user = request.lite_user
Expand Down Expand Up @@ -35,3 +38,22 @@ def get_success_url(self):
"tab": "ecju-queries",
},
)

def get_query(self, open_ecju_queries):
for query in open_ecju_queries:
if query["id"] == str(self.kwargs["query_pk"]):
return query
return None

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

open_ecju_queries, _ = get_ecju_queries(self.request, self.kwargs["pk"])
query = self.get_query(open_ecju_queries)
if not query:
raise Http404

context["title"] = "Close query"
context["query"] = query

return context
35 changes: 35 additions & 0 deletions caseworker/templates/case/close-query.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{% extends 'layouts/two-pane.html' %}
{% load crispy_forms_tags crispy_forms_gds %}

{% block title %}{{title}}{% endblock %}
{% block back_link %}
<a href="{{ back_link_url }}" id="back-link" class="govuk-back-link">{{ back_link_text|default:"Back" }}</a>
{% endblock %}

{% block two_thirds %}

{% if errors %}
{% include "forms-errors.html" %}
{% endif %}

<form action="{{ form_action_url }}" method="post" enctype="multipart/form-data">
{% csrf_token %}

{% error_summary form %}

<div class="govuk-body">
<h1 class="govuk-label-wrapper">
<label class="govuk-label--l">
Close query
</label>
</h1>
<div class=" govuk-!-padding-top-3 govuk-!-padding-bottom-3">
<div class="app-ecju-query__text">
{{ query.question }}
</div>
</div>
{% crispy form %}
</div>
</form>

{% endblock %}
2 changes: 1 addition & 1 deletion caseworker/templates/case/tabs/ecju-queries.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h3 class="govuk-heading-m">{% lcs 'cases.EcjuQueries.OPEN' %}</h3>
{{ ecju_query.question|linebreaks }}
</div>
<p class="app-ecju-query__date">
Sent at {{ ecju_query.created_at|str_time_on_date }}. This query has been open for {{ ecju_query.open_working_days }} working days.
Sent at {{ ecju_query.created_at|str_time_on_date }}. This query has been open for {{ ecju_query.open_working_days }} working day{{ ecju_query.open_working_days|pluralize }}.
</p>
<details class="govuk-details">
<summary class="govuk-details__summary">
Expand Down
5 changes: 5 additions & 0 deletions caseworker/templates/layouts/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ <h2 class="govuk-visually-hidden">Support links</h2>
</a>
</li>
{% endif %}
<li class="govuk-footer__inline-list-item">
<a class="govuk-footer__link" href="/accessibility-statement">
Accessibility statement
</a>
</li>
</ul>

<span class="govuk-footer__licence-description">
Expand Down
10 changes: 6 additions & 4 deletions caseworker/templates/users/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ <h1 class="govuk-heading-l">
<a href="{% url 'teams:team' data.user.team.id %}" id="user-team-name" class="govuk-link govuk-link--no-visited-state">{{ data.user.team.name }}</a>
</dd>
<dd class="govuk-summary-list__actions">
<a id="link-edit-team" href="{% url 'users:edit' data.user.id %}#team" class="govuk-link govuk-link--no-visited-state">
{% lcs 'users.UserProfile.SummaryList.CHANGE' %}
<span class="govuk-visually-hidden">{% lcs 'users.UserProfile.SummaryList.TEAM' %}</span>
</a>
{% if can_edit_team %}
<a id="link-edit-team" href="{% url 'users:edit' data.user.id %}#team" class="govuk-link govuk-link--no-visited-state">
{% lcs 'users.UserProfile.SummaryList.CHANGE' %}
<span class="govuk-visually-hidden">{% lcs 'users.UserProfile.SummaryList.TEAM' %}</span>
</a>
{% endif %}
</dd>
</div>
<div class="govuk-summary-list__row">
Expand Down
7 changes: 7 additions & 0 deletions caseworker/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import caseworker.core.views

from core.accessibility.views import CaseworkerAccessibilityStatementView


urlpatterns = [
path("healthcheck/", include("health_check.urls")),
Expand All @@ -27,6 +29,11 @@
path("tau/report_summary/", include("caseworker.report_summary.urls")),
path("search/", include("caseworker.search.urls")),
path("bookmarks/", include("caseworker.bookmarks.urls")),
path(
"accessibility-statement/",
CaseworkerAccessibilityStatementView.as_view(),
name="caseworker-accessibility-statement",
),
]


Expand Down
15 changes: 9 additions & 6 deletions caseworker/users/forms/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@ def add_user_form(request):
)


def edit_user_form(request, user, can_edit_role: bool):
def edit_user_form(request, user, can_edit_role: bool, can_edit_team: bool):
return Form(
title=EditUserForm.TITLE.format(user["first_name"], user["last_name"]),
questions=[
TextInput(title=EditUserForm.Email.TITLE, description=EditUserForm.Email.DESCRIPTION, name="email"),
Select(
title=EditUserForm.Team.TITLE,
description=EditUserForm.Team.DESCRIPTION,
name="team",
options=get_teams(request, True),
conditional(
can_edit_team,
Select(
title=EditUserForm.Team.TITLE,
description=EditUserForm.Team.DESCRIPTION,
name="team",
options=get_teams(request, True),
),
),
conditional(
can_edit_role,
Expand Down
4 changes: 4 additions & 0 deletions caseworker/users/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ def is_super_user(user):
return user["user"]["role"]["id"] == SUPER_USER_ROLE_ID


def is_user_in_team(user, team_id):
return user["user"]["team"]["id"] == team_id


def get_user_case_note_mentions(request, params):

query_params = urlencode(params)
Expand Down
26 changes: 23 additions & 3 deletions caseworker/users/views/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
from caseworker.cases.services import update_mentions

from core.auth.views import LoginRequiredMixin
from caseworker.core.constants import SUPER_USER_ROLE_ID, UserStatuses
from caseworker.core.constants import (
ADMIN_TEAM_ID,
SUPER_USER_ROLE_ID,
UserStatuses,
)
from lite_content.lite_internal_frontend import strings
from lite_content.lite_internal_frontend.users import UsersPage
from lite_forms.components import FiltersBar, Select, Option, TextInput
Expand All @@ -19,6 +23,7 @@
put_gov_user,
get_gov_user,
is_super_user,
is_user_in_team,
get_user_case_note_mentions,
)

Expand Down Expand Up @@ -77,13 +82,15 @@ def get(self, request, **kwargs):
super_user = is_super_user(request_user)
can_deactivate = not is_super_user(data)
can_edit_role = data["user"]["id"] != request.session["lite_api_user_id"]
can_edit_team = super_user or is_user_in_team(request_user, ADMIN_TEAM_ID)

context = {
"data": data,
"super_user": super_user,
"super_user_role_id": SUPER_USER_ROLE_ID,
"can_deactivate": can_deactivate,
"can_edit_role": can_edit_role,
"can_edit_team": can_edit_team,
}
return render(request, "users/profile.html", context)

Expand All @@ -97,13 +104,26 @@ class EditUser(SingleFormView):
def init(self, request, **kwargs):
self.object_pk = kwargs["pk"]
user, _ = get_gov_user(request, self.object_pk)
request_user, _ = get_gov_user(request, str(request.session["lite_api_user_id"]))
self.user = user["user"]
can_edit_role = self.user["id"] != request.session["lite_api_user_id"]
self.form = edit_user_form(request, self.user, can_edit_role)
self.can_edit_role = self.user["id"] != request.session["lite_api_user_id"]
self.can_edit_team = is_super_user(request_user) or is_user_in_team(request_user, ADMIN_TEAM_ID)
self.form = edit_user_form(request, self.user, self.can_edit_role, self.can_edit_team)
self.data = self.user
self.action = put_gov_user
self.success_url = reverse("users:user", kwargs={"pk": self.object_pk})

def clean_data(self, data):
# We have to remove these by hand as lite-forms by default just passes through the full post data instead of
# cleansing the data in the edit form itself.
# We are removing these form fields programatically in the form code but this isn't enough to remove the data
# from this data blob.
if not self.can_edit_team and "team" in data:
del data["team"]
if not self.can_edit_role and "role" in data:
del data["role"]
return data

def post_success_step(self):
super().post_success_step()

Expand Down
1 change: 1 addition & 0 deletions conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
# AWS
VCAP_SERVICES = env.json("VCAP_SERVICES", {})

AWS_S3_ENDPOINT_URL = env.str("AWS_S3_ENDPOINT_URL", None)
AWS_ACCESS_KEY_ID = env.str("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = env.str("AWS_SECRET_ACCESS_KEY")
AWS_REGION = env.str("AWS_REGION")
Expand Down
29 changes: 29 additions & 0 deletions core/accessibility/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from django.views.generic import TemplateView
from django.urls import reverse

from core.auth.views import LoginRequiredMixin


class BaseAccessibilityStatementView(LoginRequiredMixin, TemplateView):
template_name = "accessibility/accessibility.html"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
protocol = "https://" if self.request.is_secure() else "http://"
context["host"] = f"{protocol}{self.request.get_host()}/"
return context


class ExporterAccessibilityStatementView(BaseAccessibilityStatementView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["back_url"] = reverse("core:home")
return context


class CaseworkerAccessibilityStatementView(BaseAccessibilityStatementView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["back_url"] = reverse("core:index")

return context
4 changes: 4 additions & 0 deletions core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ def __init__(self, message, status_code, response, log_message, user_message):
self.response = response
self.log_message = log_message
self.user_message = user_message


class APIError(Exception):
pass
Loading

0 comments on commit 64bd791

Please sign in to comment.