dry-scarletD
Refine2y ago
9 replies
dry-scarlet

Acces Control using Casbin and Antd

import { newModel, StringAdapter } from "casbin";

export const model = newModel(`
[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, obj, act, eft

[role_definition]
g = _, _

[policy_effect]
e = some(where (p.eft == allow)) && !some(where (p.eft == deny))

[matchers]
m = g(r.sub, p.sub) && keyMatch(r.obj, p.obj) && regexMatch(r.act, p.act)
`);

export const adapter = new StringAdapter(`
p, admin, posts, (list)|(create)
p, admin, posts/*, (edit)|(show)|(delete)
p, admin, posts/*, field

p, admin, users, (list)|(create)
p, admin, users/*, (edit)|(show)|(delete)

p, admin, categories, (list)|(create)
p, admin, categories/*, (edit)|(show)|(delete)

p, editor, posts, (list)|(create)
p, editor, posts/*, (edit)|(show)
p, editor, posts/hit, field, deny

p, editor, categories, list

`);


i have few question about this access control using casbin and antd design:
1. is there any way to make the menu disapear instead of disabled when some role can't acces it?
2. in the example i realize that editor role can't see hit field in the posts list. I thought it related to "p, editor, posts/hit, field, deny" but when i delete the code it still not show up in the editor view? How to hide certain field for certain role?
3. i hope further explaination about how this two code work "p, admin, posts/*, field" and "p, editor, posts/hit, field, deny"
Was this page helpful?