Add delete buttons

This commit is contained in:
Lars Westermann 2019-06-10 18:10:58 +02:00
parent 0026643a0a
commit fd41c3a72e
Signed by: lars.westermann
GPG key ID: 9D417FA5BB9D5E1D

View file

@ -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)
}
}
}