All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lightningkite.ktordb.SecurityRules.kt Maven / Gradle / Ivy

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)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy