Skip to content
This repository was archived by the owner on Feb 18, 2020. It is now read-only.

Latest commit

 

History

History
193 lines (141 loc) · 8.2 KB

File metadata and controls

193 lines (141 loc) · 8.2 KB

MongooseAdapter

Implements a policy adapter for casbin with MongoDB support.

Kind: global class

new MongooseAdapter(uri, [options])

Creates a new instance of mongoose adapter for casbin. It does not wait for successfull connection to MongoDB. So, if you want to have a possibility to wait until connection successful, use newAdapter instead.

Param Type Default Description
uri String Mongo URI where casbin rules must be persisted
[options] Object {} Additional options to pass on to mongoose client

mongooseAdapter.setFiltered([isFiltered])

Switch adapter to (non)filtered state. Casbin uses this flag to determine if it should load the whole policy from DB or not.

Kind: instance method of MongooseAdapter

Param Type Default Description
[isFiltered] Boolean true Flag that represents the current state of adapter (filtered or not)

mongooseAdapter.loadPolicyLine(line, model)

Loads one policy rule into casbin model. This method is used by casbin and should not be called by user.

Kind: instance method of MongooseAdapter

Param Type Description
line Object Record with one policy rule from MongoDB
model Object Casbin model to which policy rule must be loaded

mongooseAdapter.loadPolicy(model) ⇒ Promise.<void>

Implements the process of loading policy from database into enforcer. This method is used by casbin and should not be called by user.

Kind: instance method of MongooseAdapter

Param Type Description
model Model Model instance from enforcer

mongooseAdapter.loadFilteredPolicy(model, [filter])

Loads partial policy based on filter criteria. This method is used by casbin and should not be called by user.

Kind: instance method of MongooseAdapter

Param Type Description
model Model Enforcer model
[filter] Object MongoDB filter to query

mongooseAdapter.savePolicyLine(ptype, rule) ⇒ Object

Persists one policy rule into MongoDB. This method is used by casbin and should not be called by user.

Kind: instance method of MongooseAdapter
Returns: Object - Returns a created CasbinRule record for MongoDB

Param Type Description
ptype String Policy type to save into MongoDB
rule Array.<String> An array which consists of policy rule elements to store

mongooseAdapter.savePolicy(model) ⇒ Promise.<Boolean>

Implements the process of saving policy from enforcer into database. This method is used by casbin and should not be called by user.

Kind: instance method of MongooseAdapter

Param Type Description
model Model Model instance from enforcer

mongooseAdapter.addPolicy(sec, ptype, rule) ⇒ Promise.<void>

Implements the process of adding policy rule. This method is used by casbin and should not be called by user.

Kind: instance method of MongooseAdapter

Param Type Description
sec String Section of the policy
ptype String Type of the policy (e.g. "p" or "g")
rule Array.<String> Policy rule to add into enforcer

mongooseAdapter.removePolicy(sec, ptype, rule) ⇒ Promise.<void>

Implements the process of removing policy rule. This method is used by casbin and should not be called by user.

Kind: instance method of MongooseAdapter

Param Type Description
sec String Section of the policy
ptype String Type of the policy (e.g. "p" or "g")
rule Array.<String> Policy rule to remove from enforcer

mongooseAdapter.removeFilteredPolicy(sec, ptype, fieldIndex, ...fieldValues) ⇒ Promise.<void>

Implements the process of removing policy rules. This method is used by casbin and should not be called by user.

Kind: instance method of MongooseAdapter

Param Type Description
sec String Section of the policy
ptype String Type of the policy (e.g. "p" or "g")
fieldIndex Number Index of the field to start filtering from
...fieldValues String Policy rule to match when removing (starting from fieldIndex)

MongooseAdapter.newAdapter(uri, [options])

Creates a new instance of mongoose adapter for casbin. Instead of constructor, it does wait for successfull connection to MongoDB. Preferable way to construct an adapter instance, is to use this static method.

Kind: static method of MongooseAdapter

Param Type Default Description
uri String Mongo URI where casbin rules must be persisted
[options] Object {} Additional options to pass on to mongoose client

Example

const adapter = await MongooseAdapter.newAdapter('MONGO_URI');
const adapter = await MongooseAdapter.newAdapter('MONGO_URI', { mongoose_options: 'here' });

MongooseAdapter.newFilteredAdapter(uri, [options])

Creates a new instance of mongoose adapter for casbin. It does the same as newAdapter, but it also sets a flag that this adapter is in filtered state. That way, casbin will not call loadPolicy() automatically.

Kind: static method of MongooseAdapter

Param Type Default Description
uri String Mongo URI where casbin rules must be persisted
[options] Object {} Additional options to pass on to mongoose client

Example

const adapter = await MongooseAdapter.newFilteredAdapter('MONGO_URI');
const adapter = await MongooseAdapter.newFilteredAdapter('MONGO_URI', { mongoose_options: 'here' });