Giter Club home page Giter Club logo

casbin-mongoose-adapter's People

Contributors

exigentcoder avatar ghaiklor avatar hsluoyz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

casbin-mongoose-adapter's Issues

FilteredAdapter should not dynamically change to ordinary Adapter

When creating a FilteredAdapter with MongooseAdapter.newFilteredAdapter(config.db) it is expected to stay as FilteredAdapter. However current behaviour is that it changes dynamically during execution

this.setFiltered(false);

Now the problem is that when a filtered adapter is first created casbin internally calls loadPolicy(model)

async loadPolicy (model) {

which switches it back to an ordinary adapter. Then if a user calls enforcer.loadFilteredPolicy() casbin throws an error, as it does not recognize the adapter to be filtered anymore
https://github.com/casbin/node-casbin/blob/40dd90a6dd7a023746bc3c15593d96d802c612ab/src/coreEnforcer.ts#L164

I think loadPolicy() should work without changing the adapter type.

SavePolicy should be a transaction

https://github.com/elasticio/casbin-mongoose-adapter/blob/master/src/adapter.js#L197
General idea of this function is to save whole policy file or nothing. Now it will save part of it if it fails a half way through.

However standard mongoDB multi-document transaction is only supported by replicas and/or shards. I'm not sure whether to fix it by using different outsourced library (mongoose-transaction), just use a try-catch-finally setup to just delete already saved documents or just disable this function if replica / shard is not found.

[Feature Request] Ability to close connection

Firstly thanks for putting this together, works really well!

I'm using the adapter in some tests and the tests fail to exit because the mongodb connection is still open, i'd like a way to call something like adapter.close() on the instance.

This would also be useful outside of automated tests to allow for graceful shutdown of an app.

This repo is unmaintained, it's forked by official Casbin team: https://github.com/node-casbin/mongoose-adapter ?

Hi guys, the original author ghaiklor of this repo has left elasticio and this repo is left unmaintained for long time.

Therefore, the official Casbin team has forked this repo to: https://github.com/node-casbin/mongoose-adapter and is actively maintaining it for fixing bugs, add new features. But it seems there are still some people come to this repo, create issues with no feedback.

So for the better of Casbin users, can we move this repo to Casbin officially? (given that Casbin has a working fork now, it's similar like deleting this repo, making it private or at least archiving this repo and make some pointer to the new one). So people will not get lost. What do you say? Thanks!

Tag last master version ?

Hello,

Thanks you for your work.
Could you tag the last master version please ?

At least the version which includes the close() method which is required for most of integration in order to properly close the mongodb connection ?

Thanks a lot.

Can't delete roles

Hi, i've used this mongoose adapter to handle rules in mongodb, I can't delete roles, what i'm doing wrong?

static async getInstance() {
    const adapter = await Adapter.newAdapter(db.uri, db.config);
    const model = `${process.env.STORAGE_PATH}/casbin/rbac.conf`;
    return casbin.newEnforcer(model, adapter);
  }

Assign roles works properly.

static async assignRole(identifier, role, domain = '*') {
    const enforcer = await Enforcer.getInstance();
    return enforcer.addRoleForUser(identifier, role, domain);
  }

deleteRoleForUser returns false

static async revokeRole(identifier, role, domain = 'admin') {
    const enforcer = await Enforcer.getInstance();
    console.log(identifier, role, domain);
    return enforcer.deleteRoleForUser(identifier, role);
  }

deleteRolesForUser returns false

static async revokeRoles(identifier) {
    const enforcer = await Enforcer.getInstance();
    return enforcer.deleteRolesForUser(identifier);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.