Signed-off-by: Chaoscaot <max@maxsp.de>
This commit is contained in:
@@ -32,6 +32,7 @@ import io.ktor.server.routing.Route
|
|||||||
import io.ktor.server.routing.get
|
import io.ktor.server.routing.get
|
||||||
import io.ktor.server.routing.route
|
import io.ktor.server.routing.route
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
import org.jetbrains.exposed.v1.core.Alias
|
||||||
import org.jetbrains.exposed.v1.core.JoinType
|
import org.jetbrains.exposed.v1.core.JoinType
|
||||||
import org.jetbrains.exposed.v1.core.SortOrder
|
import org.jetbrains.exposed.v1.core.SortOrder
|
||||||
import org.jetbrains.exposed.v1.core.alias
|
import org.jetbrains.exposed.v1.core.alias
|
||||||
@@ -41,8 +42,10 @@ import org.jetbrains.exposed.v1.core.isNull
|
|||||||
import org.jetbrains.exposed.v1.core.less
|
import org.jetbrains.exposed.v1.core.less
|
||||||
import org.jetbrains.exposed.v1.core.like
|
import org.jetbrains.exposed.v1.core.like
|
||||||
import org.jetbrains.exposed.v1.core.or
|
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.andWhere
|
||||||
import org.jetbrains.exposed.v1.jdbc.select
|
import org.jetbrains.exposed.v1.jdbc.select
|
||||||
|
import org.jetbrains.exposed.v1.jdbc.selectAll
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
|
||||||
fun Route.configureAuditLog() {
|
fun Route.configureAuditLog() {
|
||||||
@@ -126,34 +129,32 @@ data class PagedAuditLog(val rows: Long, val entries: List<AuditLogEntry>) {
|
|||||||
*AuditLogTable.columns.toTypedArray()
|
*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(
|
PagedAuditLog(
|
||||||
query.count(),
|
AuditLogTable.selectAll().addAuditLogFilters(
|
||||||
|
actionText,
|
||||||
|
serverText,
|
||||||
|
fullText,
|
||||||
|
actor,
|
||||||
|
actionType,
|
||||||
|
timeGreater,
|
||||||
|
timeLess,
|
||||||
|
serverOwner,
|
||||||
|
velocity
|
||||||
|
).count(),
|
||||||
query
|
query
|
||||||
|
.addAuditLogFilters(
|
||||||
|
actionText,
|
||||||
|
serverText,
|
||||||
|
fullText,
|
||||||
|
actor,
|
||||||
|
actionType,
|
||||||
|
timeGreater,
|
||||||
|
timeLess,
|
||||||
|
serverOwner,
|
||||||
|
velocity,
|
||||||
|
actorTable,
|
||||||
|
serverOwnerTable
|
||||||
|
)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset((page * limit).toLong())
|
.offset((page * limit).toLong())
|
||||||
.orderBy(AuditLogTable.time, SortOrder.valueOf(sorting.uppercase()))
|
.orderBy(AuditLogTable.time, SortOrder.valueOf(sorting.uppercase()))
|
||||||
@@ -170,6 +171,38 @@ data class PagedAuditLog(val rows: Long, val entries: List<AuditLogEntry>) {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Query.addAuditLogFilters(
|
||||||
|
actionText: String? = null,
|
||||||
|
serverText: String? = null,
|
||||||
|
fullText: String? = null,
|
||||||
|
actor: Set<String>? = null,
|
||||||
|
actionType: Set<AuditLog.Type>? = null,
|
||||||
|
timeGreater: Instant? = null,
|
||||||
|
timeLess: Instant? = null,
|
||||||
|
serverOwner: Set<String>? = null,
|
||||||
|
velocity: Boolean? = null,
|
||||||
|
actorTable: Alias<SteamwarUserTable>? = null,
|
||||||
|
serverOwnerTable: Alias<SteamwarUserTable>? = 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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user