Skip to content

Commit

Permalink
Remove article-id from uu disclaimer. Add migrations to remove articl…
Browse files Browse the repository at this point in the history
…e-id from uu disclaimer embed
  • Loading branch information
katrinewi committed Dec 16, 2024
1 parent 47ef162 commit 1a2073a
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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 =
"""<section><ndlaembed data-resource="uu-disclaimer" data-disclaimer="Dette innholdet er ikke universelt utformet, og noen brukere kan derfor ha problemer med å oppfatte og forstå det." data-article-id="38293"><p>Hallo!</p></ndlaembed></section>"""
val newArticle =
"""<section><ndlaembed data-resource="uu-disclaimer" data-disclaimer="Dette innholdet er ikke universelt utformet, og noen brukere kan derfor ha problemer med å oppfatte og forstå det."><p>Hallo!</p></ndlaembed></section>"""

migration.convertContent(oldArticle, "nb") should be(newArticle)
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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 =
"""<section><ndlaembed data-resource="uu-disclaimer" data-disclaimer="Dette innholdet er ikke universelt utformet, og noen brukere kan derfor ha problemer med å oppfatte og forstå det." data-article-id="38293"><p>Hallo!</p></ndlaembed></section>"""
val newArticle =
"""<section><ndlaembed data-resource="uu-disclaimer" data-disclaimer="Dette innholdet er ikke universelt utformet, og noen brukere kan derfor ha problemer med å oppfatte og forstå det."><p>Hallo!</p></ndlaembed></section>"""

migration.convertContent(oldArticle, "nb") should be(newArticle)
}
}
7 changes: 0 additions & 7 deletions validation/src/main/resources/embed-tag-rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@
"validation": {
"required": true
}
},
{
"name": "data-article-id",
"validation": {
"required": false,
"dataType": "NUMBER"
}
}
],
"children": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"
),
"""
|<p>Her er en disclaimer</p>
Expand Down

0 comments on commit 1a2073a

Please sign in to comment.