Repository navigation
Bug 2094122 - Migrate extension WebService REST resources to native Mojo API - #2836
Conversation
…jo API POST /rest/invalid_bug_helper/close/<id> is now served by the native controller Bugzilla::Extension::InvalidBugHelper::API::V1::InvalidBugHelper instead of the legacy REST server. Same path, parameters, checks and response, mark_as_spam must now be a boolean. The legacy WebService module and its webservice hook are removed, and the extension test now goes through the real route.
GET /rest/bitly/shorten and GET /rest/bitly/list are now served by the native controller
Bugzilla::Extension::Bitly::API::V1::Bitly instead of the legacy REST server.
Same paths, url parameter, checks and {url} response.
The legacy WebService module and its webservice hook are removed, and a test covers
both routes.
… API GET /rest/prod_comp_search/find/<search> and GET /rest/prod_comp_search/frequent are now served by the native controller Bugzilla::Extension::ProdCompSearch::API::V1::ProdCompSearch instead of the legacy REST server. Same paths, limit parameter, queries and responses. The legacy WebService module and its webservice hook are removed, and a test covers both routes.
GET /rest/editcomments/comment[/<id>], PUT /rest/editcomments/comment/<id> and PUT /rest/editcomments/revision are now served by the native controller Bugzilla::Extension::EditComments::API::V1::EditComments instead of the legacy REST server. Same paths, parameters, checks and responses and is_hidden must now be a boolean (true/false/1/0). The legacy WebService module and its webservice hook are removed, and a test covers the four routes.
…ojo API GET and POST /rest/component-watching, GET and DELETE /rest/component-watching/<id> are now served by the native controller Bugzilla::Extension::ComponentWatching::API::V1::ComponentWatching instead of the legacy REST server. Same paths, parameters, checks and responses, except that product_access_denied now names the product (it was passed as product instead of name, so the message showed ''). The Preferences page gets the same fix. The legacy WebService module and its webservice hook are removed, and a test covers the four routes. rest_legacy_credentials.t moves to GET /rest/bug_modal/initial_field_values, still on the legacy server.
GET /rest/mydashboard/run_bug_query, run_flag_query and run_last_changes, and PUT /rest/mydashboard/bug_interest_unmark (also still served without the prefix) are now served by the native controller Bugzilla::Extension::MyDashboard::API::V1::MyDashboard instead of the legacy REST server. Same paths, parameters, checks and responses. The two query methods still read from the shadow database. The legacy WebService module and its webservice hook are removed, and a test covers the five routes.
query_flags meant to accept only requestee and requester, but its check (ne || ne) was always true, so any other type was treated as requester and returned under that key. It now throws param_invalid, and Queries.pm imports Bugzilla::Error, which that error path never needed before.
GET /rest/phabbugz/check_bug/<bug_id>/<user_id>, GET /rest/phabbugz/check_enter_bug/<product>/<user_id>, GET /rest/phabbugz/bug_revisions/<bug_id> and GET /rest/phabbugz/user/<user_id> are now served by the existing native controller Bugzilla::Extension::PhabBugz::API::V1::PhabBugz instead of the legacy REST server. Same paths, checks and responses. The three read-only ones still use the shadow database. The legacy WebService module and its webservice hook are removed, and webservice.t now calls the routes.
GET /rest/review/suggestions (by bug ID, product, product/component or query params) and GET /rest/review/flag_activity (by flag ID, type name, requestee, setter, type ID or query params) are now served by the native controller Bugzilla::Extension::Review::API::V1::Review instead of the legacy REST server. Same paths, parameters, checks and responses, include_fields and exclude_fields included. The legacy WebService module and its webservice hook are removed, and a test covers both methods.
GET /rest/bug_modal/initial_field_values, product_info, edit/<id>, cc/<id>, comment_tags/<id> and new_product/<id>, and PUT /rest/bug_modal/update_comment_tags/<id> are now served by the native controller Bugzilla::Extension::BugModal::API::V1::BugModal instead of the legacy REST server. Same paths, parameters, checks and responses. A bug id sent as a hash is now refused, as on the core bug routes. The legacy WebService module and its webservice hook are removed, and a test covers the seven routes. rest_legacy_credentials.t is deleted: no resource is left on the legacy REST server.
On a GET, the legacy REST server kept the id from the path even when the query string had one, and only a PUT body or query string replaced it. The controller let a query-string id win on GET too, so GET /rest/bug_modal/edit/5?id=6 answered for bug 6. The path id wins again on GET, which also makes the hash id check unneeded, so it is removed.
…required The legacy route matched /prod_comp_search/find/ with an empty search and returned the param_required error. The *search placeholder needed at least one character, so it was a 404. The placeholder now defaults to ''.
The legacy route matched /review/flag_activity/requestee/ (and setter/, type_id/) with an empty value, which was then ignored. The *value placeholder made it a 404. The placeholder now defaults to ''.
…board run_last_changes
…allers and mandatory groups
There was a problem hiding this comment.
🟡 Changes recommended
Authorization checks against a lagging shadow database can continue granting access after permissions are revoked and expose revision and reviewer metadata.
5 open issues
Run bug-permission checks against the primary database · New Run product-entry authorization checks against the primary database · New Run bug-visibility checks against the primary database · New Preserve OPTIONS handlers for migrated API routes · New Reject non-boolean JSON references before writing · New
What changed in this PR
Migrates nine extensions’ remaining legacy REST resources to native Mojo controllers, completing the endpoint migration needed before the legacy REST server can be removed.
Changes:
- Replaces legacy WebService registrations with native routes and JSON responses.
- Tightens selected parameter validation and corrects ComponentWatching product errors.
- Adds or rewrites route-level tests and removes the legacy credential test.
| File | Description |
|---|---|
qa/t/rest_legacy_credentials.t |
Removes legacy password-authentication tests. |
extensions/Review/t/bmo/review-api.t |
Tests reviewer suggestions and flag-history routes. |
extensions/Review/lib/WebService.pm |
Removes the legacy Review service. |
extensions/Review/lib/API/V1/Review.pm |
Adds native suggestions and flag-history routes. |
extensions/Review/Extension.pm |
Removes legacy service registration. |
extensions/ProdCompSearch/t/bmo/prod-comp-search.t |
Tests search and frequent-component routes. |
extensions/ProdCompSearch/lib/API/V1/ProdCompSearch.pm |
Migrates product/component searches to Mojo. |
extensions/ProdCompSearch/Extension.pm |
Removes legacy service registration. |
extensions/PhabBugz/t/bmo/webservice.t |
Exercises migrated routes with simulated Phabricator responses. |
extensions/PhabBugz/lib/WebService.pm |
Removes the legacy PhabBugz service. |
extensions/PhabBugz/lib/API/V1/PhabBugz.pm |
Adds permission, revision, and account routes. |
extensions/PhabBugz/Extension.pm |
Removes legacy service registration. |
extensions/MyDashboard/t/bmo/mydashboard-api.t |
Tests dashboard queries, visibility, and interest removal. |
extensions/MyDashboard/lib/Queries.pm |
Rejects unsupported flag-query types. |
extensions/MyDashboard/lib/API/V1/MyDashboard.pm |
Migrates dashboard routes and preserves the unprefixed alias. |
extensions/MyDashboard/Extension.pm |
Removes legacy service registration. |
extensions/InvalidBugHelper/t/bmo/invalid-bug-helper.t |
Converts invalid-bug checks to route-level tests. |
extensions/InvalidBugHelper/lib/API/V1/InvalidBugHelper.pm |
Migrates bug closing and adds boolean coercion. |
extensions/InvalidBugHelper/Extension.pm |
Removes legacy service registration. |
extensions/EditComments/t/bmo/editcomments-api.t |
Tests comment editing, visibility, and revision routes. |
extensions/EditComments/lib/WebService.pm |
Removes the legacy comment-editing service. |
extensions/EditComments/lib/API/V1/EditComments.pm |
Adds native routes, path-ID precedence, and boolean coercion. |
extensions/EditComments/Extension.pm |
Removes legacy service registration. |
extensions/ComponentWatching/t/bmo/component-watching-api.t |
Tests watch creation, retrieval, ownership, and deletion. |
extensions/ComponentWatching/lib/WebService.pm |
Removes the legacy component-watching service. |
extensions/ComponentWatching/lib/API/V1/ComponentWatching.pm |
Adds native watch-management routes. |
extensions/ComponentWatching/Extension.pm |
Fixes product error arguments and removes registration. |
extensions/BugModal/t/bmo/bug-modal-api.t |
Tests bug-page routes and access checks. |
extensions/BugModal/lib/API/V1/BugModal.pm |
Migrates bug-page data and comment-tag routes. |
extensions/BugModal/Extension.pm |
Removes legacy service registration. |
extensions/Bitly/t/bmo/bitly.t |
Tests URL routes with a simulated Bitly service. |
extensions/Bitly/lib/API/V1/Bitly.pm |
Migrates URL-shortening routes to Mojo. |
extensions/Bitly/Extension.pm |
Removes legacy service registration. |
Review effort: Balanced
The legacy REST server answered OPTIONS for every resource it served, which browsers send before a cross-origin PUT, DELETE, JSON POST or API-key request. The routes moved to native controllers didn't, so those requests failed from other origins. Each migrated route now has an OPTIONS route answering with its methods, through a new shared render_options callback in Bugzilla::API::V1::Util. New t/app-extension-api-options.t checks every path.
check_user_permission_for_bug, check_user_enter_bug_permission and bug_revisions switched to the shadow database, which the legacy WebService didn't do. As the shadow database can lag behind, a user whose access was just removed could still be reported as allowed, or see the revisions of a bug they can no longer see. Remove the switches so these checks read the main database again.
coerce_booleans let every reference through, so a JSON [] or {} was taken as true: an admin request
with "is_hidden": [] hid a comment revision instead of getting an error. Only JSON booleans are let
through now, and other references get the "must be true or false" error. This applies to every caller:
EditComments, InvalidBugHelper, Needinfo mentions, and the Component, Group and Product routes.
New t/api-util-coerce-booleans.t and an editcomments-api.t case.
merge_request_params only made declared list params into lists when they came from the query string
or a form: a single value in a JSON body was kept as is, so {"comment_ids": 5} on GET /editcomments/comment,
or {"add": "tag"} on PUT /bug_modal/update_comment_tags, died with a 500.
The legacy server's validate() wrapping such value into a list, done the same for every declared list param.
GET /review/flag_activity?bug_id=1&bug_id=2 only matched the last bug: bug_id and status weren't declared as list params, so a repeated one kept a single value, where the legacy server matched all of them. Declared them as lists. The flag_activity tests in review-api.t were all skipped, as the needinfo on the private bug was refused for a requestee who can't see it: the requestee is now on its CC list, so they run, with a new case for a repeated bug_id and status.
|
Thanks for the review! :) |
merge_request_params let a hash or a list of lists through for a list param, which then crashed callers such as update_comment_tags and bug_interest_unmark with a 500. Refuse anything that isn't a value or a list of plain values with invalid_params, as the legacy validate() did.
…rams instead of throwing merge_request_params threw invalid_params for a list param that isn't a value or a list of plain values. Return it instead, with its variables as a third element, as the malformed JSON error is returned, and have the callers with list params pass the variables to user_error. The POD now says how a single value is wrapped into a list and what is refused.


Summary
Moves the REST endpoints that extensions still registered through the
webservicehook from the legacy REST server to native Mojo controllers (extensions/<Name>/lib/API/V1/<Name>.pm), one commit per extension. Paths, parameters and responses stay the same, except for the changes listed below.Last step of 2057358 before the legacy REST server can be removed in 2081819: no resource is left on it after this PR.
Changes
lib/WebService.pmandwebservicehook: InvalidBugHelper, Bitly, ProdCompSearch, EditComments, ComponentWatching, MyDashboard, PhabBugz (added to its existing controller), Review, BugModal.mark_as_spam(InvalidBugHelper) andis_hidden(EditComments) must now be booleans (true/false/1/0).comment_idsent with aPUTno longer replaces the one in the path.run_flag_queryrefuses atypeother thanrequesteeorrequester, which it used to treat asrequester.qa/t/rest_legacy_credentials.tis removed, as no endpoint is left on the legacy server.t/bmotests in each extension call the routes.Test plan
enter_bug.cgiReferences