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 {
|
||||
// Specify runtime options
|
||||
Statement::Option(stm) => {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Db)?;
|
||||
// Process the option
|
||||
|
|
|
@ -191,10 +191,15 @@ impl Options {
|
|||
if !self.auth.check(level) {
|
||||
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);
|
||||
}
|
||||
if self.db.is_none() {
|
||||
if self.db.is_none() && matches!(level, Level::Db) {
|
||||
return Err(Error::DbEmpty);
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -40,6 +40,8 @@ impl CreateStatement {
|
|||
txn: &Transaction,
|
||||
doc: Option<&Value>,
|
||||
) -> Result<Value, Error> {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::No)?;
|
||||
// Create a new iterator
|
||||
|
|
|
@ -114,6 +114,8 @@ impl DefineNamespaceStatement {
|
|||
txn: &Transaction,
|
||||
_doc: Option<&Value>,
|
||||
) -> Result<Value, Error> {
|
||||
// No need for NS/DB
|
||||
opt.needs(Level::Kv)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Kv)?;
|
||||
// Process the statement
|
||||
|
@ -161,6 +163,8 @@ impl DefineDatabaseStatement {
|
|||
txn: &Transaction,
|
||||
_doc: Option<&Value>,
|
||||
) -> Result<Value, Error> {
|
||||
// Selected NS?
|
||||
opt.needs(Level::Ns)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Ns)?;
|
||||
// Clone transaction
|
||||
|
@ -218,6 +222,8 @@ impl DefineLoginStatement {
|
|||
) -> Result<Value, Error> {
|
||||
match self.base {
|
||||
Base::Ns => {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Ns)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Kv)?;
|
||||
// Clone transaction
|
||||
|
@ -232,6 +238,8 @@ impl DefineLoginStatement {
|
|||
Ok(Value::None)
|
||||
}
|
||||
Base::Db => {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Ns)?;
|
||||
// Clone transaction
|
||||
|
@ -343,6 +351,8 @@ impl DefineTokenStatement {
|
|||
) -> Result<Value, Error> {
|
||||
match self.base {
|
||||
Base::Ns => {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Ns)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Kv)?;
|
||||
// Clone transaction
|
||||
|
@ -357,6 +367,8 @@ impl DefineTokenStatement {
|
|||
Ok(Value::None)
|
||||
}
|
||||
Base::Db => {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Ns)?;
|
||||
// Clone transaction
|
||||
|
@ -439,6 +451,8 @@ impl DefineScopeStatement {
|
|||
txn: &Transaction,
|
||||
_doc: Option<&Value>,
|
||||
) -> Result<Value, Error> {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Db)?;
|
||||
// Clone transaction
|
||||
|
@ -559,6 +573,8 @@ impl DefineTableStatement {
|
|||
txn: &Transaction,
|
||||
doc: Option<&Value>,
|
||||
) -> Result<Value, Error> {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Db)?;
|
||||
// Clone transaction
|
||||
|
@ -726,6 +742,8 @@ impl DefineEventStatement {
|
|||
txn: &Transaction,
|
||||
_doc: Option<&Value>,
|
||||
) -> Result<Value, Error> {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Db)?;
|
||||
// Clone transaction
|
||||
|
@ -805,6 +823,8 @@ impl DefineFieldStatement {
|
|||
txn: &Transaction,
|
||||
_doc: Option<&Value>,
|
||||
) -> Result<Value, Error> {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Db)?;
|
||||
// Clone transaction
|
||||
|
@ -943,6 +963,8 @@ impl DefineIndexStatement {
|
|||
txn: &Transaction,
|
||||
doc: Option<&Value>,
|
||||
) -> Result<Value, Error> {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Db)?;
|
||||
// Clone transaction
|
||||
|
|
|
@ -41,6 +41,8 @@ impl DeleteStatement {
|
|||
txn: &Transaction,
|
||||
doc: Option<&Value>,
|
||||
) -> Result<Value, Error> {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::No)?;
|
||||
// Create a new iterator
|
||||
|
|
|
@ -34,6 +34,8 @@ impl InfoStatement {
|
|||
// Allowed to run?
|
||||
match self {
|
||||
InfoStatement::Kv => {
|
||||
// No need for NS/DB
|
||||
opt.needs(Level::Kv)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Kv)?;
|
||||
// Clone transaction
|
||||
|
@ -52,6 +54,8 @@ impl InfoStatement {
|
|||
Value::from(res).ok()
|
||||
}
|
||||
InfoStatement::Ns => {
|
||||
// Selected NS?
|
||||
opt.needs(Level::Ns)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Ns)?;
|
||||
// Clone transaction
|
||||
|
@ -82,6 +86,8 @@ impl InfoStatement {
|
|||
Value::from(res).ok()
|
||||
}
|
||||
InfoStatement::Db => {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Db)?;
|
||||
// Clone transaction
|
||||
|
@ -118,6 +124,8 @@ impl InfoStatement {
|
|||
Value::from(res).ok()
|
||||
}
|
||||
InfoStatement::Sc(sc) => {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Db)?;
|
||||
// Clone transaction
|
||||
|
@ -136,6 +144,8 @@ impl InfoStatement {
|
|||
Value::from(res).ok()
|
||||
}
|
||||
InfoStatement::Tb(tb) => {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Db)?;
|
||||
// Clone transaction
|
||||
|
|
|
@ -44,6 +44,8 @@ impl InsertStatement {
|
|||
txn: &Transaction,
|
||||
doc: Option<&Value>,
|
||||
) -> Result<Value, Error> {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::No)?;
|
||||
// Create a new iterator
|
||||
|
|
|
@ -27,6 +27,8 @@ impl KillStatement {
|
|||
) -> Result<Value, Error> {
|
||||
// Allowed to run?
|
||||
opt.realtime()?;
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::No)?;
|
||||
// Clone transaction
|
||||
|
|
|
@ -40,6 +40,8 @@ impl LiveStatement {
|
|||
) -> Result<Value, Error> {
|
||||
// Allowed to run?
|
||||
opt.realtime()?;
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::No)?;
|
||||
// Clone transaction
|
||||
|
|
|
@ -52,6 +52,8 @@ impl RelateStatement {
|
|||
txn: &Transaction,
|
||||
doc: Option<&Value>,
|
||||
) -> Result<Value, Error> {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::No)?;
|
||||
// Create a new iterator
|
||||
|
|
|
@ -98,6 +98,8 @@ impl RemoveNamespaceStatement {
|
|||
txn: &Transaction,
|
||||
_doc: Option<&Value>,
|
||||
) -> Result<Value, Error> {
|
||||
// No need for NS/DB
|
||||
opt.needs(Level::Kv)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Kv)?;
|
||||
// Clone transaction
|
||||
|
@ -152,6 +154,8 @@ impl RemoveDatabaseStatement {
|
|||
txn: &Transaction,
|
||||
_doc: Option<&Value>,
|
||||
) -> Result<Value, Error> {
|
||||
// Selected NS?
|
||||
opt.needs(Level::Ns)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Ns)?;
|
||||
// Clone transaction
|
||||
|
@ -209,6 +213,8 @@ impl RemoveLoginStatement {
|
|||
) -> Result<Value, Error> {
|
||||
match self.base {
|
||||
Base::Ns => {
|
||||
// Selected NS?
|
||||
opt.needs(Level::Ns)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Kv)?;
|
||||
// Clone transaction
|
||||
|
@ -222,6 +228,8 @@ impl RemoveLoginStatement {
|
|||
Ok(Value::None)
|
||||
}
|
||||
Base::Db => {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Ns)?;
|
||||
// Clone transaction
|
||||
|
@ -284,6 +292,8 @@ impl RemoveTokenStatement {
|
|||
) -> Result<Value, Error> {
|
||||
match self.base {
|
||||
Base::Ns => {
|
||||
// Selected NS?
|
||||
opt.needs(Level::Ns)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Kv)?;
|
||||
// Clone transaction
|
||||
|
@ -297,6 +307,8 @@ impl RemoveTokenStatement {
|
|||
Ok(Value::None)
|
||||
}
|
||||
Base::Db => {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Ns)?;
|
||||
// Clone transaction
|
||||
|
@ -356,6 +368,8 @@ impl RemoveScopeStatement {
|
|||
txn: &Transaction,
|
||||
_doc: Option<&Value>,
|
||||
) -> Result<Value, Error> {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Db)?;
|
||||
// Clone transaction
|
||||
|
@ -407,6 +421,8 @@ impl RemoveTableStatement {
|
|||
txn: &Transaction,
|
||||
_doc: Option<&Value>,
|
||||
) -> Result<Value, Error> {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Db)?;
|
||||
// Clone transaction
|
||||
|
@ -462,6 +478,8 @@ impl RemoveEventStatement {
|
|||
txn: &Transaction,
|
||||
_doc: Option<&Value>,
|
||||
) -> Result<Value, Error> {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Db)?;
|
||||
// Clone transaction
|
||||
|
@ -520,6 +538,8 @@ impl RemoveFieldStatement {
|
|||
txn: &Transaction,
|
||||
_doc: Option<&Value>,
|
||||
) -> Result<Value, Error> {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Db)?;
|
||||
// Clone transaction
|
||||
|
@ -578,6 +598,8 @@ impl RemoveIndexStatement {
|
|||
txn: &Transaction,
|
||||
_doc: Option<&Value>,
|
||||
) -> Result<Value, Error> {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::Db)?;
|
||||
// Clone transaction
|
||||
|
|
|
@ -80,6 +80,8 @@ impl SelectStatement {
|
|||
txn: &Transaction,
|
||||
doc: Option<&Value>,
|
||||
) -> Result<Value, Error> {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::No)?;
|
||||
// Create a new iterator
|
||||
|
|
|
@ -42,6 +42,8 @@ impl UpdateStatement {
|
|||
txn: &Transaction,
|
||||
doc: Option<&Value>,
|
||||
) -> Result<Value, Error> {
|
||||
// Selected DB?
|
||||
opt.needs(Level::Db)?;
|
||||
// Allowed to run?
|
||||
opt.check(Level::No)?;
|
||||
// Create a new iterator
|
||||
|
|
Loading…
Reference in a new issue