Fix bug when defining NS / DB without first selecting NS / DB
Closes #12
This commit is contained in:
parent
8159c10693
commit
a2c5ea237b
13 changed files with 79 additions and 2 deletions
|
@ -139,6 +139,8 @@ impl<'a> Executor<'a> {
|
||||||
let res = match stm {
|
let res = match stm {
|
||||||
// Specify runtime options
|
// Specify runtime options
|
||||||
Statement::Option(stm) => {
|
Statement::Option(stm) => {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Db)?;
|
opt.check(Level::Db)?;
|
||||||
// Process the option
|
// Process the option
|
||||||
|
|
|
@ -191,10 +191,15 @@ impl Options {
|
||||||
if !self.auth.check(level) {
|
if !self.auth.check(level) {
|
||||||
return Err(Error::QueryPermissions);
|
return Err(Error::QueryPermissions);
|
||||||
}
|
}
|
||||||
if self.ns.is_none() {
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check whether the authentication permissions are ok
|
||||||
|
pub fn needs(&self, level: Level) -> Result<(), Error> {
|
||||||
|
if self.ns.is_none() && matches!(level, Level::Ns | Level::Db) {
|
||||||
return Err(Error::NsEmpty);
|
return Err(Error::NsEmpty);
|
||||||
}
|
}
|
||||||
if self.db.is_none() {
|
if self.db.is_none() && matches!(level, Level::Db) {
|
||||||
return Err(Error::DbEmpty);
|
return Err(Error::DbEmpty);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -40,6 +40,8 @@ impl CreateStatement {
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::No)?;
|
opt.check(Level::No)?;
|
||||||
// Create a new iterator
|
// Create a new iterator
|
||||||
|
|
|
@ -114,6 +114,8 @@ impl DefineNamespaceStatement {
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
// No need for NS/DB
|
||||||
|
opt.needs(Level::Kv)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Kv)?;
|
opt.check(Level::Kv)?;
|
||||||
// Process the statement
|
// Process the statement
|
||||||
|
@ -161,6 +163,8 @@ impl DefineDatabaseStatement {
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
// Selected NS?
|
||||||
|
opt.needs(Level::Ns)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Ns)?;
|
opt.check(Level::Ns)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -218,6 +222,8 @@ impl DefineLoginStatement {
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
match self.base {
|
match self.base {
|
||||||
Base::Ns => {
|
Base::Ns => {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Ns)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Kv)?;
|
opt.check(Level::Kv)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -232,6 +238,8 @@ impl DefineLoginStatement {
|
||||||
Ok(Value::None)
|
Ok(Value::None)
|
||||||
}
|
}
|
||||||
Base::Db => {
|
Base::Db => {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Ns)?;
|
opt.check(Level::Ns)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -343,6 +351,8 @@ impl DefineTokenStatement {
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
match self.base {
|
match self.base {
|
||||||
Base::Ns => {
|
Base::Ns => {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Ns)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Kv)?;
|
opt.check(Level::Kv)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -357,6 +367,8 @@ impl DefineTokenStatement {
|
||||||
Ok(Value::None)
|
Ok(Value::None)
|
||||||
}
|
}
|
||||||
Base::Db => {
|
Base::Db => {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Ns)?;
|
opt.check(Level::Ns)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -439,6 +451,8 @@ impl DefineScopeStatement {
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Db)?;
|
opt.check(Level::Db)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -559,6 +573,8 @@ impl DefineTableStatement {
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Db)?;
|
opt.check(Level::Db)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -726,6 +742,8 @@ impl DefineEventStatement {
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Db)?;
|
opt.check(Level::Db)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -805,6 +823,8 @@ impl DefineFieldStatement {
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Db)?;
|
opt.check(Level::Db)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -943,6 +963,8 @@ impl DefineIndexStatement {
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Db)?;
|
opt.check(Level::Db)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
|
|
@ -41,6 +41,8 @@ impl DeleteStatement {
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::No)?;
|
opt.check(Level::No)?;
|
||||||
// Create a new iterator
|
// Create a new iterator
|
||||||
|
|
|
@ -34,6 +34,8 @@ impl InfoStatement {
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
match self {
|
match self {
|
||||||
InfoStatement::Kv => {
|
InfoStatement::Kv => {
|
||||||
|
// No need for NS/DB
|
||||||
|
opt.needs(Level::Kv)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Kv)?;
|
opt.check(Level::Kv)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -52,6 +54,8 @@ impl InfoStatement {
|
||||||
Value::from(res).ok()
|
Value::from(res).ok()
|
||||||
}
|
}
|
||||||
InfoStatement::Ns => {
|
InfoStatement::Ns => {
|
||||||
|
// Selected NS?
|
||||||
|
opt.needs(Level::Ns)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Ns)?;
|
opt.check(Level::Ns)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -82,6 +86,8 @@ impl InfoStatement {
|
||||||
Value::from(res).ok()
|
Value::from(res).ok()
|
||||||
}
|
}
|
||||||
InfoStatement::Db => {
|
InfoStatement::Db => {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Db)?;
|
opt.check(Level::Db)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -118,6 +124,8 @@ impl InfoStatement {
|
||||||
Value::from(res).ok()
|
Value::from(res).ok()
|
||||||
}
|
}
|
||||||
InfoStatement::Sc(sc) => {
|
InfoStatement::Sc(sc) => {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Db)?;
|
opt.check(Level::Db)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -136,6 +144,8 @@ impl InfoStatement {
|
||||||
Value::from(res).ok()
|
Value::from(res).ok()
|
||||||
}
|
}
|
||||||
InfoStatement::Tb(tb) => {
|
InfoStatement::Tb(tb) => {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Db)?;
|
opt.check(Level::Db)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
|
|
@ -44,6 +44,8 @@ impl InsertStatement {
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::No)?;
|
opt.check(Level::No)?;
|
||||||
// Create a new iterator
|
// Create a new iterator
|
||||||
|
|
|
@ -27,6 +27,8 @@ impl KillStatement {
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.realtime()?;
|
opt.realtime()?;
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::No)?;
|
opt.check(Level::No)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
|
|
@ -40,6 +40,8 @@ impl LiveStatement {
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.realtime()?;
|
opt.realtime()?;
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::No)?;
|
opt.check(Level::No)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
|
|
@ -52,6 +52,8 @@ impl RelateStatement {
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::No)?;
|
opt.check(Level::No)?;
|
||||||
// Create a new iterator
|
// Create a new iterator
|
||||||
|
|
|
@ -98,6 +98,8 @@ impl RemoveNamespaceStatement {
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
// No need for NS/DB
|
||||||
|
opt.needs(Level::Kv)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Kv)?;
|
opt.check(Level::Kv)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -152,6 +154,8 @@ impl RemoveDatabaseStatement {
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
// Selected NS?
|
||||||
|
opt.needs(Level::Ns)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Ns)?;
|
opt.check(Level::Ns)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -209,6 +213,8 @@ impl RemoveLoginStatement {
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
match self.base {
|
match self.base {
|
||||||
Base::Ns => {
|
Base::Ns => {
|
||||||
|
// Selected NS?
|
||||||
|
opt.needs(Level::Ns)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Kv)?;
|
opt.check(Level::Kv)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -222,6 +228,8 @@ impl RemoveLoginStatement {
|
||||||
Ok(Value::None)
|
Ok(Value::None)
|
||||||
}
|
}
|
||||||
Base::Db => {
|
Base::Db => {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Ns)?;
|
opt.check(Level::Ns)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -284,6 +292,8 @@ impl RemoveTokenStatement {
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
match self.base {
|
match self.base {
|
||||||
Base::Ns => {
|
Base::Ns => {
|
||||||
|
// Selected NS?
|
||||||
|
opt.needs(Level::Ns)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Kv)?;
|
opt.check(Level::Kv)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -297,6 +307,8 @@ impl RemoveTokenStatement {
|
||||||
Ok(Value::None)
|
Ok(Value::None)
|
||||||
}
|
}
|
||||||
Base::Db => {
|
Base::Db => {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Ns)?;
|
opt.check(Level::Ns)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -356,6 +368,8 @@ impl RemoveScopeStatement {
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Db)?;
|
opt.check(Level::Db)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -407,6 +421,8 @@ impl RemoveTableStatement {
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Db)?;
|
opt.check(Level::Db)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -462,6 +478,8 @@ impl RemoveEventStatement {
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Db)?;
|
opt.check(Level::Db)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -520,6 +538,8 @@ impl RemoveFieldStatement {
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Db)?;
|
opt.check(Level::Db)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
@ -578,6 +598,8 @@ impl RemoveIndexStatement {
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Db)?;
|
opt.check(Level::Db)?;
|
||||||
// Clone transaction
|
// Clone transaction
|
||||||
|
|
|
@ -80,6 +80,8 @@ impl SelectStatement {
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::No)?;
|
opt.check(Level::No)?;
|
||||||
// Create a new iterator
|
// Create a new iterator
|
||||||
|
|
|
@ -42,6 +42,8 @@ impl UpdateStatement {
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
// Selected DB?
|
||||||
|
opt.needs(Level::Db)?;
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::No)?;
|
opt.check(Level::No)?;
|
||||||
// Create a new iterator
|
// Create a new iterator
|
||||||
|
|
Loading…
Reference in a new issue