Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TyperError: this.adapter.isFiltered is not a function #6

Closed
csmcgee opened this issue Jul 23, 2020 · 11 comments · Fixed by #10
Closed

TyperError: this.adapter.isFiltered is not a function #6

csmcgee opened this issue Jul 23, 2020 · 11 comments · Fixed by #10

Comments

@csmcgee
Copy link

csmcgee commented Jul 23, 2020

I was attempting to use the RBAC management api and noticed that the delete was not persisting (autosave I guess doesn't work for deleteUser). So I attempted to use savePolicy and got the following error:

    TypeError: this.adapter.isFiltered is not a function

      46 |     const enforcer = await getInstance();
      47 |     const result = await enforcer.deleteUser(user.id);
    > 48 |     await enforcer.savePolicy();
         |                    ^
      49 |     return result;
      50 |   },
      51 | 

      at Enforcer.isFiltered (node_modules/casbin/lib/coreEnforcer.js:175:33)
      at Enforcer.<anonymous> (node_modules/casbin/lib/coreEnforcer.js:185:22)
      at node_modules/casbin/lib/coreEnforcer.js:21:71
      at __awaiter (node_modules/casbin/lib/coreEnforcer.js:17:12)
      at Enforcer.savePolicy (node_modules/casbin/lib/coreEnforcer.js:184:16)
      at Object.removeUser (api/services/AuthorizationService.js:48:20)
      at Object.<anonymous> (tests/services/authorization.test.js:79:3)

Diving deeper I noticed that node-casbin expects isFiltered to be a function see https://github.com/casbin/node-casbin/blob/master/src/coreEnforcer.ts#L184.

  public isFiltered(): boolean {
    if ('isFiltered' in this.adapter) {
      return this.adapter.isFiltered();
    }
    return false;
  }

Current state of isFiltered in the adapter.

Workaround for those interested:

  adapter = await MongoAdapter.newAdapter({
    // config for mongo here
  });
  // workaround
  delete adapter.isFiltered;
  // casbin initialization
  enforcer = await casbin.newEnforcer(model, adapter);

I'm not currently using filtered yet... so I'm not sure how useful this will be to anyone.

@csmcgee
Copy link
Author

csmcgee commented Jul 31, 2020

After reviewing this more with other devs. I have found that really if this MongoAdapter is meant to be a FilteredAdapter then maybe we should consider implementing FilteredAdapter casbin source interface.

So instead of

MongoAdapter implements Adapter

it should be

MongoAdapter implements FilteredAdapter

then adjust to that interface accordingly.

@hsluoyz
Copy link

hsluoyz commented Jul 31, 2020

@juicycleff

@sapcik
Copy link

sapcik commented Oct 2, 2020

Any news on that?

@hsluoyz
Copy link

hsluoyz commented Oct 2, 2020

@sapcik It seems that the developer is inactive for some time. You can take a look at theother 2 MongoDB adapters at: https://casbin.org/docs/en/adapters

image

@Casa-Cloud
Copy link

Casa-Cloud commented Feb 4, 2021

True, I am getting the issue of auto-save not working for deleted policies. it forces me to use enforcer.savePolicy() method to push all the policies to MongoDB which takes a lot of time to process. The expectation was to get deleted policies auto-saved
with Cabin 5.0.1.

WIth Casbin 5.0.3 Exactly same issue - "this.adapter.isFiltered is not a function" is showing while using enforcer.savePolicy()

Due to this reason, I am completely blocked. Cannot use this adapter as this is not getting updated with the latest casbin.
As said above Developer is inactive now. Need to switch to a different adapter.

@hsluoyz
Copy link

hsluoyz commented Feb 4, 2021

ping @juicycleff

@hsluoyz
Copy link

hsluoyz commented Feb 4, 2021

@alokadhao20 are you claiming the same issue about FilteredAdapter? If not, please send a new issue.

@Casa-Cloud
Copy link

Casa-Cloud commented Feb 4, 2021

Yes @hsluoyz

@17bit
Copy link
Contributor

17bit commented Feb 14, 2021

@juicycleff @alokadhao20 @csmcgee

isFiltered in a function in casbin-filter
This is simply because isFiltered is overwrited in https://github.com/juicycleff/casbin-mongodb-adapter/blob/master/src/lib/adapter.ts#L60

@juicycleff
Copy link
Owner

Hi all, I am looking at fixing this today. Will make an update at the end of today

17bit added a commit to 17bit/casbin-mongodb-adapter that referenced this issue Feb 14, 2021
fix: juicycleff#6 
TypeError: this.adapter.isFiltered is not a function
@17bit 17bit mentioned this issue Feb 14, 2021
@17bit
Copy link
Contributor

17bit commented Feb 14, 2021

Hi all, I am looking at fixing this today. Will make an update at the end of today

Please see #10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants