Skip to content

Commit

Permalink
Merge branch 'develop' into feature/global-header-and-footer
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbiggs committed Apr 11, 2024
2 parents a0763c2 + 8439f3a commit c122044
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 22 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/remove-untagged.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Remove untagged container images

on:
workflow_dispatch:
# schedule:
# - cron: "0 3 * * 1"

jobs:
remove-untagged:
runs-on: ubuntu-latest
env:
PER_PAGE: 100
steps:
- name: Delete untagged images
uses: actions/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const response = await github.request("GET /orgs/${{ github.repository_owner }}/packages/container/${{ vars.DOCKER_IMAGE_NAME }}/versions",
{ per_page: ${{ env.PER_PAGE }}
});
for(version of response.data) {
if (version.metadata.container.tags.length == 0 && version.name !== "latest" && version.name !== "preview") {
console.log("Delete " + version.id)
// const deleteResponse = await github.request("DELETE /orgs/${{ github.repository_owner }}/packages/container/${{ vars.DOCKER_IMAGE_NAME }}/versions/" + version.id, { });
// console.log("status " + deleteResponse.status)
}
}
2 changes: 1 addition & 1 deletion .platform/services.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
db:
type: postgresql:12
disk: 256
disk: 512

redis:
type: redis:6.0
4 changes: 4 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@
"WAGTAILADMIN_BASE_URL", "https://nationalarchives.gov.uk"
)

CSRF_TRUSTED_ORIGINS = [
os.getenv("CSRF_TRUSTED_ORIGIN", "https://nationalarchives.gov.uk")
]

# For search results within Wagtail itself
WAGTAILSEARCH_BACKENDS = {
"default": {
Expand Down
13 changes: 7 additions & 6 deletions etna/articles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class Meta:
index.SearchField("article_tag_names", boost=2),
]

api_fields = [APIField("article_tag_names")]
api_fields = [APIField("tags")]


class ArticleIndexPage(BasePageWithIntro):
Expand Down Expand Up @@ -264,13 +264,13 @@ class Meta:
]
)

