RbacApi::delete_permissions_for_user seems to be no-op
andoriyu opened this issue · comments
Always returns false
and sqlx shows zero queries made in database. Permissions don't get deleted.
RbacApi::delete_permission_for_user
does work as expected.
Crate versions:
casbin = "2.0.9"
sqlx-adapter = { version = "0.4.2", default-features = false, features = ["runtime-tokio-native-tls", "sqlite"] }
Using debugger, I narrowed down the issue to this area of the code:
async fn remove_filtered_policy(
&mut self,
_sec: &str,
pt: &str,
field_index: usize,
field_values: Vec<String>,
) -> Result<bool> {
if field_index <= 5 && !field_values.is_empty() && field_values.len() >= 6 - field_index {
adapter::remove_filtered_policy(&self.pool, pt, field_index, field_values).await
} else {
Ok(false)
}
}
field_values.len()
is 0, so it short circuits to Ok(false)
branch.
I think a way to fix it is to change adapter::remove_filtered_policy
to accept vectors of any length and change query based on length.
@andoriyu we should not introduce breaking change. But we can add appropriate new APIs.
@hsluoyz the I was thinking doing would keep backward compatibility, just in addition to Vec<String>
in will take other things.