-
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.
Merge pull request #321 from NDLANO/config-lists
learningpath-api: Add support for `arenaEnabled`/`MY_NDLA_ENABLED_ORGS`
- Loading branch information
Showing
26 changed files
with
422 additions
and
142 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
.../main/resources/no/ndla/learningpathapi/db/migration/V30__ConvertConfigToSpecificType.sql
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,6 @@ | ||
UPDATE configtable c | ||
SET value=( | ||
SELECT value || jsonb_build_object('value', jsonb_build_object('value', (c2.value->>'value')::jsonb)) | ||
FROM configtable c2 | ||
WHERE c2.configkey = c.configkey | ||
) |
6 changes: 6 additions & 0 deletions
6
...pi/src/main/resources/no/ndla/learningpathapi/db/migration/V32__AddArenaEnabledToUser.sql
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,6 @@ | ||
UPDATE my_ndla_users mnu | ||
SET document=( | ||
SELECT document || jsonb_build_object('arenaEnabled', false) | ||
FROM my_ndla_users mnu2 | ||
WHERE mnu.id = mnu2.id | ||
) |
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
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
67 changes: 67 additions & 0 deletions
67
...a/no/ndla/learningpathapi/db/migrationwithdependencies/V31__ArenaDefaultEnabledOrgs.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,67 @@ | ||
/* | ||
* Part of NDLA learningpath-api | ||
* Copyright (C) 2023 NDLA | ||
* | ||
* See LICENSE | ||
*/ | ||
|
||
package no.ndla.learningpathapi.db.migrationwithdependencies | ||
|
||
import io.circe.Json | ||
import io.circe.syntax._ | ||
import no.ndla.common.model.NDLADate | ||
import no.ndla.learningpathapi.LearningpathApiProperties | ||
import org.flywaydb.core.api.migration.{BaseJavaMigration, Context} | ||
import org.postgresql.util.PGobject | ||
import scalikejdbc.{DB, DBSession, _} | ||
|
||
class V31__ArenaDefaultEnabledOrgs(properties: LearningpathApiProperties) extends BaseJavaMigration { | ||
|
||
override def migrate(context: Context): Unit = DB(context.getConnection) | ||
.autoClose(false) | ||
.withinTx { implicit session => | ||
insertConfig | ||
} | ||
|
||
def insertConfig(implicit session: DBSession): Unit = { | ||
val document = Json.obj( | ||
"key" -> Json.fromString("ARENA_ENABLED_ORGS"), | ||
"value" -> Json.obj("value" -> Json.fromValues(orgs.map(Json.fromString))), | ||
"updatedAt" -> NDLADate.now().asJson, | ||
"updatedBy" -> Json.fromString("System") | ||
) | ||
|
||
val dataObject = new PGobject() | ||
dataObject.setType("jsonb") | ||
dataObject.setValue(document.noSpaces) | ||
|
||
val inserted = sql""" | ||
INSERT INTO configtable(configkey, value) | ||
VALUES ( | ||
'ARENA_ENABLED_ORGS', | ||
$dataObject | ||
) | ||
""".update.apply() | ||
|
||
if (inserted != 1) throw new RuntimeException("Failed to insert ARENA_ENABLED_ORGS") | ||
} | ||
|
||
private def orgs: List[String] = properties.Environment match { | ||
case "local" | "test" => | ||
List( | ||
"Agder fylkeskommune", | ||
"Innlandet fylkeskommune", | ||
"Møre og Romsdal fylkeskommune", | ||
"Nordland fylkeskommune", | ||
"Rogaland fylkeskommune", | ||
"Troms og Finnmark fylkeskommune", | ||
"Trøndelag fylkeskommune", | ||
"Vestfold og Telemark fylkeskommune", | ||
"Vestland fylkeskommune", | ||
"Viken fylkeskommune", | ||
"Universitetet i Rogn" | ||
) | ||
case _ => List.empty | ||
} | ||
|
||
} |
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
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
30 changes: 30 additions & 0 deletions
30
...ingpath-api/src/main/scala/no/ndla/learningpathapi/model/api/config/ConfigMetaValue.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,30 @@ | ||
/* | ||
* Part of NDLA learningpath-api. | ||
* Copyright (C) 2023 NDLA | ||
* | ||
* See LICENSE | ||
*/ | ||
|
||
package no.ndla.learningpathapi.model.api.config | ||
|
||
import no.ndla.learningpathapi.model.domain | ||
import org.scalatra.swagger.annotations.ApiModelProperty | ||
|
||
import scala.annotation.meta.field | ||
|
||
case class ConfigMetaValue( | ||
@(ApiModelProperty @field)(description = "Value to set configuration param to.") | ||
value: Either[Boolean, List[String]] | ||
) | ||
|
||
object ConfigMetaValue { | ||
def from(value: domain.config.ConfigMetaValue): ConfigMetaValue = { | ||
value match { | ||
case domain.config.BooleanValue(value) => ConfigMetaValue(Left(value)) | ||
case domain.config.StringListValue(value) => ConfigMetaValue(Right(value)) | ||
} | ||
} | ||
|
||
def apply(value: Boolean): ConfigMetaValue = ConfigMetaValue(Left(value)) | ||
def apply(value: List[String]): ConfigMetaValue = ConfigMetaValue(Right(value)) | ||
} |
17 changes: 0 additions & 17 deletions
17
...gpath-api/src/main/scala/no/ndla/learningpathapi/model/api/config/UpdateConfigValue.scala
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.