Allow a collective to disable the integration endpoint

This commit is contained in:
Eike Kettner
2020-05-23 13:53:36 +02:00
parent f74f8e5198
commit f16632bc7f
14 changed files with 138 additions and 71 deletions

View File

@ -0,0 +1,7 @@
ALTER TABLE `collective`
ADD COLUMN (`integration_enabled` BOOLEAN);
UPDATE `collective` SET `integration_enabled` = true;
ALTER TABLE `collective`
MODIFY `integration_enabled` BOOLEAN NOT NULL;

View File

@ -0,0 +1,7 @@
ALTER TABLE "collective"
ADD COLUMN "integration_enabled" BOOLEAN;
UPDATE "collective" SET "integration_enabled" = true;
ALTER TABLE "collective"
ALTER COLUMN "integration_enabled" SET NOT NULL;

View File

@ -11,6 +11,7 @@ case class RCollective(
id: Ident,
state: CollectiveState,
language: Language,
integrationEnabled: Boolean,
created: Timestamp
)
@ -20,12 +21,13 @@ object RCollective {
object Columns {
val id = Column("cid")
val state = Column("state")
val language = Column("doclang")
val created = Column("created")
val id = Column("cid")
val state = Column("state")
val language = Column("doclang")
val integration = Column("integration_enabled")
val created = Column("created")
val all = List(id, state, language, created)
val all = List(id, state, language, integration, created)
}
import Columns._
@ -34,7 +36,7 @@ object RCollective {
val sql = insertRow(
table,
Columns.all,
fr"${value.id},${value.state},${value.language},${value.created}"
fr"${value.id},${value.state},${value.language},${value.integrationEnabled},${value.created}"
)
sql.update.run
}
@ -56,6 +58,16 @@ object RCollective {
def updateLanguage(cid: Ident, lang: Language): ConnectionIO[Int] =
updateRow(table, id.is(cid), language.setTo(lang)).update.run
def updateSettings(cid: Ident, settings: Settings): ConnectionIO[Int] =
updateRow(
table,
id.is(cid),
commas(
language.setTo(settings.language),
integration.setTo(settings.integrationEnabled)
)
).update.run
def findById(cid: Ident): ConnectionIO[Option[RCollective]] = {
val sql = selectSimple(all, table, id.is(cid))
sql.query[RCollective].option
@ -75,4 +87,6 @@ object RCollective {
val sql = selectSimple(all, table, Fragment.empty) ++ orderBy(order(Columns).f)
sql.query[RCollective].stream
}
case class Settings(language: Language, integrationEnabled: Boolean)
}