From 1a2073a442b5b9fa856f7fea9c1ae0002f7f3bed Mon Sep 17 00:00:00 2001 From: Katrine Wist Date: Mon, 16 Dec 2024 15:24:36 +0100 Subject: [PATCH] Remove article-id from uu disclaimer. Add migrations to remove article-id from uu disclaimer embed --- ...V55__RemoveArticleIdFromUUDisclaimer.scala | 28 +++++++++++++++++++ ..._RemoveArticleIdFromUUDisclaimerTest.scala | 22 +++++++++++++++ ...V66__RemoveArticleIdFromUUDisclaimer.scala | 28 +++++++++++++++++++ ..._RemoveArticleIdFromUUDisclaimerTest.scala | 22 +++++++++++++++ .../src/main/resources/embed-tag-rules.json | 7 ----- .../validation/EmbedTagValidatorTest.scala | 6 ++-- 6 files changed, 102 insertions(+), 11 deletions(-) create mode 100644 article-api/src/main/scala/no/ndla/articleapi/db/migration/V55__RemoveArticleIdFromUUDisclaimer.scala create mode 100644 article-api/src/test/scala/no/ndla/articleapi/db/migration/V55__RemoveArticleIdFromUUDisclaimerTest.scala create mode 100644 draft-api/src/main/scala/no/ndla/draftapi/db/migration/V66__RemoveArticleIdFromUUDisclaimer.scala create mode 100644 draft-api/src/test/scala/no/ndla/draftapi/db/migration/V66__RemoveArticleIdFromUUDisclaimerTest.scala diff --git a/article-api/src/main/scala/no/ndla/articleapi/db/migration/V55__RemoveArticleIdFromUUDisclaimer.scala b/article-api/src/main/scala/no/ndla/articleapi/db/migration/V55__RemoveArticleIdFromUUDisclaimer.scala new file mode 100644 index 000000000..622f91e25 --- /dev/null +++ b/article-api/src/main/scala/no/ndla/articleapi/db/migration/V55__RemoveArticleIdFromUUDisclaimer.scala @@ -0,0 +1,28 @@ +/* + * Part of NDLA article-api + * Copyright (C) 2024 NDLA + * + * See LICENSE + */ + +package no.ndla.articleapi.db.migration + +import no.ndla.articleapi.db.HtmlMigration +import org.jsoup.nodes.Element + +class V55__RemoveArticleIdFromUUDisclaimer extends HtmlMigration { + override val convertVisualElement: Boolean = true + override def convertHtml(doc: Element, language: String): Element = { + doc + .select("ndlaembed[data-resource='uu-disclaimer']") + .forEach(embed => { + val hasArticleId = embed.hasAttr("data-article-id") + if (hasArticleId) { + embed.removeAttr( + "data-article-id" + ): Unit + } + }) + doc + } +} diff --git a/article-api/src/test/scala/no/ndla/articleapi/db/migration/V55__RemoveArticleIdFromUUDisclaimerTest.scala b/article-api/src/test/scala/no/ndla/articleapi/db/migration/V55__RemoveArticleIdFromUUDisclaimerTest.scala new file mode 100644 index 000000000..bcb631a0c --- /dev/null +++ b/article-api/src/test/scala/no/ndla/articleapi/db/migration/V55__RemoveArticleIdFromUUDisclaimerTest.scala @@ -0,0 +1,22 @@ +/* + * Part of NDLA article-api + * Copyright (C) 2024 NDLA + * + * See LICENSE + */ + +package no.ndla.articleapi.db.migration + +import no.ndla.articleapi.{TestEnvironment, UnitSuite} + +class V55__RemoveArticleIdFromUUDisclaimerTest extends UnitSuite with TestEnvironment { + test("That article-id is removed from uu-disclaimer") { + val migration = new V55__RemoveArticleIdFromUUDisclaimer + val oldArticle = + """

Hallo!

""" + val newArticle = + """

Hallo!

""" + + migration.convertContent(oldArticle, "nb") should be(newArticle) + } +} diff --git a/draft-api/src/main/scala/no/ndla/draftapi/db/migration/V66__RemoveArticleIdFromUUDisclaimer.scala b/draft-api/src/main/scala/no/ndla/draftapi/db/migration/V66__RemoveArticleIdFromUUDisclaimer.scala new file mode 100644 index 000000000..2e2ae712d --- /dev/null +++ b/draft-api/src/main/scala/no/ndla/draftapi/db/migration/V66__RemoveArticleIdFromUUDisclaimer.scala @@ -0,0 +1,28 @@ +/* + * Part of NDLA draft-api + * Copyright (C) 2024 NDLA + * + * See LICENSE + */ + +package no.ndla.draftapi.db.migration + +import no.ndla.draftapi.db.HtmlMigration +import org.jsoup.nodes.Element + +class V66__RemoveArticleIdFromUUDisclaimer extends HtmlMigration { + override val convertVisualElement: Boolean = true + override def convertHtml(doc: Element, language: String): Element = { + doc + .select("ndlaembed[data-resource='uu-disclaimer']") + .forEach(embed => { + val hasArticleId = embed.hasAttr("data-article-id") + if (hasArticleId) { + embed.removeAttr( + "data-article-id" + ): Unit + } + }) + doc + } +} diff --git a/draft-api/src/test/scala/no/ndla/draftapi/db/migration/V66__RemoveArticleIdFromUUDisclaimerTest.scala b/draft-api/src/test/scala/no/ndla/draftapi/db/migration/V66__RemoveArticleIdFromUUDisclaimerTest.scala new file mode 100644 index 000000000..dbfc7e743 --- /dev/null +++ b/draft-api/src/test/scala/no/ndla/draftapi/db/migration/V66__RemoveArticleIdFromUUDisclaimerTest.scala @@ -0,0 +1,22 @@ +/* + * Part of NDLA draft-api + * Copyright (C) 2024 NDLA + * + * See LICENSE + */ + +package no.ndla.draftapi.db.migration + +import no.ndla.draftapi.{TestEnvironment, UnitSuite} + +class V66__RemoveArticleIdFromUUDisclaimerTest extends UnitSuite with TestEnvironment { + test("That article-id is removed from uu-disclaimer") { + val migration = new V66__RemoveArticleIdFromUUDisclaimer + val oldArticle = + """

Hallo!

""" + val newArticle = + """

Hallo!

""" + + migration.convertContent(oldArticle, "nb") should be(newArticle) + } +} diff --git a/validation/src/main/resources/embed-tag-rules.json b/validation/src/main/resources/embed-tag-rules.json index d820f42a1..fbe6f1c89 100644 --- a/validation/src/main/resources/embed-tag-rules.json +++ b/validation/src/main/resources/embed-tag-rules.json @@ -62,13 +62,6 @@ "validation": { "required": true } - }, - { - "name": "data-article-id", - "validation": { - "required": false, - "dataType": "NUMBER" - } } ], "children": { diff --git a/validation/src/test/scala/no/ndla/validation/EmbedTagValidatorTest.scala b/validation/src/test/scala/no/ndla/validation/EmbedTagValidatorTest.scala index e7351cd5d..218a8f53e 100644 --- a/validation/src/test/scala/no/ndla/validation/EmbedTagValidatorTest.scala +++ b/validation/src/test/scala/no/ndla/validation/EmbedTagValidatorTest.scala @@ -248,8 +248,7 @@ class EmbedTagValidatorTest extends UnitSuite { val tag = generateTagWithAttrsAndChildren( Map( TagAttribute.DataResource -> ResourceType.UuDisclaimer.toString, - TagAttribute.DataDisclaimer -> "Dette er en disclaimer", - TagAttribute.DataArticleId -> "123" + TagAttribute.DataDisclaimer -> "Dette er en disclaimer" ), generateTagWithAttrs( Map( @@ -270,8 +269,7 @@ class EmbedTagValidatorTest extends UnitSuite { val tag = generateTagWithAttrsAndChildren( Map( TagAttribute.DataResource -> ResourceType.UuDisclaimer.toString, - TagAttribute.DataDisclaimer -> "Dette er en disclaimer", - TagAttribute.DataArticleId -> "123" + TagAttribute.DataDisclaimer -> "Dette er en disclaimer" ), """ |

Her er en disclaimer