Repository navigation
Document the seven extenders that had no documentation at all - #597
karl-bullock wants to merge 2 commits into
Conversation
Auth, Csrf, ErrorHandling, Link, ModelPrivate, Session and Validator were not mentioned anywhere in the docs, nor were Settings::resetJsCacheFor and the Theme extender (Theme is covered separately). Each is given a home where a reader would look for it rather than collected into a reference dump. Three new pages. validation.md covers using and writing an AbstractValidator and extending someone else's with the Validator extender, and opens by distinguishing it from the field rules on API resources, which is where API input is actually validated in 2.0. It also records that DiscussionValidator, PostValidator, TagValidator, SuspendValidator and GroupValidator were removed in 2.0, along with the Validating event that used to be the way to adjust rules. error-handling.md explains the type and status pipeline, KnownError, custom handlers returning a HandledError, and reporters, with core's registered statuses as a table so an extension can reuse a type instead of inventing one. authentication.md covers password checkers, including why a checker should return null rather than false, and session drivers. Four additions to existing pages. formatting.md gains the Link extender, since it is the same TextFormatter layer the page already documents. middleware.md gains CSRF route exemption. settings.md gains resetJsCacheFor. model-visibility.md gains private models, which is where ModelPrivate belongs: its own docblock describes the pairing with a viewPrivate scoper, and flarum/approval is built on exactly that. Every signature, default and return contract comes from the class in flarum/framework@2.x. Security-sensitive extenders carry a warning where the failure mode is worse than a bug: removing the standard password checker can lock out every account, a CSRF-exempt route has to authenticate its caller some other way, and a privacy checker that stops matching will republish a model on its next save.
|
|
||
| ::: | ||
|
|
||
| ## Session Drivers |
There was a problem hiding this comment.
I'd be careful here... I understand where you're coming from, but we don't want to give the impression that setting the redis session driver by hand is a good thing.. fof/redis wraps all this so that the default Laravel implementation becomes compatible with Flarum's "quirks", for example
|
|
||
| return [ | ||
| (new Extend\ErrorHandling()) | ||
| ->reporter(SentryReporter::class), |
There was a problem hiding this comment.
Confused here, this would break the sentry extension, if overriding the reporter like this?
| use Psr\Http\Message\UriInterface; | ||
|
|
||
| return [ | ||
| (new Extend\Link()) |
There was a problem hiding this comment.
Might be best to call this out as an example, and note that fof/seo handles cases like this for the vast majority?
| ]) | ||
| ``` | ||
|
|
||
| ### Recompiling Assets When a Setting Changes |
There was a problem hiding this comment.
This is not needed after rc.8, 2.0.0 covers this nicely (see 2.x-dev)
…tJsCacheFor - Session drivers: do not suggest setting a redis driver by hand; Laravel's built-in drivers resolve but Flarum does not wire their cache stores. fof/redis is the supported route. Example driver renamed to acme. - Reporters: example no longer named SentryReporter; note fof/sentry exists and that a second Sentry reporter double-reports. - Link: frame as an example, point to fof/seo, note rel precedence, and correct when the URI is null. - Settings: remove the resetJsCacheFor section; its example paired it with a runtime-serialized setting, and 2.x flags assets dirty itself.
|
Thanks Ian, all four were fair. I made the doc changes and used AI to check every reference against my edits, and it got these wrong. I'm on it. |
|
Pushed:
|
Nine pieces of extender API were documented nowhere at all: the
Auth,Csrf,ErrorHandling,Link,ModelPrivate,SessionandValidatorextenders, plusSettings::registerLessConfigVarandSettings::resetJsCacheFor. This covers all of them exceptregisterLessConfigVar, which #594 documents alongside theThemeextender.Each one is put where a reader would go looking for it, rather than gathered into a reference dump.
Three new pages
extend/validation.mdcovers using a validator, writing one onAbstractValidator, and changing someone else's with theValidatorextender. It opens by separating this from field rules on API resources, because in 2.0 that is where API input is actually validated and the two are not interchangeable: field rules for anything arriving over the API,AbstractValidatorfor data you are about to save from a command, a job or a listener. It documents the 2.0 behaviour that only rules whose key is present in the passed array are applied, andvalidateMissingKeys()for when you want the opposite. It also records thatDiscussionValidator,PostValidator,TagValidator,SuspendValidatorandGroupValidatorwere removed in 2.0, and that theValidatingevent is gone, since an extension being ported will look for both.extend/error-handling.mdexplains the pipeline: an exception gets an error type and an HTTP status, the type is what selects a translated message or view, and anything unrecognised becomesunknown/500 and goes to the reporters. ThenKnownErrorfor your own exceptions,type()for third-party ones,status(), custom handlers returning aHandledErrorwith details, and reporters. Core's registered statuses are included as a table so an extension can reuse an existing type rather than invent a parallel one.extend/authentication.mdcovers password checkers and session drivers, and cross-references Authorization for the "what may they do" half. The checker return contract gets particular attention, becausenullandfalseare not interchangeable:nullmeans "no opinion, let other checkers run" andfalsehalts evaluation outright.Four additions to existing pages
formatting.mdgains theLinkextender. It belongs there rather than on a page of its own:Linkis implemented on top of theFormatterextender that page already documents, rewritingrelandtargetonURLtags at render time.middleware.mdgains CSRF route exemption, noting thatexemptRoute()takes the route's name and not its path.settings.mdgainsresetJsCacheFor.model-visibility.mdgains a "Private Models" section forModelPrivate. That is the right page for it: the extender's own docblock describes the pairing with aviewPrivatescoper, andflarum/approvalis built on exactly that combination, registeringModelPrivatecheckers forDiscussionandCommentPostand aviewPrivatescoper to reveal them.sidebars.jsregisters the three new pages: authentication beside authorization and validation beside forms under Reference Guides, error handling beside database under Advanced Guides.Where I added warnings
Four of these extenders fail in ways worse than a display bug, so each carries a short warning rather than being documented neutrally:
standardpassword checker makes the stored hash authenticate nobody, which can lock out every account including the admin account you would use to undo it.trueis a full authentication bypass if it is wrong, so the page says to usehash_equals(), not to log the plaintext, and to keep custom checkers narrow.is_privateboth ways, so one that stops matching will quietly republish a model.Verification
npx docusaurus build --locale encompletes with no errors and all three pages render. Docusaurus's broken-anchor check reports nothing for any page in this PR (model-visibility.mdhas one pre-existing broken anchor that #592 fixes, unrelated to the section added here). The sidebar resolves with no dangling entries.Every signature, default value and return contract was read from the class in
flarum/framework@2.x, including checking thatserializeToForumtakes the attribute name before the setting key, thatRoutes::posttakes path then name then handler, and thatModelVisibility::scopetakes the ability as its second argument.One note on prior art
While checking for overlap I found
as/validation, a branch from October 2020 with a completeextend/validation.mddraft that was never merged. It is 326 commits behind and its examples useGroupValidatorand theValidatingevent, both since removed, so I have not built on it, but the page it intended clearly wanted to exist and the structure here follows the same shape. Worth closing that branch if nobody is holding it. Same foras/post-typesfrom August 2020, relative to #594.