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:
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
docs/menu-permissions/
Example for Menu Permissions
https://casbin.org/docs/menu-permissions/
Beta Was this translation helpful? Give feedback.
All reactions