juicycleff / casbin-mongodb-adapter

Pure MongoDB adapter for Casbin
MIT License
9 stars 14 forks source link

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

Closed csmcgee closed 3 years ago

csmcgee commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

@juicycleff

sapcik commented 3 years ago

Any news on that?

hsluoyz commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

ping @juicycleff

hsluoyz commented 3 years ago

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

Casa-Cloud commented 3 years ago

Yes @hsluoyz

17bit commented 3 years ago

@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 commented 3 years ago

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

17bit commented 3 years ago

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

Please see https://github.com/juicycleff/casbin-mongodb-adapter/pull/10