Skip to content

Commit

Permalink
Merge pull request #582 from NDLANO/4272-republish-for-all
Browse files Browse the repository at this point in the history
draft-api: Allow republishing articles without publishing rights
  • Loading branch information
gunnarvelle authored Jan 22, 2025
2 parents d9ff8f0 + 3d7e3ba commit 4d993b2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,54 +139,54 @@ trait StateTransitionRules {
(IN_PROGRESS -> INTERNAL_REVIEW) keepCurrentOnTransition,
(IN_PROGRESS -> QUALITY_ASSURANCE) .require(PublishRoles, articleHasBeenPublished) keepStates Set(PUBLISHED),
(IN_PROGRESS -> LANGUAGE) .require(PublishRoles, articleHasBeenPublished) keepStates Set(PUBLISHED),
(IN_PROGRESS -> PUBLISHED) require DirectPublishRoles withSideEffect publishWithSoftValidation withSideEffect resetResponsible,
(IN_PROGRESS -> PUBLISHED) .require(DirectPublishRoles, articleHasBeenPublished) withSideEffect publishWithSoftValidation withSideEffect resetResponsible,
(IN_PROGRESS -> ARCHIVED) .require(PublishRoles, articleHasNotBeenPublished) withIllegalStatuses Set(PUBLISHED) withSideEffect resetResponsible,
(IN_PROGRESS -> REPUBLISH) .require(PublishRoles, articleHasBeenPublished) keepStates Set(PUBLISHED) requireStatusesForTransition Set(PUBLISHED),
EXTERNAL_REVIEW -> IN_PROGRESS keepStates Set(PUBLISHED),
(EXTERNAL_REVIEW -> EXTERNAL_REVIEW) keepStates Set(IN_PROGRESS, PUBLISHED),
(EXTERNAL_REVIEW -> INTERNAL_REVIEW) keepStates Set(PUBLISHED) keepCurrentOnTransition,
(EXTERNAL_REVIEW -> PUBLISHED) require DirectPublishRoles withSideEffect publishWithSoftValidation withSideEffect resetResponsible,
(EXTERNAL_REVIEW -> PUBLISHED) .require(DirectPublishRoles, articleHasBeenPublished) withSideEffect publishWithSoftValidation withSideEffect resetResponsible,
(EXTERNAL_REVIEW -> ARCHIVED) .require(PublishRoles, articleHasNotBeenPublished) withIllegalStatuses Set(PUBLISHED) withSideEffect resetResponsible,
INTERNAL_REVIEW -> IN_PROGRESS,
(INTERNAL_REVIEW -> EXTERNAL_REVIEW) keepStates Set(INTERNAL_REVIEW, PUBLISHED),
INTERNAL_REVIEW -> INTERNAL_REVIEW,
(INTERNAL_REVIEW -> QUALITY_ASSURANCE) keepCurrentOnTransition,
(INTERNAL_REVIEW -> PUBLISHED) require DirectPublishRoles withSideEffect publishWithSoftValidation withSideEffect resetResponsible,
(INTERNAL_REVIEW -> PUBLISHED) .require(DirectPublishRoles, articleHasBeenPublished) withSideEffect publishWithSoftValidation withSideEffect resetResponsible,
(INTERNAL_REVIEW -> ARCHIVED) .require(PublishRoles, articleHasNotBeenPublished) withIllegalStatuses Set(PUBLISHED) withSideEffect resetResponsible,
(QUALITY_ASSURANCE -> IN_PROGRESS) keepStates Set(PUBLISHED),
(QUALITY_ASSURANCE -> INTERNAL_REVIEW) keepStates Set(PUBLISHED),
QUALITY_ASSURANCE -> QUALITY_ASSURANCE,
(QUALITY_ASSURANCE -> LANGUAGE) keepStates Set(PUBLISHED) require DirectPublishRoles,
(QUALITY_ASSURANCE -> ARCHIVED) .require(PublishRoles, articleHasNotBeenPublished) withIllegalStatuses Set(PUBLISHED) withSideEffect resetResponsible,
(QUALITY_ASSURANCE -> PUBLISHED) require PublishRoles withSideEffect publishArticle withSideEffect resetResponsible,
(QUALITY_ASSURANCE -> PUBLISHED) .require(PublishRoles, articleHasBeenPublished) withSideEffect publishArticle withSideEffect resetResponsible,
LANGUAGE -> IN_PROGRESS,
(LANGUAGE -> QUALITY_ASSURANCE) keepCurrentOnTransition,
LANGUAGE -> LANGUAGE,
(LANGUAGE -> FOR_APPROVAL) keepStates Set(PUBLISHED) require DirectPublishRoles,
(LANGUAGE -> PUBLISHED) require PublishRoles withSideEffect publishArticle withSideEffect resetResponsible,
(LANGUAGE -> PUBLISHED) .require(PublishRoles, articleHasBeenPublished) withSideEffect publishArticle withSideEffect resetResponsible,
(LANGUAGE -> ARCHIVED) .require(PublishRoles, articleHasNotBeenPublished) withIllegalStatuses Set(PUBLISHED) withSideEffect resetResponsible,
(FOR_APPROVAL -> IN_PROGRESS) keepStates Set(PUBLISHED),
(FOR_APPROVAL -> LANGUAGE) keepStates Set(PUBLISHED),
FOR_APPROVAL -> FOR_APPROVAL,
(FOR_APPROVAL -> END_CONTROL) keepStates Set(PUBLISHED) withSideEffect validateArticleApiArticle,
(FOR_APPROVAL -> PUBLISHED) require PublishRoles withSideEffect publishArticle withSideEffect resetResponsible,
(FOR_APPROVAL -> PUBLISHED) .require(PublishRoles, articleHasBeenPublished) withSideEffect publishArticle withSideEffect resetResponsible,
(FOR_APPROVAL -> ARCHIVED) .require(PublishRoles, articleHasNotBeenPublished) withIllegalStatuses Set(PUBLISHED) withSideEffect resetResponsible,
(END_CONTROL -> IN_PROGRESS) keepStates Set(PUBLISHED),
(END_CONTROL -> FOR_APPROVAL) keepStates Set(PUBLISHED),
(END_CONTROL -> END_CONTROL) withSideEffect validateArticleApiArticle,
(END_CONTROL -> PUBLISH_DELAYED) require DirectPublishRoles withSideEffect validateArticleApiArticle,
(END_CONTROL -> PUBLISHED) require DirectPublishRoles withSideEffect publishArticle withSideEffect resetResponsible,
(END_CONTROL -> PUBLISHED) .require(DirectPublishRoles, articleHasBeenPublished) withSideEffect publishArticle withSideEffect resetResponsible,
(END_CONTROL -> ARCHIVED) .require(PublishRoles, articleHasNotBeenPublished) withIllegalStatuses Set(PUBLISHED) withSideEffect resetResponsible,
(PUBLISH_DELAYED -> END_CONTROL) keepStates Set(PUBLISHED) withSideEffect validateArticleApiArticle,
PUBLISH_DELAYED -> PUBLISH_DELAYED,
(PUBLISH_DELAYED -> PUBLISHED) require DirectPublishRoles withSideEffect publishArticle withSideEffect resetResponsible,
(PUBLISH_DELAYED -> PUBLISHED) .require(DirectPublishRoles, articleHasBeenPublished) withSideEffect publishArticle withSideEffect resetResponsible,
(PUBLISH_DELAYED -> ARCHIVED) .require(PublishRoles, articleHasNotBeenPublished) withIllegalStatuses Set(PUBLISHED) withSideEffect resetResponsible,
(PUBLISHED -> IN_PROGRESS) keepStates Set(PUBLISHED) withSideEffect addResponsible keepCurrentOnTransition,
(PUBLISHED -> UNPUBLISHED) keepStates Set.empty require DirectPublishRoles withSideEffect unpublishArticle withSideEffect resetResponsible,
(PUBLISHED -> ARCHIVED) .require(PublishRoles, articleHasNotBeenPublished) withIllegalStatuses Set(PUBLISHED) withSideEffect unpublishArticle withSideEffect resetResponsible,
REPUBLISH -> REPUBLISH,
REPUBLISH -> IN_PROGRESS keepStates Set(PUBLISHED),
(REPUBLISH -> PUBLISHED) require PublishRoles withSideEffect publishArticle withSideEffect resetResponsible,
(REPUBLISH -> PUBLISHED) .require(PublishRoles, articleHasBeenPublished) withSideEffect publishArticle withSideEffect resetResponsible,
UNPUBLISHED -> UNPUBLISHED withSideEffect resetResponsible,
(UNPUBLISHED -> PUBLISHED) require DirectPublishRoles withSideEffect publishWithSoftValidation withSideEffect resetResponsible,
UNPUBLISHED -> IN_PROGRESS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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.draft.DraftStatus.ARCHIVED
import no.ndla.common.model.domain.language.OptLanguageFields
import no.ndla.draftapi.Props
import no.ndla.draftapi.integration.ArticleApiClient
Expand Down Expand Up @@ -98,7 +99,7 @@ trait ContentValidator {
else Seq.empty

val editorialValidationErrors =
validateRevisionMeta(article.revisionMeta)
validateRevisionMeta(article.revisionMeta, article.status)

val validationErrors = regularValidationErrors ++ editorialValidationErrors

Expand Down Expand Up @@ -202,7 +203,8 @@ trait ContentValidator {
.toList ++ validateLanguage("language", content.language)
}

private def validateRevisionMeta(revisionMeta: Seq[RevisionMeta]): Seq[ValidationMessage] = {
private def validateRevisionMeta(revisionMeta: Seq[RevisionMeta], newStatus: Status): Seq[ValidationMessage] = {
if (newStatus.current == ARCHIVED) return Seq.empty
revisionMeta.find(rm =>
rm.status == RevisionStatus.NeedsRevision && rm.revisionDate.isAfter(NDLADate.now())
) match {
Expand All @@ -211,7 +213,7 @@ trait ContentValidator {
Seq(
ValidationMessage(
"revisionMeta",
"An article must contain at least one planned revisiondate"
"An article must contain at least one planned revision date"
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class ContentValidatorTest extends UnitSuite with TestEnvironment {

res.errors.length should be(1)
res.errors.head.field should be("revisionMeta")
res.errors.head.message should be("An article must contain at least one planned revisiondate")
res.errors.head.message should be("An article must contain at least one planned revision date")
}

test("validation should fail if slug field is present but articleType is not frontpage-article") {
Expand Down Expand Up @@ -449,6 +449,6 @@ class ContentValidatorTest extends UnitSuite with TestEnvironment {
result.isFailure should be(true)
val Failure(validationError: ValidationException) = result
validationError.errors.length should be(1)
validationError.errors.head.message should be("An article must contain at least one planned revisiondate")
validationError.errors.head.message should be("An article must contain at least one planned revision date")
}
}

0 comments on commit 4d993b2

Please sign in to comment.