casbin-rs / sqlx-adapter

Asynchronous casbin adapter for mysql, postgres, sqlite based on sqlx-rs

Home Page:https://github.com/casbin/casbin-rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 can you make a PR?

@andoriyu can you make a PR?

@hsluoyz sure I will try to put it together later today (PDT).

Would you be open if I change casbin-rs API a bit? (not in this PR)

Right now, Rule is Vec<String>. I can make polymorphic and accept things like: [String; N], tuples with up to 6 values etc.

@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.

@andoriyu no breaking change then OK!