generated from alphane/template
58 lines
1.1 KiB
TypeScript
58 lines
1.1 KiB
TypeScript
import { Attributes, FindOptions } from "@sequelize/core"
|
|
|
|
import { BlogPost, User } from "@/models"
|
|
import { ALL_RECORDS_SCOPE, PolicyFactory } from "@/policies/base-policy"
|
|
import { Path } from "@/utils/deep-pick"
|
|
|
|
export class BlogPostsPolicy extends PolicyFactory(BlogPost) {
|
|
show(): boolean {
|
|
if (this.user.isSystemAdmin) {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
create(): boolean {
|
|
if (this.user.isSystemAdmin) {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
update(): boolean {
|
|
if (this.user.isSystemAdmin) {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
destroy(): boolean {
|
|
if (this.user.isSystemAdmin) {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
permittedAttributes(): Path[] {
|
|
return ["title", "slug", "content", "tags", "publishedAt"] as (keyof Attributes<BlogPost>)[]
|
|
}
|
|
|
|
permittedAttributesForCreate(): Path[] {
|
|
return [...this.permittedAttributes()]
|
|
}
|
|
|
|
permittedAttributesForUpdate(): Path[] {
|
|
return [...this.permittedAttributes()]
|
|
}
|
|
|
|
static policyScope(_user: User): FindOptions<Attributes<BlogPost>> {
|
|
return ALL_RECORDS_SCOPE
|
|
}
|
|
}
|
|
|
|
export default BlogPostsPolicy
|