Skip to content

Commit

Permalink
learningpath-api: Adds madeAvailable field to learningpaths
Browse files Browse the repository at this point in the history
This field updates whenever a learningpath's status has been set to
UNLISTED or PUBLISHED.
  • Loading branch information
jnatten committed Nov 25, 2024
1 parent 000ebd9 commit ed9bfd6
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ case class LearningPath(
owner: String,
copyright: LearningpathCopyright,
learningsteps: Option[Seq[LearningStep]] = None,
message: Option[Message] = None
message: Option[Message] = None,
madeAvailable: Option[NDLADate] = None
) extends Content {

def supportedLanguages: Seq[String] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ case class LearningPathV2(
@description("True if authenticated user may edit this learningpath") canEdit: Boolean,
@description("The supported languages for this learningpath") supportedLanguages: Seq[String],
@description("Visible if administrator or owner of LearningPath") ownerId: Option[String],
@description("Message set by administrator. Visible if administrator or owner of LearningPath") message: Option[Message]
@description("Message set by administrator. Visible if administrator or owner of LearningPath") message: Option[Message],
@description("The date when this learningpath was made available to the public.") madeAvailable: Option[NDLADate]
)

object LearningPathV2 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ trait ConverterService {
lp.canEdit(userInfo),
supportedLanguages,
owner,
message
message,
lp.madeAvailable
)
)
} else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,22 @@ trait UpdateService {
case _ => valid.message
}

val updatedLearningPath = learningPathRepository.update(
valid.copy(message = newMessage, status = status, lastUpdated = clock.now())
val madeAvailable = valid.madeAvailable.orElse {
status match {
case LearningPathStatus.PUBLISHED | LearningPathStatus.UNLISTED => Some(clock.now())
case _ => None
}
}

val toUpdateWith = valid.copy(
message = newMessage,
status = status,
lastUpdated = clock.now(),
madeAvailable = madeAvailable
)

val updatedLearningPath = learningPathRepository.update(toUpdateWith)

updateSearchAndTaxonomy(updatedLearningPath, owner.tokenUser)
.flatMap(_ =>
converterService.asApiLearningpathV2(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class ConverterServiceTest extends UnitSuite with UnitTestEnvironment {
true,
List("nb"),
None,
None,
None
)
val domainLearningStep: LearningStep =
Expand Down Expand Up @@ -137,6 +138,7 @@ class ConverterServiceTest extends UnitSuite with UnitTestEnvironment {
canEdit = true,
List("nb", "en"),
None,
None,
None
)
)
Expand Down Expand Up @@ -188,6 +190,7 @@ class ConverterServiceTest extends UnitSuite with UnitTestEnvironment {
true,
List("nb", "en"),
None,
None,
None
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,26 @@ class UpdateServiceTest extends UnitSuite with UnitTestEnvironment {
verify(searchIndexService, times(1)).indexDocument(any[LearningPath])
}

test("That updateLearningPathStatusV2 updates madeAvailable when going to UNLISTED") {
when(learningPathRepository.withIdIncludingDeleted(eqTo(PUBLISHED_ID))(any[DBSession]))
.thenReturn(Some(PUBLISHED_LEARNINGPATH))
when(learningPathRepository.update(any[LearningPath])(any[DBSession]))
.thenReturn(PUBLISHED_LEARNINGPATH.copy(status = learningpath.LearningPathStatus.PRIVATE))
when(learningPathRepository.learningPathsWithIsBasedOn(PUBLISHED_ID)).thenReturn(List())
val nowDate = NDLADate.fromUnixTime(1337)
when(clock.now()).thenReturn(nowDate)
val user = PRIVATE_OWNER.copy(permissions = Set(LEARNINGPATH_API_ADMIN)).toCombined

service.updateLearningPathStatusV2(PUBLISHED_ID, LearningPathStatus.UNLISTED, user, "nb").failIfFailure

val expectedLearningPath = PUBLISHED_LEARNINGPATH.copy(
status = LearningPathStatus.UNLISTED,
lastUpdated = nowDate,
madeAvailable = Some(nowDate)
)
verify(learningPathRepository, times(1)).update(eqTo(expectedLearningPath))(any)
}

test(
"That updateLearningPathStatusV2 updates the status when the given user is not the owner, but is admin and the status is PUBLISHED"
) {
Expand Down

0 comments on commit ed9bfd6

Please sign in to comment.