Process PERMISSIONS clauses on document fields
This commit is contained in:
parent
6b6d4f65f9
commit
c4386f1549
1 changed files with 29 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
use crate::dbs::Runtime;
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
|
@ -7,6 +8,7 @@ use crate::err::Error;
|
||||||
use crate::sql::field::Field;
|
use crate::sql::field::Field;
|
||||||
use crate::sql::idiom::Idiom;
|
use crate::sql::idiom::Idiom;
|
||||||
use crate::sql::output::Output;
|
use crate::sql::output::Output;
|
||||||
|
use crate::sql::permission::Permission;
|
||||||
use crate::sql::value::Value;
|
use crate::sql::value::Value;
|
||||||
|
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
|
@ -19,8 +21,8 @@ impl<'a> Document<'a> {
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
// Ensure futures are run
|
// Ensure futures are run
|
||||||
let opt = &opt.futures(true);
|
let opt = &opt.futures(true);
|
||||||
match stm.output() {
|
// Process the desired output
|
||||||
// Process output clause
|
let mut out = match stm.output() {
|
||||||
Some(v) => match v {
|
Some(v) => match v {
|
||||||
Output::None => Err(Error::Ignore),
|
Output::None => Err(Error::Ignore),
|
||||||
Output::Null => Ok(Value::Null),
|
Output::Null => Ok(Value::Null),
|
||||||
|
@ -109,6 +111,31 @@ impl<'a> Document<'a> {
|
||||||
}
|
}
|
||||||
_ => Err(Error::Ignore),
|
_ => Err(Error::Ignore),
|
||||||
},
|
},
|
||||||
|
}?;
|
||||||
|
// Loop through all field statements
|
||||||
|
for fd in self.fd(opt, txn).await?.iter() {
|
||||||
|
// Loop over each field in document
|
||||||
|
for k in out.each(&fd.name).into_iter() {
|
||||||
|
// Process field permissions
|
||||||
|
match &fd.permissions.select {
|
||||||
|
Permission::Full => (),
|
||||||
|
Permission::None => out.del(ctx, opt, txn, &k).await?,
|
||||||
|
Permission::Specific(e) => {
|
||||||
|
// Get the current value
|
||||||
|
let val = self.current.pick(&k);
|
||||||
|
// Configure the context
|
||||||
|
let mut ctx = Context::new(ctx);
|
||||||
|
ctx.add_value("value".into(), val);
|
||||||
|
let ctx = ctx.freeze();
|
||||||
|
// Process the PERMISSION clause
|
||||||
|
if !e.compute(&ctx, opt, txn, Some(&self.current)).await?.is_truthy() {
|
||||||
|
out.del(&ctx, opt, txn, &k).await?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// Output result
|
||||||
|
Ok(out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue