-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove article-id from uu disclaimer. Add migrations to remove articl…
…e-id from uu disclaimer embed
- Loading branch information
Showing
6 changed files
with
102 additions
and
11 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
...src/main/scala/no/ndla/articleapi/db/migration/V55__RemoveArticleIdFromUUDisclaimer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...test/scala/no/ndla/articleapi/db/migration/V55__RemoveArticleIdFromUUDisclaimerTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...i/src/main/scala/no/ndla/draftapi/db/migration/V66__RemoveArticleIdFromUUDisclaimer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...c/test/scala/no/ndla/draftapi/db/migration/V66__RemoveArticleIdFromUUDisclaimerTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters