The policy name, lowercase kebab-case and unique in the
application (validated when DecoratorPlugin registers the class)
A standard class decorator
@Policy('post')
@Inject('posts')
class PostPolicy {
constructor(private readonly posts: PostRepository) {}
before(principal: IPrincipal): boolean | undefined {
return principal.roles?.includes('admin') ? true : undefined;
}
@Ability()
update(principal: IPrincipal, post: Post | undefined): boolean {
return post?.authorId === principal.id;
}
@Ability({ anonymous: true })
read(_principal: IPrincipal | null, post: Post | undefined): boolean {
return post?.published === true;
}
}
Marks a class as an authorization policy named
name.