Skip to content

Commit 183c1e1

Browse files
authored
chore: add model validate method (#374)
* feat: validate and compile matcher when loading model * feat: add model validate method Signed-off-by: Taoyuesong <[email protected]> --------- Signed-off-by: Taoyuesong <[email protected]>
1 parent acd8715 commit 183c1e1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Casbin/Model/DefaultModel.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,18 @@ private void LoadRoleAssertion(string type, RoleAssertion assertion)
156156
ExpressionHandler.SetFunction(type, BuiltInFunctions.GenerateGFunction(
157157
assertion.RoleManager, GFunctionCachePool.GetCache(type)));
158158
}
159+
160+
public bool Validate()
161+
{
162+
// Required sections check.
163+
if (Sections.ContainsSection(PermConstants.Section.RequestSection) is false ||
164+
Sections.ContainsSection(PermConstants.Section.PolicySection) is false ||
165+
Sections.ContainsSection(PermConstants.Section.PolicyEffectSection) is false ||
166+
Sections.ContainsSection(PermConstants.Section.MatcherSection) is false)
167+
{
168+
return false;
169+
}
170+
return true;
171+
}
159172
}
160173
}

0 commit comments

Comments
 (0)