Bug 2071907 - Migrate Product REST resource to native Mojo API - #2762
Merged
Merged
Conversation
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.
Summary
Ports
Bugzilla::WebService::Product'sget/create/get_accessible_products/get_enterable_products/get_selectable_productsmethods into a nativeBugzilla::API::V1::ProductMojo controller, mirroring the pattern already used for Classification/Component/Teams/Reminders/Configuration/Bugzilla (system info)/BugUserLastVisit.This is a child bug of 2057358, see there for details.
Changes
Bugzilla/API/V1/Product.pm:GET /rest/product_accessible,/rest/product_enterable,/rest/product_selectable,GET /rest/product,GET /rest/product/<id_or_name>andPOST /rest/product(login +editcomponentsrequired for create), same JSON response shape as the legacy endpointsBugzilla/WebService/Product.pmandBugzilla/WebService/Server/REST/Resources/Product.pmProductentry fromWS_DISPATCHinBugzilla/WebService/Constants.pm, the correspondinguseline inBugzilla/WebService/Server/REST.pm, and the POD entry inBugzilla/WebService.pm. Also repoint a POD link inBugzilla/WebService/Bug.pmthat referencedBugzilla::WebService::Product/get_accessible_productsget()declaresids,names,type,include_fieldsandexclude_fieldsas list parameters to the sharedmerge_request_params, so?ids=1&ids=2returns every product asked for rather than only the last.include_fields/exclude_fieldsalso accept a comma-separated list. A malformed JSON body is reported asrest_malformed_jsoncreate()coercesis_open,has_unconfirmedandcreate_seriesfrom query-string/form values (true/false/1/0, case-insensitive) and rejects anything else withinvalid_params. Without this,?is_open=falsewould create an open product, since the string"false"is truthy in Perl. JSON booleans are unchangedget()and the three id lists returnlogin_requiredfor anonymous requests when therequireloginparameter is on. The legacy dispatcher'sBugzilla->login()enforced this, but the native Mojo login helper does not for REST requests. Anonymous access is still allowed whenrequireloginis off, matching the legacy behaviourOPTIONScome from the route, so/rest/productadvertisesGET, POSTand the other routes advertiseGET.Access-Control-Allow-Methodsfollows the same value/rest/product/<id_or_name>placeholder is#id_or_name, so product names containing a dot are matched in fullqa/t/rest_product.t: cover lookup by id and by name in the path,include_fields=id,name, the missing-params and invalid-typeerrors, andOPTIONS.qa/t/rest_product_create.t: cover query-string booleans and an invalid boolean valueBreaking change: removing the
WS_DISPATCHentry also removesProduct.get/create/get_accessible_products/get_enterable_products/get_selectable_products(and theProduct.get_productsalias) from JSON-RPC and XML-RPC, not just the legacy REST dispatcher, since all three share that table. Native Mojo routes only serve REST. This matches the same tradeoff already made in the Classification, Bugzilla (system-info), BugUserLastVisit and Group migrations earlier in this series.Not ported:
PUT /rest/product/<id_or_name>is documented indocs/en/rst/api/core/v1/product.rst, and the legacy REST resource routed it to anupdatemethod, butBugzilla::WebService::Productnever had one. The endpoint has never worked on BMO; it now returns 404 instead of an error.Test plan
GET /rest/product_accessible/_enterable/_selectableas admin, unprivileged and logged-out usersGET /rest/product?ids=<id>&ids=<id>/GET /rest/product?names=<name>/GET /rest/product?type=accessibleGET /rest/product/<id>/GET /rest/product/<name>GET /rest/product/<id>?include_fields=id,nameGET /rest/productwith no parameters, expectingparams_requiredGET /rest/product?type=bogus, expectingget_products_invalid_typePOST /rest/product(logged out, unprivileged, missing/empty/too-long/duplicate name, missing description, all optional arguments)POST /rest/product?...&is_open=false&has_unconfirmed=false, expecting a closed product without UNCONFIRMED, andis_open=mayberejectedOPTIONS /rest/productreturnsAllow: GET, POSTqa/t/rest_product.tandqa/t/rest_product_create.tpassReferences