docs/menu-permissions/ #1375
Replies: 1 comment 1 reply
|
hello, can you tell me where was wrong? below is my test code, but i cant get the result as expected. func TestMenu(t *testing.T) {
f := getEnforcer(t, model_2, policy_2)
PERMS := []string{
"SystemMenu", // ✅ ❌ ❌
"UserMenu", // ❌ ✅ ✅
"UserSubMenu_allow", // ❌ ✅ ✅
"UserSubSubMenu", // ❌ ✅ ✅
"UserSubMenu_deny", // ❌ ✅ ❌
"AdminMenu", // ✅ ✅ ❌
"AdminSubMenu_allow", // ✅ ✅ ❌
"AdminSubMenu_deny", // ✅ ❌ ❌
}
ans := bufio.NewWriter(os.Stdout)
for _, obj := range PERMS {
ans.WriteString(obj + strings.Repeat(" ", 30-len(obj)))
for _, sub := range []string{"ROLE_ROOT", "ROLE_ADMIN", "ROLE_USER"} {
ok, err := f.Enforce(sub, obj, "read")
if ok {
ans.WriteString("✅ ")
} else {
ans.WriteString("❌ ")
}
if err != nil {
t.Fatal(err)
}
}
ans.WriteString("\n")
}
ans.Flush()
}the code output is: |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
docs/menu-permissions/
Example for Menu Permissions
https://casbin.org/docs/menu-permissions/
All reactions