casbin / node-casbin

An authorization library that supports access control models like ACL, RBAC, ABAC in Node.js and Browser
https://casbin.org
Apache License 2.0
2.57k stars 214 forks source link

logger print exception #327

Open gensir opened 2 years ago

gensir commented 2 years ago

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch casbin@5.11.5 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/casbin/lib/cjs/coreEnforcer.js b/node_modules/casbin/lib/cjs/coreEnforcer.js
index b9e4f06..9e9ff26 100644
--- a/node_modules/casbin/lib/cjs/coreEnforcer.js
+++ b/node_modules/casbin/lib/cjs/coreEnforcer.js
@@ -158,6 +158,7 @@ class CoreEnforcer {
     async loadPolicy() {
         this.model.clearPolicy();
         await this.adapter.loadPolicy(this.model);
+        this.model.printPolicy();
         this.sortPolicies();
         if (this.autoBuildRoleLinks) {
             await this.buildRoleLinksInternal();
diff --git a/node_modules/casbin/lib/cjs/rbac/defaultRoleManager.js b/node_modules/casbin/lib/cjs/rbac/defaultRoleManager.js
index 1db1411..c3a25db 100644
--- a/node_modules/casbin/lib/cjs/rbac/defaultRoleManager.js
+++ b/node_modules/casbin/lib/cjs/rbac/defaultRoleManager.js
@@ -285,8 +285,10 @@ class DefaultRoleManager {
      */
     async printRoles() {
         if (log_1.getLogger().isEnable()) {
-            [...this.allDomains.values()].forEach((n) => {
-                log_1.logPrint(n.toString());
+            [...this.allDomains.values()].forEach((roles) => {
+                roles.forEach(n => { 
+                    log_1.logPrint(n.toString());
+                });
             });
         }
     }

This issue body was partially generated by patch-package.

casbin-bot commented 2 years ago

@Gabriel-403 @Zxilly @kingiw @nodece

nodece commented 2 years ago

Do you want to print the policy data?

gensir commented 2 years ago
async printRoles() {
      if (log_1.getLogger().isEnable()) {
          [...this.allDomains.values()].forEach((roles) => {
              console.log(roles);// Roles(0) [Map] {}
              roles.forEach(n => { 
                  log_1.logPrint(n.toString());
              });
          });
      }
  }
hsluoyz commented 2 years ago

@gensir plz make a PR!

gensir commented 2 years ago

https://github.com/casbin/node-casbin/pull/330