@@ -26,7 +26,7 @@ export interface MongooseAdapterOptions {
26
26
}
27
27
28
28
export interface policyLine {
29
- p_type ?: string ,
29
+ ptype ?: string ,
30
30
v0 ?: string ,
31
31
v1 ?: string ,
32
32
v2 ?: string ,
@@ -272,7 +272,7 @@ export class MongooseAdapter implements BatchAdapter, FilteredAdapter, Updatable
272
272
* @param {Object } model Casbin model to which policy rule must be loaded
273
273
*/
274
274
loadPolicyLine ( line : policyLine , model : Model ) {
275
- let lineText = `${ line . p_type ! } ` ;
275
+ let lineText = `${ line . ptype ! } ` ;
276
276
277
277
for ( const word of [ line . v0 , line . v1 , line . v2 , line . v3 , line . v4 , line . v5 ] ) {
278
278
if ( word !== undefined ) {
@@ -327,12 +327,12 @@ export class MongooseAdapter implements BatchAdapter, FilteredAdapter, Updatable
327
327
* This method is used by casbin to generate Mongoose Model Object for single policy
328
328
* and should not be called by user.
329
329
*
330
- * @param {String } ptype Policy type to save into MongoDB
330
+ * @param {String } pType Policy type to save into MongoDB
331
331
* @param {Array<String> } rule An array which consists of policy rule elements to store
332
332
* @returns {Object } Returns a created CasbinRule record for MongoDB
333
333
*/
334
- savePolicyLine ( ptype : string , rule : string [ ] ) {
335
- const model = new CasbinRule ( { p_type : ptype } ) ;
334
+ savePolicyLine ( pType : string , rule : string [ ] ) {
335
+ const model = new CasbinRule ( { ptype : pType } ) ;
336
336
337
337
if ( rule . length > 0 ) {
338
338
model . v0 = rule [ 0 ] ;
@@ -412,16 +412,16 @@ export class MongooseAdapter implements BatchAdapter, FilteredAdapter, Updatable
412
412
* This method is used by casbin and should not be called by user.
413
413
*
414
414
* @param {String } sec Section of the policy
415
- * @param {String } ptype Type of the policy (e.g. "p" or "g")
415
+ * @param {String } pType Type of the policy (e.g. "p" or "g")
416
416
* @param {Array<String> } rule Policy rule to add into enforcer
417
417
* @returns {Promise<void> }
418
418
*/
419
- async addPolicy ( sec : string , ptype : string , rule : string [ ] ) {
419
+ async addPolicy ( sec : string , pType : string , rule : string [ ] ) {
420
420
const options : sessionOption = { } ;
421
421
try {
422
422
if ( this . isSynced ) options . session = await this . getTransaction ( ) ;
423
423
424
- const line = this . savePolicyLine ( ptype , rule ) ;
424
+ const line = this . savePolicyLine ( pType , rule ) ;
425
425
await line . save ( options ) ;
426
426
427
427
this . autoCommit && options . session && await options . session . commitTransaction ( ) ;
@@ -436,16 +436,16 @@ export class MongooseAdapter implements BatchAdapter, FilteredAdapter, Updatable
436
436
* This method is used by casbin and should not be called by user.
437
437
*
438
438
* @param {String } sec Section of the policy
439
- * @param {String } ptype Type of the policy (e.g. "p" or "g")
439
+ * @param {String } pType Type of the policy (e.g. "p" or "g")
440
440
* @param {Array<String> } rules Policy rule to add into enforcer
441
441
* @returns {Promise<void> }
442
442
*/
443
- async addPolicies ( sec : string , ptype : string , rules : Array < string [ ] > ) {
443
+ async addPolicies ( sec : string , pType : string , rules : Array < string [ ] > ) {
444
444
const options : sessionOption = { } ;
445
445
if ( this . isSynced ) options . session = await this . getTransaction ( ) ;
446
446
else throw new InvalidAdapterTypeError ( 'addPolicies is only supported by SyncedAdapter. See newSyncedAdapter' ) ;
447
447
try {
448
- const promises = rules . map ( async rule => this . addPolicy ( sec , ptype , rule ) ) ;
448
+ const promises = rules . map ( async rule => this . addPolicy ( sec , pType , rule ) ) ;
449
449
await Promise . all ( promises ) ;
450
450
451
451
this . autoCommit && options . session && await options . session . commitTransaction ( ) ;
@@ -460,19 +460,19 @@ export class MongooseAdapter implements BatchAdapter, FilteredAdapter, Updatable
460
460
* This method is used by casbin and should not be called by user.
461
461
*
462
462
* @param {String } sec Section of the policy
463
- * @param {String } ptype Type of the policy (e.g. "p" or "g")
463
+ * @param {String } pType Type of the policy (e.g. "p" or "g")
464
464
* @param {Array<String> } oldRule Policy rule to remove from enforcer
465
465
* @param {Array<String> } newRule Policy rule to add into enforcer
466
466
* @returns {Promise<void> }
467
467
*/
468
- async updatePolicy ( sec : string , ptype : string , oldRule : string [ ] , newRule : string [ ] ) {
468
+ async updatePolicy ( sec : string , pType : string , oldRule : string [ ] , newRule : string [ ] ) {
469
469
const options : sessionOption = { } ;
470
470
try {
471
471
if ( this . isSynced ) options . session = await this . getTransaction ( ) ;
472
- const { p_type , v0, v1, v2, v3, v4, v5} = this . savePolicyLine ( ptype , oldRule ) ;
473
- const newRuleLine = this . savePolicyLine ( ptype , newRule ) ;
472
+ const { ptype , v0, v1, v2, v3, v4, v5} = this . savePolicyLine ( pType , oldRule ) ;
473
+ const newRuleLine = this . savePolicyLine ( pType , newRule ) ;
474
474
const newModel = {
475
- p_type : newRuleLine . p_type ,
475
+ ptype : newRuleLine . ptype ,
476
476
v0 : newRuleLine . v0 ,
477
477
v1 : newRuleLine . v1 ,
478
478
v2 : newRuleLine . v2 ,
@@ -481,7 +481,7 @@ export class MongooseAdapter implements BatchAdapter, FilteredAdapter, Updatable
481
481
v5 : newRuleLine . v5
482
482
}
483
483
484
- await CasbinRule . updateOne ( { p_type , v0, v1, v2, v3, v4, v5} , newModel , options ) ;
484
+ await CasbinRule . updateOne ( { ptype , v0, v1, v2, v3, v4, v5} , newModel , options ) ;
485
485
486
486
this . autoCommit && options . session && await options . session . commitTransaction ( ) ;
487
487
} catch ( err ) {
@@ -495,18 +495,18 @@ export class MongooseAdapter implements BatchAdapter, FilteredAdapter, Updatable
495
495
* This method is used by casbin and should not be called by user.
496
496
*
497
497
* @param {String } sec Section of the policy
498
- * @param {String } ptype Type of the policy (e.g. "p" or "g")
498
+ * @param {String } pType Type of the policy (e.g. "p" or "g")
499
499
* @param {Array<String> } rule Policy rule to remove from enforcer
500
500
* @returns {Promise<void> }
501
501
*/
502
- async removePolicy ( sec : string , ptype : string , rule : string [ ] ) {
502
+ async removePolicy ( sec : string , pType : string , rule : string [ ] ) {
503
503
const options : sessionOption = { } ;
504
504
try {
505
505
if ( this . isSynced ) options . session = await this . getTransaction ( ) ;
506
506
507
- const { p_type , v0, v1, v2, v3, v4, v5} = this . savePolicyLine ( ptype , rule ) ;
507
+ const { ptype , v0, v1, v2, v3, v4, v5} = this . savePolicyLine ( pType , rule ) ;
508
508
509
- await CasbinRule . deleteMany ( { p_type , v0, v1, v2, v3, v4, v5} , options ) ;
509
+ await CasbinRule . deleteMany ( { ptype , v0, v1, v2, v3, v4, v5} , options ) ;
510
510
511
511
this . autoCommit && options . session && await options . session . commitTransaction ( ) ;
512
512
} catch ( err ) {
@@ -520,17 +520,17 @@ export class MongooseAdapter implements BatchAdapter, FilteredAdapter, Updatable
520
520
* This method is used by casbin and should not be called by user.
521
521
*
522
522
* @param {String } sec Section of the policy
523
- * @param {String } ptype Type of the policy (e.g. "p" or "g")
523
+ * @param {String } pType Type of the policy (e.g. "p" or "g")
524
524
* @param {Array<String> } rules Policy rule to remove from enforcer
525
525
* @returns {Promise<void> }
526
526
*/
527
- async removePolicies ( sec : string , ptype : string , rules : Array < string [ ] > ) {
527
+ async removePolicies ( sec : string , pType : string , rules : Array < string [ ] > ) {
528
528
const options : sessionOption = { } ;
529
529
try {
530
530
if ( this . isSynced ) options . session = await this . getTransaction ( ) ;
531
531
else throw new InvalidAdapterTypeError ( 'removePolicies is only supported by SyncedAdapter. See newSyncedAdapter' ) ;
532
532
533
- const promises = rules . map ( async rule => this . removePolicy ( sec , ptype , rule ) ) ;
533
+ const promises = rules . map ( async rule => this . removePolicy ( sec , pType , rule ) ) ;
534
534
await Promise . all ( promises ) ;
535
535
536
536
this . autoCommit && options . session && await options . session . commitTransaction ( ) ;
@@ -545,16 +545,16 @@ export class MongooseAdapter implements BatchAdapter, FilteredAdapter, Updatable
545
545
* This method is used by casbin and should not be called by user.
546
546
*
547
547
* @param {String } sec Section of the policy
548
- * @param {String } ptype Type of the policy (e.g. "p" or "g")
548
+ * @param {String } pType Type of the policy (e.g. "p" or "g")
549
549
* @param {Number } fieldIndex Index of the field to start filtering from
550
550
* @param {...String } fieldValues Policy rule to match when removing (starting from fieldIndex)
551
551
* @returns {Promise<void> }
552
552
*/
553
- async removeFilteredPolicy ( sec : string , ptype : string , fieldIndex : number , ...fieldValues : string [ ] ) {
553
+ async removeFilteredPolicy ( sec : string , pType : string , fieldIndex : number , ...fieldValues : string [ ] ) {
554
554
const options : sessionOption = { } ;
555
555
try {
556
556
if ( this . isSynced ) options . session = await this . getTransaction ( ) ;
557
- const where : policyLine = ptype ? { p_type : ptype } : { } ;
557
+ const where : policyLine = pType ? { ptype : pType } : { } ;
558
558
559
559
if ( fieldIndex <= 0 && fieldIndex + fieldValues . length > 0 && fieldValues [ 0 - fieldIndex ] ) {
560
560
where . v0 = fieldValues [ 0 - fieldIndex ] ;
0 commit comments