diff --git a/WebsiteBackend/src/de/steamwar/routes/AuditLog.kt b/WebsiteBackend/src/de/steamwar/routes/AuditLog.kt index 4149aeef..27a59c72 100644 --- a/WebsiteBackend/src/de/steamwar/routes/AuditLog.kt +++ b/WebsiteBackend/src/de/steamwar/routes/AuditLog.kt @@ -32,7 +32,6 @@ import io.ktor.server.routing.Route import io.ktor.server.routing.get import io.ktor.server.routing.route import kotlinx.serialization.Serializable -import org.jetbrains.exposed.v1.core.Alias import org.jetbrains.exposed.v1.core.JoinType import org.jetbrains.exposed.v1.core.SortOrder import org.jetbrains.exposed.v1.core.alias @@ -42,10 +41,8 @@ import org.jetbrains.exposed.v1.core.isNull import org.jetbrains.exposed.v1.core.less import org.jetbrains.exposed.v1.core.like import org.jetbrains.exposed.v1.core.or -import org.jetbrains.exposed.v1.jdbc.Query import org.jetbrains.exposed.v1.jdbc.andWhere import org.jetbrains.exposed.v1.jdbc.select -import org.jetbrains.exposed.v1.jdbc.selectAll import java.time.Instant fun Route.configureAuditLog() { @@ -129,32 +126,34 @@ data class PagedAuditLog(val rows: Long, val entries: List) { *AuditLogTable.columns.toTypedArray() ) + + actionText?.let { + query.andWhere { (AuditLogTable.actionText like "%$it%") } + } + + serverText?.let { + query.andWhere { (AuditLogTable.server like "%$it%") } + } + + fullText?.let { + query.andWhere { (AuditLogTable.actionText like "%$it%") or (AuditLogTable.server like "%$it%") } + } + + actor?.let { query.andWhere { actorTable[SteamwarUserTable.uuid] inList actor } } + + actionType?.let { query.andWhere { AuditLogTable.action inList actionType } } + + timeGreater?.let { query.andWhere { AuditLogTable.time greater timeGreater } } + + timeLess?.let { query.andWhere { AuditLogTable.time less timeLess } } + + serverOwner?.let { query.andWhere { serverOwnerTable[SteamwarUserTable.uuid] inList serverOwner } } + + if (velocity == true) query.andWhere { AuditLogTable.serverOwner.isNull() } + PagedAuditLog( - AuditLogTable.selectAll().addAuditLogFilters( - actionText, - serverText, - fullText, - actor, - actionType, - timeGreater, - timeLess, - serverOwner, - velocity - ).count(), + query.count(), query - .addAuditLogFilters( - actionText, - serverText, - fullText, - actor, - actionType, - timeGreater, - timeLess, - serverOwner, - velocity, - actorTable, - serverOwnerTable - ) .limit(limit) .offset((page * limit).toLong()) .orderBy(AuditLogTable.time, SortOrder.valueOf(sorting.uppercase())) @@ -171,38 +170,6 @@ data class PagedAuditLog(val rows: Long, val entries: List) { }, ) } - - private fun Query.addAuditLogFilters( - actionText: String? = null, - serverText: String? = null, - fullText: String? = null, - actor: Set? = null, - actionType: Set? = null, - timeGreater: Instant? = null, - timeLess: Instant? = null, - serverOwner: Set? = null, - velocity: Boolean? = null, - actorTable: Alias? = null, - serverOwnerTable: Alias? = null - ): Query { - actionText?.let { - andWhere { (AuditLogTable.actionText like "%$it%") } - } - serverText?.let { - andWhere { (AuditLogTable.server like "%$it%") } - } - fullText?.let { - andWhere { (AuditLogTable.actionText like "%$it%") or (AuditLogTable.server like "%$it%") } - } - actor?.let { andWhere { actorTable!![SteamwarUserTable.uuid] inList actor } } - actionType?.let { andWhere { AuditLogTable.action inList actionType } } - timeGreater?.let { andWhere { AuditLogTable.time greater timeGreater } } - timeLess?.let { andWhere { AuditLogTable.time less timeLess } } - serverOwner?.let { andWhere { serverOwnerTable!![SteamwarUserTable.uuid] inList serverOwner } } - if (velocity == true) andWhere { AuditLogTable.serverOwner.isNull() } - - return this - } } }