-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
demonstrate how to forbid certain slugs #59
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module.exports = { | ||
options: { | ||
forbiddenSlugs: [ | ||
'/evil-page', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this list to suit your needs. |
||
'evil-piece' | ||
] | ||
}, | ||
handlers(self) { | ||
return { | ||
beforeSave: { | ||
checkForbiddenSlugs(req, doc) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Each |
||
if (self.options.forbiddenSlugs.includes(doc.slug)) { | ||
const e = self.apos.error('invalid', 'That slug is reserved.'); | ||
e.path = 'slug'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tag the error with its path in the schema (the name of the field concerned). |
||
throw self.apos.error('invalid', { | ||
errors: [ | ||
e | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Including it in an |
||
] | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Placing this file in
modules/@apostrophecms/doc-type/index.js
causes Apostrophe to load it as additional configuration for@apostrophecms/doc-type
, the base class of all modules.