[英]CASL behavior if subject has no rules
When not providing any rule for a given subject in CASL checking an ability for this subject always returns false.当CASL 中没有为给定主题提供任何规则时,检查该主题的能力总是返回 false。
Eg例如
import { Ability } from '@casl/ability'; const ability = new Ability({ action: "read", subject: "FirstSubject", // no rule for SecondSubject }); ability.can("read", "FirstSubject"); // true ability.can("write", "FirstSubject"); // false ability.can("read", "SecondSubject"); // false <-- These two lines should ability.can("write", "SecondSubject"); // false <-- return `true`
Is it possible to change this behavior in a way that the ability returns true
for subjects that do not have any rules?是否有可能以这种能力对没有任何规则的对象返回true
的方式改变这种行为?
In my use case I have a very large amount of subjects and new ones can be added dynamically.在我的用例中,我有大量的主题,可以动态添加新主题。 It would be difficult to always having to add { action: "manage", subject: "NewSubject"}
whenever a new subject is added.每当添加新主题时,总是不得不添加{ action: "manage", subject: "NewSubject"}
是很困难的。 I would rather like to only add rules for subjects where something is actually restricted.我宁愿只为实际受到限制的主题添加规则。
根据与 CASL 作者的聊天,这是不可能实现的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.