KS5017
An @inject() takes a record of a model that has a policy, and nothing asks the policy. The record reaches the component or type whoever is asking. Write the ability to ask, or check where the record is used:
<import package="KScript.Data" />
<import package="KScript.Auth" />
<model name="Post">
<field name="title" type="string" />
<field name="published" type="bool" default="false" />
</model>
<policy for="Post">
<fn name="read" params="user: map?, post: Post" value="$post.published or $user != null" />
</policy>
<fn name="heading" value="@inject(Post).title" /> <!-- warning: Post has a policy -->import KScript.Data
import KScript.Auth
model Post {
title: string
published: bool = false
}
policy for Post {
fn read(user: map?, post: Post) => $post.published or $user != null
}
fn heading() => @inject(Post).title // warning: Post has a policy@inject(Post, can: read) asks the policy as the record is taken, and answers 403 when it says no. As an input's default it is construct({ post: Post = @inject(can: read) }).