com.lightningkite.ktordb.SecurityRules.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of db Show documentation
Show all versions of db Show documentation
An abstract tool for communicating with different types of databases.
The newest version!
package com.lightningkite.ktordb
/*
Per-field security rules
rewrite: (Model, T) -> T
mask: (Model, T) -> T
modify: (Model, TModification) -> (TModification)
queryableRequires: TCondition
*/
@Deprecated("Prefer using the new ModelPermissions instead.")
interface SecurityRules {
suspend fun sortAllowed(filter: SortPart): Condition
suspend fun read(filter: Condition): Condition
suspend fun edit(filter: Condition, modification: Modification): Pair, Modification> = read(filter) to modification
suspend fun delete(filter: Condition): Condition = edit(filter, Modification.Chain(listOf())).first
suspend fun mask(model: Model): Model = model
suspend fun create(model: Model): Model = model
suspend fun replace(model: Model): Pair, Model>
suspend fun maxQueryTimeMs(): Long = 10_000L
open class AllowAll: SecurityRules {
override suspend fun sortAllowed(filter: SortPart): Condition = Condition.Always()
override suspend fun read(filter: Condition): Condition = filter
override suspend fun edit(filter: Condition, modification: Modification): Pair, Modification> = filter to modification
override suspend fun delete(filter: Condition): Condition = filter
override suspend fun mask(model: Model): Model = model
override suspend fun create(model: Model): Model = model
override suspend fun replace(model: Model): Pair, Model> = Condition.Always() to model
override suspend fun maxQueryTimeMs(): Long = 100_000L
}
}
//abstract class SimpleSecurityRules {
// abstract suspend fun read
//}
@Deprecated("Prefer using new ModelPermissions instead")
fun FieldCollection.secure(
rules: SecurityRules
) = SecuredFieldCollection(this, rules)