Skip to content

Commit

Permalink
Merge pull request #602 from NDLANO/id-permissions-lp
Browse files Browse the repository at this point in the history
learningpath-api: Open `ids` endpoint to allow everyone to fetch
  • Loading branch information
jnatten authored Feb 10, 2025
2 parents 843d8ec + a6893fd commit 0179665
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import no.ndla.language.Language.AllLanguages
import no.ndla.learningpathapi.Props
import no.ndla.learningpathapi.integration.TaxonomyApiClient
import no.ndla.learningpathapi.model.api.*
import no.ndla.learningpathapi.model.domain.UserInfo.LearningpathCombinedUser
import no.ndla.learningpathapi.model.domain.{License as _, *}
import no.ndla.learningpathapi.service.search.{SearchConverterServiceComponent, SearchService}
import no.ndla.learningpathapi.service.{ConverterService, ReadService, UpdateService}
Expand Down Expand Up @@ -284,26 +283,21 @@ trait LearningpathControllerV2 {
.in(pageSize)
.in(pageNo)
.errorOut(errorOutputsFor(400, 401, 403))
.out(jsonBody[Seq[LearningPathV2DTO]])
.out(jsonBody[List[LearningPathV2DTO]])
.withOptionalMyNDLAUserOrTokenUser
.serverLogicPure { user =>
{ case (idList, fallback, language, pageSizeQ, pageNoQ) =>
if (!user.isNdla) {
forbidden.asLeft
} else {
val pageSize = pageSizeQ.getOrElse(props.DefaultPageSize) match {
case tooSmall if tooSmall < 1 => props.DefaultPageSize
case x => x
}
val page = pageNoQ.getOrElse(1) match {
case tooSmall if tooSmall < 1 => 1
case x => x
}
readService.withIdV2List(idList.values, language, fallback, page, pageSize, user) match {
case Failure(ex) => returnLeftError(ex)
case Success(articles) => articles.asRight
}
val pageSize = pageSizeQ.getOrElse(props.DefaultPageSize) match {
case tooSmall if tooSmall < 1 => props.DefaultPageSize
case x => x
}
val page = pageNoQ.getOrElse(1) match {
case tooSmall if tooSmall < 1 => 1
case x => x
}
readService
.withIdV2List(idList.values, language, fallback, page, pageSize, user)
.handleErrorsOrOk
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ trait ReadService {
page: Int,
pageSize: Int,
userInfo: CombinedUser
): Try[Seq[LearningPathV2DTO]] = {
): Try[List[LearningPathV2DTO]] = {
if (ids.isEmpty) Failure(ValidationException("ids", "Query parameter 'ids' is missing"))
else {
val offset = (page - 1) * pageSize
val learningpaths = learningPathRepository.pageWithIds(ids, pageSize, offset)
learningpaths.traverse(learningpath =>
converterService.asApiLearningpathV2(learningpath, language, fallback, userInfo)
)
learningpaths
.map(_.isOwnerOrPublic(userInfo))
.collect { case Success(lp) => converterService.asApiLearningpathV2(lp, language, fallback, userInfo) }
.sequence
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import scala.collection.mutable.ListBuffer
object Layout {
lazy val prebuiltLayout: PatternLayout = PatternLayout
.newBuilder()
.withPattern("[%level] %C.%M#%L: %msg%n")
.withPattern("[%level] (%X{correlationID}) %C.%M#%L: %msg%n")
.build()
}

Expand Down

0 comments on commit 0179665

Please sign in to comment.