verbose_name_public = Meta.verbose_name_public
api_fields = (
BasePageWithIntro.api_fields
+ RequiredHeroImageMixin.api_fields
+ ContentWarningMixin.api_fields
+ NewLabelMixin.api_fields
+ ArticleTagMixin.api_fields
+ [
APIField("verbose_name_public"),
APIField("similar_items", serializer=PageSerializer(many=True)),
APIField("latest_items", serializer=PageSerializer(many=True)),
APIField("body"),
Expand Down Expand Up @@ -423,9 +423,10 @@ class Meta:
)
api_fields = (
BasePageWithIntro.api_fields
+ ArticleTagMixin.api_fields
+ HeroImageMixin.api_fields
+ ContentWarningMixin.api_fields
+ NewLabelMixin.api_fields
+ ArticleTagMixin.api_fields
+ [
APIField("type_label"),
APIField("body"),
Expand Down Expand Up @@ -667,9 +668,9 @@ class Meta:

api_fields = (
BasePageWithIntro.api_fields
+ ArticleTagMixin.api_fields
+ NewLabelMixin.api_fields
+ ContentWarningMixin.api_fields
+ NewLabelMixin.api_fields
+ ArticleTagMixin.api_fields
+ [
APIField("type_label"),
APIField("date_text"),
Expand Down
43 changes: 43 additions & 0 deletions etna/ciim/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
find_all,
format_description_markup,
pluck,
strip_html,
)


Expand Down Expand Up @@ -370,3 +371,45 @@ def test_index_is_zero_for_non_int_sort_key(self):
index = convert_sort_key_to_index(sort)

self.assertEqual(index, 0)


class TestStripHtml(SimpleTestCase):

def test_ensure_spaces_preserve_marks(self):

test_data = (
(
"test for span tag",
"This is a<span>test example</span>",
"This is a test example",
),
(
"test for p tag",
"This is a<p>test example</p>",
"This is a test example",
),
(
"test for unknown tag",
"This is a<unknown>test example</unknown>",
"This is atest example",
),
(
"D7376859",
'<span class="wrapper"><span altrender="doctype" class="emph"></span><span class="persname"><span altrender="surname" class="emph">Patman</span><span altrender="forenames" class="emph">Clifford Douglas</span></span><span altrender="rank" class="emph">Armament Quarter Master Serjeant</span><span altrender="regno" class="emph">1865334</span><span class="corpname">Royal Army Ordnance Corps, 8 Hussars now Royal Electrical and Mechanical Engineers</span><span class="geogname">Escape and Evasion</span><span altrender="award" class="emph">Mentions in Despatches</span></span>',
"Patman Clifford Douglas Armament Quarter Master Serjeant 1865334 Royal Army Ordnance Corps, 8 Hussars now Royal Electrical and Mechanical Engineers Escape and Evasion Mentions in Despatches",
),
)

for label, value, expected in test_data:
with self.subTest(label):
result = strip_html(value, preserve_marks=True, ensure_spaces=True)
self.assertEqual(result, expected)

def test_allow_tags(self):
value = """<a href="http://test.com">this is a test</a>"""
expected = (
"""<a href="http://test.com" rel="noopener noreferrer">this is a test</a>"""
)
allow_tags = {"a", "br", "p"}
result = strip_html(value, allow_tags=allow_tags)
self.assertEqual(result, expected)
39 changes: 29 additions & 10 deletions etna/ciim/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,20 +257,39 @@ def format_link(link_html: str) -> Dict[str, str]:
return {"href": href, "id": id, "text": document.text()}


def strip_html(value: str, *, preserve_marks, ensure_spaces):
def strip_html(
value: str,
*,
preserve_marks: bool = False,
ensure_spaces: bool = False,
allow_tags: Optional[set] = None,
) -> str:
"""
Temporary HTML sanitiser to remove unwanted tags from data.
K-int will eventually sanitise this at API level.
preserve_marks=True will keep <mark> tags in the output, otherwise they are removed.
Replacing <span> and <p> tags is necessary to prevent "bunched" data,
"This is a<span>test</span>example" will return as "This is atestexample"
without the placement of the space.
TODO:this will eventually be sanitised at API level.
value:
the value to be sanitised
preserver_marks:
allow pre-defined tags for styling
ensure_spaces:
allow pre-defined tags and replaces them with whitespace
allow_tags:
sets the tags that are allowed
"""
clean_tags = {"span", "p"} if ensure_spaces else set()
clean_html = nh3.clean(
value, tags={*clean_tags, "mark"} if preserve_marks else clean_tags
)

if allow_tags is None:
allow_tags = set()

tags = set()
if preserve_marks:
tags.add("mark")
tags.update(clean_tags)
tags.update(allow_tags)

clean_html = nh3.clean(value, tags=tags)

for tag in clean_tags:
opening_regex = rf"<{tag}[^>]*>"
closing_regex = rf"</{tag}>"
Expand Down
4 changes: 2 additions & 2 deletions etna/collections/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,8 @@ class HighlightGalleryPage(TopicalPageMixin, ContentWarningMixin, BasePageWithIn
)

api_fields = (
ContentWarningMixin.api_fields
+ BasePageWithIntro.api_fields
BasePageWithIntro.api_fields
+ ContentWarningMixin.api_fields
+ [
APIField("featured_record_article"),
APIField("featured_article"),
Expand Down
1 change: 1 addition & 0 deletions etna/core/models/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ContentWarningMixin(models.Model):
)

api_fields = [
APIField("display_content_warning"),
APIField("custom_warning_text", serializer=RichTextSerializer()),
]

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "Etna"
version = "24.03.19.29"
version = "24.04.03.31"
description = ""
authors = ["James Biggs <[email protected]>"]

Expand Down
4 changes: 2 additions & 2 deletions templates/includes/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</div>
</div>

<footer class="tna-footer">
<div class="tna-container">
<footer class="tna-footer tna-!--margin-top-xl">
<div class="tna-container">
<div class="tna-column tna-column--flex-1 tna-column--width-1-2-medium tna-column--full-small tna-column--full-tiny tna-column--order-1">
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" class="tna-logo" viewBox="0 0 160 160" width="96" height="96">
<title>The National Archives</title>
Expand Down

0 comments on commit c122044

Please sign in to comment.