Repository navigation
Conversation
Contributor
|
Landed on 2.4-main via #1953, with the write operations folded into entriesv1_0.php rather than a v1.1 file (the loader would have made v1.1 the default for unversioned callers), plus the review fixes: nested-set-safe category delete, normalised alias on update, extension-wide alias check, route variables not taken from the JSON body, and field validation. |
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.
v1.0 of the knowledge base API is read-only. This adds a v1.1 controller that
keeps both of its tasks — with an ordinary caller's visibility unchanged: a
published article, in a published category, at an access level they hold — and
adds create, update and delete for articles and for the categories they sit in.
Writes are gated on
core.admin, so a Super User only. That is stricter thanthe admin UI, which needs
core.manageon com_kb; the site has no authoringinterface for the knowledge base at all, so this holds the API to the stricter
of the two. A Super User also sees unpublished content, which they need in
order to manage it.
Routes
The component's existing
router.phpis unchanged. It hands a second pathsegment to the task rather than to an id, so there is no
/kb/categories/{id}to route; the category is named by
?id=and the method picks the action./v1.1/kb/list/v1.1/kb/{id}/v1.1/kb/v1.1/kb/{id}/v1.1/kb/{id}/v1.1/kb/categories?id=reads one)/v1.1/kb/categories/v1.1/kb/categories?id=/v1.1/kb/categories?id=Bodies may be form-encoded or JSON. Updates apply only the fields the request
carries.
Notes for review
Category writes go through
com_categories' ownNestedmodel, since that iswhat keeps the nested set, the materialised path the site routes on, and the
access asset in step. Three things fell out of that:
setNameSpace('com_kb')on every save. Without it the row's asset is namedcom_.category.Nand never matches thecom_kb.category.Nthe ACL checksask for. The admin only does this when a Super User posts permission rules.
Nested::destroy()does not remove its descendants' assets — it builds eachname from a namespace those blank models do not have — so
deleteCategory()sweeps them by name afterwards.
saveAsChildOf()when the parent actually changed.Calling it unconditionally, as the admin does, moves a category to the end of
its siblings every time anyone edits it.
Alias uniqueness is enforced (within the category for articles, among siblings
for categories) because the site resolves both by alias, so a duplicate leaves
one row unreachable.
COM_KB_ERROR_ALIAS_IN_USEalready existed in the adminstrings but was never checked.
API-only strings live in a new
api/language/en-GB/rather than in the site's,following com_blog and com_activity. That directory makes
Lang::load('com_kb')succeed in the API app, which short-circuits v1.0's fallback to the site file,
so it also carries
COM_KB_ERROR_ARTICLE_NOT_FOUNDandCOM_KB_ERROR_CATEGORY_NOT_FOUND. v1.0 is otherwise untouched and stillresolves them.
Testing
Exercised against a local hub: full CRUD for both types, nested creates, moves
with descendant path rebuilds, and the guards (409 on duplicate alias, on
deleting a category that still holds articles, and on reparenting a category
beneath itself; 422 on a missing title; 400 on a malformed JSON body; 404 on an
unknown category). The nested set stayed contiguous and other extensions'
categories were untouched; an article created through the API renders on the
site at its real URL and follows its category when moved. Guests and a
non-Super-User in the Administrator group get 403 on every write while still
listing what they may see.
/api/v1.0/kb/listand unversioned/api/kb/listare unaffected.
🤖 Generated with Claude Code