Skip to content

Commit

Permalink
Merge pull request #1504 from nationalarchives/FCL-176-pre-commit-audit
Browse files Browse the repository at this point in the history
[FCL-176] Tooling configuration audit
  • Loading branch information
jacksonj04 authored Jul 2, 2024
2 parents e289eca + e438861 commit 93cb9a9
Show file tree
Hide file tree
Showing 28 changed files with 61 additions and 158 deletions.
39 changes: 20 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
exclude: "^docs/|/migrations/"
default_install_hook_types: [pre-commit, pre-push]
exclude: "/migrations/"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
- id: check-case-conflict
- id: check-json
- id: check-merge-conflict
- id: check-xml
- id: check-yaml
- id: end-of-file-fixer
- id: forbid-submodules
- id: mixed-line-ending
- id: no-commit-to-branch
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format

- repo: https://github.com/Riverside-Healthcare/djLint
rev: v1.34.1
Expand All @@ -28,20 +42,7 @@ repos:
language: python

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
rev: v4.0.0-alpha.8
hooks:
- id: prettier
types_or: [scss, yaml, markdown, javascript, xml]

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

# sets up .pre-commit-ci.yaml to ensure pre-commit dependencies stay up to date
ci:
autoupdate_schedule: weekly
skip: []
submodules: false
types_or: [yaml, json, xml, markdown, scss, javascript]
5 changes: 1 addition & 4 deletions auth0/attack-protection/brute-force-protection.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"enabled": true,
"shields": [
"block",
"user_notification"
],
"shields": ["block", "user_notification"],
"mode": "count_per_identifier_and_ip",
"allowlist": [],
"max_attempts": 10
Expand Down
5 changes: 1 addition & 4 deletions auth0/attack-protection/suspicious-ip-throttling.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"enabled": true,
"shields": [
"admin_notification",
"block"
],
"shields": ["admin_notification", "block"],
"allowlist": [],
"stage": {
"pre-login": {
Expand Down
4 changes: 1 addition & 3 deletions auth0/clients/auth0-deploy-cli-extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
},
"token_endpoint_auth_method": "client_secret_post",
"app_type": "non_interactive",
"grant_types": [
"client_credentials"
],
"grant_types": ["client_credentials"],
"custom_login_page_on": true
}
4 changes: 1 addition & 3 deletions auth0/clients/production.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,5 @@
"client_credentials"
],
"custom_login_page_on": true,
"web_origins": [
"https://editor.caselaw.nationalarchives.gov.uk"
]
"web_origins": ["https://editor.caselaw.nationalarchives.gov.uk"]
}
4 changes: 2 additions & 2 deletions auth0/clients/staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"custom_login_page_on": true,
"web_origins": [
"https://editor.staging.caselaw.nationalarchives.gov.uk",
"https://editor.staging.caselaw-stg.dalmatian.dxw.net"
]
"https://editor.staging.caselaw-stg.dalmatian.dxw.net"
]
}
10 changes: 4 additions & 6 deletions auth0/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
"AUTH0_DOMAIN": "tna-caselaw-editorial-team.eu.auth0.com",
"AUTH0_CLIENT_ID": "<client_id>",
"AUTH0_CLIENT_SECRET": "<client_secret>",
"AUTH0_KEYWORD_REPLACE_MAPPINGS": {
},
"AUTH0_KEYWORD_REPLACE_MAPPINGS": {},
"AUTH0_ALLOW_DELETE": false,
"AUTH0_EXCLUDED_RULES": [
],
"AUTH0_EXCLUDED_RULES": [],
"INCLUDED_PROPS": {
"clients": [ ]
"clients": []
},
"EXCLUDED_PROPS": {
"connections": [ "options.client_secret" ]
"connections": ["options.client_secret"]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
"strategy": "auth0",
"name": "Username-Password-Authentication",
"is_domain_connection": false,
"realms": [
"Username-Password-Authentication"
],
"enabled_clients": [
"staging",
"production"
]
"realms": ["Username-Password-Authentication"],
"enabled_clients": ["staging", "production"]
}
4 changes: 1 addition & 3 deletions auth0/tenant.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"friendly_name": "Case Law Editorial Team",
"enabled_locales": [
"en"
],
"enabled_locales": ["en"],
"flags": {
"universal_login": true,
"revoke_refresh_token_grant": false,
Expand Down
3 changes: 1 addition & 2 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@
"disable_existing_loggers": False,
"formatters": {
"verbose": {
"format": "%(levelname)s %(asctime)s %(module)s "
"%(process)d %(thread)d %(message)s",
"format": "%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s",
},
},
"handlers": {
Expand Down
3 changes: 1 addition & 2 deletions config/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@
"filters": {"require_debug_false": {"()": "django.utils.log.RequireDebugFalse"}},
"formatters": {
"verbose": {
"format": "%(levelname)s %(asctime)s %(module)s "
"%(process)d %(thread)d %(message)s",
"format": "%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s",
},
},
"handlers": {
Expand Down
5 changes: 1 addition & 4 deletions ds_caselaw_editor_ui/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
__version__ = "0.1.0"
__version_info__ = tuple(
[
int(num) if num.isdigit() else num
for num in __version__.replace("-", ".", 1).split(".")
],
[int(num) if num.isdigit() else num for num in __version__.replace("-", ".", 1).split(".")],
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
NUMBER_TO_PARSE = 1
MAX_DOCUMENTS_TO_TRY = 200


class Command(BaseCommand):
help = "Sends the next document in the reparse queue to be reparsed"

Expand Down
4 changes: 1 addition & 3 deletions judgments/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ def build(cls, **kwargs) -> DocumentClass:
if "html" in kwargs:
document_mock.return_value.content_as_html.return_value = kwargs.pop("html")
else:
document_mock.return_value.content_as_html.return_value = (
"<p>This is a judgment.</p>"
)
document_mock.return_value.content_as_html.return_value = "<p>This is a judgment.</p>"

for map_to, map_from in cls.PARAMS_MAP.items():
if map_from[0] in kwargs:
Expand Down
15 changes: 3 additions & 12 deletions judgments/tests/test_document_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ def test_document_history_view(self, document_type, document_exists, mock_docume

self.client.force_login(User.objects.get_or_create(username="testuser")[0])

assert (
reverse("document-history", kwargs={"document_uri": document.uri})
== "/edtest/4321/123/history"
)
assert reverse("document-history", kwargs={"document_uri": document.uri}) == "/edtest/4321/123/history"

response = self.client.get(
reverse("document-history", kwargs={"document_uri": document.uri}),
Expand Down Expand Up @@ -405,10 +402,7 @@ def test_structured_history_with_legacy(

self.sign_in_developer_user()

assert (
reverse("document-history", kwargs={"document_uri": document.uri})
== "/test/4321/123/history"
)
assert reverse("document-history", kwargs={"document_uri": document.uri}) == "/test/4321/123/history"

response = self.client.get(
reverse("document-history", kwargs={"document_uri": document.uri}),
Expand Down Expand Up @@ -503,10 +497,7 @@ def test_structured_history(

self.sign_in_developer_user()

assert (
reverse("document-history", kwargs={"document_uri": document.uri})
== "/test/4321/123/history"
)
assert reverse("document-history", kwargs={"document_uri": document.uri}) == "/test/4321/123/history"

response = self.client.get(
reverse("document-history", kwargs={"document_uri": document.uri}),
Expand Down
10 changes: 2 additions & 8 deletions judgments/tests/test_judgments.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ def test_judgment_html_view(self, document_type, document_exists, mock_judgment)

self.client.force_login(User.objects.get_or_create(username="testuser")[0])

assert (
reverse("full-text-html", kwargs={"document_uri": judgment.uri})
== "/hvtest/4321/123"
)
assert reverse("full-text-html", kwargs={"document_uri": judgment.uri}) == "/hvtest/4321/123"

response = self.client.get(
reverse("full-text-html", kwargs={"document_uri": judgment.uri}),
Expand Down Expand Up @@ -118,10 +115,7 @@ def test_judgment_pdf_view_no_pdf_response(
self.client.force_login(User.objects.get_or_create(username="testuser")[0])
response = self.client.get("/test/1234/pdf")
decoded_response = response.content.decode("utf-8")
assert (
"Document &quot;JUDGMENT v JUDGEMENT&quot; does not have a PDF."
in decoded_response
)
assert "Document &quot;JUDGMENT v JUDGEMENT&quot; does not have a PDF." in decoded_response
assert response.status_code == 404

def test_judgment_xml_view_redirect(self):
Expand Down
5 changes: 1 addition & 4 deletions judgments/tests/test_metadata_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,5 @@ def test_metadata_panel(self, document_type, document_exists, mock_judgment):
reverse("full-text-html", kwargs={"document_uri": judgment.uri}),
)

assert (
b'<input type="hidden" name="judgment_uri" value="hvtest/4321/123" />'
in response.content
)
assert b'<input type="hidden" name="judgment_uri" value="hvtest/4321/123" />' in response.content
assert response.status_code == 200
5 changes: 1 addition & 4 deletions judgments/tests/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,4 @@ def test_combined_csv_download(self, mock_api_client):
decoded_response = response.content.decode("utf-8")

assert response.status_code == 200
assert (
decoded_response
== "Column 1,Column 2,Column 3,Column 4\r\nValue 1,Value 2,,7\r\n"
)
assert decoded_response == "Column 1,Column 2,Column 3,Column 4\r\nValue 1,Value 2,,7\r\n"
4 changes: 1 addition & 3 deletions judgments/tests/test_unlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ def test_break_lock_confirm_page():

response = client.get("/unlock?judgment_uri=my_uri")
decoded_response = response.content.decode("utf-8")
assert (
'<input type="hidden" name="judgment_uri" value="my_uri" />' in decoded_response
)
assert '<input type="hidden" name="judgment_uri" value="my_uri" />' in decoded_response
assert response.status_code == 200


Expand Down
5 changes: 1 addition & 4 deletions judgments/tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,7 @@ def test_when_referrer_is_relative(self, request):
def test_when_referrer_is_absolute_and_local(self, request):
request.META = {"HTTP_REFERER": "https://www.example.com/foo/bar"}
request.get_host.return_value = "www.example.com"
assert (
ensure_local_referer_url(request, "/default")
== "https://www.example.com/foo/bar"
)
assert ensure_local_referer_url(request, "/default") == "https://www.example.com/foo/bar"

@patch("django.http.request.HttpRequest")
def test_when_referrer_is_absolute_and_remote(self, request):
Expand Down
10 changes: 2 additions & 8 deletions judgments/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ def update_document_uri(old_uri, new_citation):
copy_assets(old_uri, new_uri)
api_client.set_judgment_this_uri(new_uri)
except MarklogicAPIError as e:
msg = (
f"Failure when attempting to copy document from {old_uri} to {new_uri}: {e}"
)
msg = f"Failure when attempting to copy document from {old_uri} to {new_uri}: {e}"
raise MoveJudgmentError(
msg,
) from e
Expand Down Expand Up @@ -178,11 +176,7 @@ def editors_dict():

def get_linked_document_uri(document: Document) -> str | None:
related_uri = _build_related_document_uri(document)
return (
related_uri
if api_client.document_exists(DocumentURIString(related_uri))
else None
)
return related_uri if api_client.document_exists(DocumentURIString(related_uri)) else None


def _build_related_document_uri(document: Document) -> str:
Expand Down
4 changes: 1 addition & 3 deletions judgments/utils/link_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ def build_confirmation_email_link(
document: Document,
signature: str | None = None,
) -> str:
subject_string = (
f"Notification of publication [TDR ref: {document.consignment_reference}]"
)
subject_string = f"Notification of publication [TDR ref: {document.consignment_reference}]"

email_context = {
"judgment_name": document.name,
Expand Down
4 changes: 1 addition & 3 deletions judgments/utils/view_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def get_search_parameters(
):
query = params.get("query")
page = int(params.get("page", default_page))
order = (
params.get("order") if params.get("order") in ALLOWED_ORDERS else default_order
)
order = params.get("order") if params.get("order") in ALLOWED_ORDERS else default_order
return {
"query": query,
"page": page,
Expand Down
6 changes: 1 addition & 5 deletions judgments/views/judgment_hold.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["email_issue_link"] = build_raise_issue_email_link(
document=context["document"],
signature=(
self.request.user.get_full_name()
if self.request.user.is_authenticated
else None
),
signature=(self.request.user.get_full_name() if self.request.user.is_authenticated else None),
)
return context

Expand Down
6 changes: 1 addition & 5 deletions judgments/views/judgment_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ def get_context_data(self, **kwargs):

context["email_confirmation_link"] = build_confirmation_email_link(
document=context["document"],
signature=(
self.request.user.get_full_name()
if self.request.user.is_authenticated
else None
),
signature=(self.request.user.get_full_name() if self.request.user.is_authenticated else None),
)

return context
Expand Down
12 changes: 3 additions & 9 deletions judgments/views/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ def get_context_data(self, **kwargs):
target_parser_version = api_client.get_highest_parser_version()

context["page_title"] = "Documents awaiting parsing"
context["target_parser_version"] = (
f"{target_parser_version[0]}.{target_parser_version[1]}"
)
context["target_parser_version"] = f"{target_parser_version[0]}.{target_parser_version[1]}"

context["documents"] = get_rows_from_result(
api_client.get_pending_parse_for_version(
Expand All @@ -60,12 +58,8 @@ def get_context_data(self, **kwargs):
target_parser_version = api_client.get_highest_parser_version()

context["page_title"] = "Documents awaiting enrichment"
context["target_enrichment_version"] = (
f"{target_enrichment_version[0]}.{target_enrichment_version[1]}"
)
context["target_parser_version"] = (
f"{target_parser_version[0]}.{target_parser_version[1]}"
)
context["target_enrichment_version"] = f"{target_enrichment_version[0]}.{target_enrichment_version[1]}"
context["target_parser_version"] = f"{target_parser_version[0]}.{target_parser_version[1]}"

context["documents"] = get_rows_from_result(
api_client.get_pending_enrichment_for_version(
Expand Down
Loading

0 comments on commit 93cb9a9

Please sign in to comment.