Skip to content

Commit

Permalink
Validate titles without strong
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarvelle committed Oct 23, 2024
1 parent 0117192 commit 3577ac9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ArticleApiProperties extends BaseProps {
ResourceType.H5P.toString -> H5PAddress
)

def InlineHtmlTags: Set[String] = Set("code", "em", "span", "strong", "sub", "sup")
def InlineHtmlTags: Set[String] = Set("code", "em", "span", "sub", "sup")
def IntroductionHtmlTags: Set[String] = InlineHtmlTags ++ Set("br", "p")

private def H5PAddress: String = propOrElse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ import no.ndla.articleapi.repository.ArticleRepository
import no.ndla.common.errors.{ValidationException, ValidationMessage}
import no.ndla.common.model.NDLADate
import no.ndla.common.model.domain.article.{Article, Copyright}
import no.ndla.common.model.domain._
import no.ndla.common.model.domain.*
import no.ndla.language.model.{Iso639, LanguageField}
import no.ndla.mapping.License.getLicense
import no.ndla.validation.HtmlTagRules.{allLegalTags, stringToJsoupDocument}
import no.ndla.validation.SlugValidator.validateSlug
import no.ndla.validation.TextValidator

import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters.*
import scala.util.{Failure, Success, Try}

trait ContentValidator {
this: ArticleRepository with Props =>
this: ArticleRepository & Props =>
val contentValidator: ContentValidator

class ContentValidator() {
class ContentValidator {
private val inlineHtmlTags = props.InlineHtmlTags
private val introductionHtmlTags = props.IntroductionHtmlTags

Expand Down Expand Up @@ -73,7 +73,7 @@ trait ContentValidator {
}
}

private def validateNonEmpty(field: String, values: Seq[LanguageField[_]]): Option[ValidationMessage] = {
private def validateNonEmpty(field: String, values: Seq[LanguageField[?]]): Option[ValidationMessage] = {
if (values.isEmpty || values.forall(_.isEmpty)) {
Some(ValidationMessage(field, "Field must contain at least one entry"))
} else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class V54__RemoveStrongFromTitleTest extends UnitSuite with TestEnvironment {
}

test("That strong are removed from title in article") {
val oldContent = ArticleContent("<section><h2>This is a <strong>title</strong></h2><p>Some text</p></section>", language = "nb")
val oldContent =
ArticleContent("<section><h2>This is a <strong>title</strong></h2><p>Some text</p></section>", language = "nb")
val expectedContent = ArticleContent("<section><h2>This is a title</h2><p>Some text</p></section>", language = "nb")

val migration = new V54__RemoveStrongFromTitle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DraftApiProperties extends BaseProps with StrictLogging {
"image-api" -> s"http://$ImageApiHost/intern"
)

def InlineHtmlTags: Set[String] = Set("code", "em", "span", "strong", "sub", "sup")
def InlineHtmlTags: Set[String] = Set("code", "em", "span", "sub", "sup")
def IntroductionHtmlTags: Set[String] = InlineHtmlTags ++ Set("br", "p")

private def BrightcoveAccountId: String = prop("NDLA_BRIGHTCOVE_ACCOUNT_ID")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ package no.ndla.draftapi.validation

import no.ndla.common.errors.{ValidationException, ValidationMessage}
import no.ndla.common.model.NDLADate
import no.ndla.common.model.domain._
import no.ndla.common.model.domain.draft._
import no.ndla.common.model.domain.*
import no.ndla.common.model.domain.draft.*
import no.ndla.draftapi.Props
import no.ndla.draftapi.integration.ArticleApiClient
import no.ndla.draftapi.model.api.{ContentId, NotFoundException, UpdatedArticle}
Expand All @@ -21,18 +21,18 @@ import no.ndla.mapping.License.getLicense
import no.ndla.network.tapir.auth.TokenUser
import no.ndla.validation.HtmlTagRules.{allLegalTags, stringToJsoupDocument}
import no.ndla.validation.SlugValidator.validateSlug
import no.ndla.validation._
import no.ndla.validation.*
import scalikejdbc.ReadOnlyAutoSession

import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters.*
import scala.util.{Failure, Success, Try}

trait ContentValidator {
this: DraftRepository with ConverterService with ArticleApiClient with Props =>
this: DraftRepository & ConverterService & ArticleApiClient & Props =>
val contentValidator: ContentValidator
val importValidator: ContentValidator

class ContentValidator() {
class ContentValidator {
import props.{BrightcoveVideoScriptUrl, H5PResizerScriptUrl, NRKVideoScriptUrl}
private val inlineHtmlTags = props.InlineHtmlTags
private val introductionHtmlTags = props.IntroductionHtmlTags
Expand Down

0 comments on commit 3577ac9

Please sign in to comment.