Repository navigation
Replace the tags policy examples with the 2.x code they claim to be - #602
Open
karl-bullock wants to merge 1 commit into
Open
karl-bullock wants to merge 1 commit into
karl-bullock wants to merge 1 commit into
Conversation
Both examples in Example Policies are 1.x code presented as current Flarum Tags source, and the page links to that source, so a reader who follows the link finds something quite different. The GlobalPolicy sample calls Tag::getIdsWhereCan(), which does not exist anywhere in 2.x, and reads un-namespaced settings (min_primary_tags rather than flarum-tags.min_primary_tags), so it is not merely dated but would not run. It is replaced by a simplified policy built from real APIs: a nullable-string return, the namespaced setting, and the Tag::whereHasPermission scope. A note says plainly that it is simplified and why the real one is more involved, rather than pretending the real implementation is this short. The TagPolicy sample defined one method per ability and wrapped hasPermission in a ternary. The real one uses the can() catch-all so a single method serves every ability, inherits restrictions from a parent tag, and returns the boolean from hasPermission directly, since AbstractPolicy::sanitizeResult turns true and false into allow() and deny(). Those are the two habits worth copying from it, so the sample now shows them and the prose points them out. The intro line is deliberately untouched, because flarum#592 corrects the branch in its link.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both code samples under Example Policies are 1.x code presented as current Flarum Tags source, and the page links to that source, so a reader who follows the link finds something quite different from what they were just shown.
GlobalPolicy: the sample would not run
Tag::getIdsWhereCan()does not exist anywhere in 2.x, and the setting keys lost their namespace at some point (flarum-tags.min_primary_tagsnow). So this is not merely dated: copying it produces a fatal.It is replaced with a simplified policy assembled from real APIs, a
?stringreturn, the namespaced setting, and theTag::whereHasPermissionscope. I have not pretended the real implementation is that short: a note says it is simplified, and that the real one also handles secondary tags, short-circuits onbypassTagCounts, memoizes its verdict per actor and ability, and counts both tag kinds in one aggregate query, which matters because a global policy runs on a great many requests.TagPolicy: the sample misses the two things worth learning from it
The old sample defines one method per ability (
startDiscussion, thenaddToDiscussiondelegating to it) and wrapshasPermissionin a ternary. The real one does neither:can()catch-all, so a single method serves every ability. The page already explains that mechanism a few paragraphs earlier, and this is the example that should demonstrate it.hasPermissiondirectly, becauseAbstractPolicy::sanitizeResultconvertstrueandfalseintoallow()anddeny(). The ternary is noise.The sample now matches the real class, and the prose points out those two habits rather than leaving the reader to notice them.
Note on overlap
The introductory line above the first sample is deliberately untouched, because #592 corrects the branch in its link (
blob/mastertoblob/2.x). That matters here: once that link points at 2.x, the mismatch between the page and the linked source becomes obvious, which is how I found this. I verified this branch and #592 merge cleanly.Verified with
npx docusaurus build --locale en: no errors, and no anchors broken by this change (the two the build reports on these pages are pre-existing and fixed by #592).