diff --git a/src/jvmMain/kotlin/de/kif/backend/route/Account.kt b/src/jvmMain/kotlin/de/kif/backend/route/Account.kt index e651308..784f4d8 100644 --- a/src/jvmMain/kotlin/de/kif/backend/route/Account.kt +++ b/src/jvmMain/kotlin/de/kif/backend/route/Account.kt @@ -2,18 +2,15 @@ package de.kif.backend.route import de.kif.backend.authenticate import de.kif.backend.authenticateOrRedirect -import de.kif.backend.util.Backup import de.kif.backend.repository.TrackRepository import de.kif.backend.repository.WorkGroupRepository import de.kif.backend.route.api.error +import de.kif.backend.util.Backup import de.kif.backend.util.WikiImporter -import de.kif.backend.view.MainTemplate -import de.kif.backend.view.MenuTemplate import de.kif.backend.view.respondMain import de.kif.common.RepositoryType import de.kif.common.model.Permission import io.ktor.application.call -import io.ktor.html.respondHtmlTemplate import io.ktor.http.ContentType import io.ktor.http.HttpStatusCode import io.ktor.http.content.PartData @@ -35,10 +32,6 @@ private val logger = KotlinLogging.logger {} fun Route.account() { get("/account") { authenticateOrRedirect { user -> - - val tracks = TrackRepository.all() - val wikiSections = WikiImporter.loadSections() - respondMain { content { h1 { +"Account" } @@ -54,6 +47,23 @@ fun Route.account() { } } + a(href = "/account/backup", classes = "form-btn") { + +"Backup" + } + a(href = "/account/import", classes = "form-btn") { + +"Import wiki" + } + } + } + } + } + + get("/account/backup") { + authenticateOrRedirect { user -> + respondMain { + content { + h1 { +"Backup" } + div("account-backup") { if (user.checkPermission(Permission.ROOM)) { a("/account/backup/rooms.json", classes = "form-btn") { @@ -99,9 +109,11 @@ fun Route.account() { } if (user.checkPermission(Permission.ADMIN)) { + h1 { +"Restore" } + div("account-import") { form( - action = "/account/import", + action = "/account/restore", method = FormMethod.post, encType = FormEncType.multipartFormData ) { @@ -146,12 +158,25 @@ fun Route.account() { } } } + } + } + } + } + + get("/account/import") { + authenticateOrRedirect { user -> + val tracks = TrackRepository.all() + val wikiSections = WikiImporter.loadSections() + + respondMain { + content { + h1 { +"Import wiki" } if (user.checkPermission(Permission.ADMIN)) { div("account-import-wiki") { span { +"Import work group data from the kif wiki" } - form(action = "/account/import-wiki", method = FormMethod.post) { + form(action = "/account/import", method = FormMethod.post) { for ((index, section) in wikiSections.withIndex()) { div("form-group") { label { @@ -277,7 +302,7 @@ fun Route.account() { } } - post("/account/import") { + post("/account/restore") { authenticate(Permission.ADMIN) { var reset = false var import = "" @@ -308,7 +333,7 @@ fun Route.account() { } } - post("/account/import-wiki") { + post("/account/import") { authenticate(Permission.ADMIN) { val params = call.receiveParameters().toMap().mapValues { (_, list) -> list.firstOrNull()