From fd41c3a72eeb633291575b75e890bb42f183bd06 Mon Sep 17 00:00:00 2001 From: Lars Westermann Date: Mon, 10 Jun 2019 18:10:58 +0200 Subject: [PATCH] Add delete buttons --- .../kotlin/de/kif/backend/route/Account.kt | 136 +++++++++++++++++- 1 file changed, 133 insertions(+), 3 deletions(-) diff --git a/src/jvmMain/kotlin/de/kif/backend/route/Account.kt b/src/jvmMain/kotlin/de/kif/backend/route/Account.kt index ebb053c..78f1705 100644 --- a/src/jvmMain/kotlin/de/kif/backend/route/Account.kt +++ b/src/jvmMain/kotlin/de/kif/backend/route/Account.kt @@ -2,8 +2,6 @@ package de.kif.backend.route import de.kif.backend.authenticate import de.kif.backend.authenticateOrRedirect -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 @@ -27,6 +25,7 @@ import io.ktor.util.toMap import kotlinx.html.* import mu.KotlinLogging import de.kif.backend.prefix +import de.kif.backend.repository.* private val logger = KotlinLogging.logger {} @@ -107,7 +106,7 @@ fun Route.account() { if (user.checkPermission(Permission.ADMIN)) { a("$prefix/account/backup.json", classes = "form-btn") { attributes["download"] = "backup.json" - +"Alles sichern" // TODO: richtiger Text? + +"Alles sichern" } } } @@ -162,6 +161,46 @@ fun Route.account() { } } } + + div("account-delete") { + h1 { +"Löschen -- Gefährlicher Bereich --" } + + if (user.checkPermission(Permission.ROOM)) { + a("$prefix/account/backup/delete/rooms", classes = "form-btn btn-danger") { + +"Räume löschen" + } + } + if (user.checkPermission(Permission.USER)) { + a("$prefix/account/backup/delete/users", classes = "form-btn btn-danger") { + +"Nutzer löschen" + } + } + if (user.checkPermission(Permission.POST)) { + a("$prefix/account/backup/delete/posts", classes = "form-btn btn-danger") { + +"Beiträge löschen" + } + } + if (user.checkPermission(Permission.WORK_GROUP)) { + a("$prefix/account/backup/delete/work-groups", classes = "form-btn btn-danger") { + +"Arbeitskreise löschen" + } + } + if ( + user.checkPermission(Permission.WORK_GROUP) && + user.checkPermission(Permission.ROOM) && + user.checkPermission(Permission.SCHEDULE) + ) { + a("$prefix/account/backup/delete/schedules", classes = "form-btn btn-danger") { + +"Zeitplan löschen" + } + } + + if (user.checkPermission(Permission.ADMIN)) { + a("$prefix/account/backup/delete/all", classes = "form-btn btn-danger") { + +"Alles löschen" + } + } + } } } } @@ -393,4 +432,95 @@ fun Route.account() { call.error(HttpStatusCode.Unauthorized) } } + + + get("/account/backup/delete/rooms") { + authenticate(Permission.ROOM) { + ScheduleRepository.all().forEach { + if (it.id != null) ScheduleRepository.delete(it.id) + } + RoomRepository.all().forEach { + if (it.id != null) RoomRepository.delete(it.id) + } + call.respondRedirect("$prefix/") + } onFailure { + call.error(HttpStatusCode.Unauthorized) + } + } + + get("/account/backup/delete/users") { + authenticate(Permission.USER) { + UserRepository.all().forEach { + if (it.id != null) UserRepository.delete(it.id) + } + call.respondRedirect("$prefix/") + } onFailure { + call.error(HttpStatusCode.Unauthorized) + } + } + + get("/account/backup/delete/posts") { + authenticate(Permission.POST) { + PostRepository.all().forEach { + if (it.id != null) PostRepository.delete(it.id) + } + call.respondRedirect("$prefix/") + } onFailure { + call.error(HttpStatusCode.Unauthorized) + } + } + + get("/account/backup/delete/work-groups") { + authenticate(Permission.WORK_GROUP) { + ScheduleRepository.all().forEach { + if (it.id != null) ScheduleRepository.delete(it.id) + } + TrackRepository.all().forEach { + if (it.id != null) TrackRepository.delete(it.id) + } + WorkGroupRepository.all().forEach { + if (it.id != null) WorkGroupRepository.delete(it.id) + } + call.respondRedirect("$prefix/") + } onFailure { + call.error(HttpStatusCode.Unauthorized) + } + } + + get("/account/backup/delete/schedules") { + authenticate(Permission.ROOM, Permission.WORK_GROUP, Permission.SCHEDULE) { + ScheduleRepository.all().forEach { + if (it.id != null) ScheduleRepository.delete(it.id) + } + call.respondRedirect("$prefix/") + } onFailure { + call.error(HttpStatusCode.Unauthorized) + } + } + + get("/account/backup/delete/all") { + authenticate(Permission.ADMIN) { + ScheduleRepository.all().forEach { + if (it.id != null) ScheduleRepository.delete(it.id) + } + TrackRepository.all().forEach { + if (it.id != null) TrackRepository.delete(it.id) + } + WorkGroupRepository.all().forEach { + if (it.id != null) WorkGroupRepository.delete(it.id) + } + RoomRepository.all().forEach { + if (it.id != null) RoomRepository.delete(it.id) + } + UserRepository.all().forEach { + if (it.id != null) UserRepository.delete(it.id) + } + PostRepository.all().forEach { + if (it.id != null) PostRepository.delete(it.id) + } + call.respondRedirect("$prefix/") + } onFailure { + call.error(HttpStatusCode.Unauthorized) + } + } }