Page MenuHomePhabricator

๐ŸŽ† Modify data of descriptions on a property
Closed, ResolvedPublic8 Estimated Story Points

Description

As a tool builder I want to be able to edit parts of descriptions of a property so that the work in my tool can be saved back to Wikidata.

PATCH /entities/properties/{property_id}/descriptions

Notes:

  • The request contains a JSON body with a mandatory patch key containing a JSON Patch document plus optional metadata: tags, bot, comment.
  • Response body containing the updated description data, using the similar structure as GET /entities/properties/{property_id}/descriptions.
  • Handle HTTP conditional request headers as in PATCH /entities/items/{item_id}/descriptions
  • Handle user authentication/authorization like in PATCH /entities/items/{item_id}/descriptions
  • All edit data is validated

Autocomments:

  • should mimic the wbeditentity behavior when editing descriptions:
    • If the change results in changing descriptions in not more than 50 languages: /* wbeditentity-update-languages-short:0||LANGS */
    • If the change results in changing descriptions in 51 or more languages: /* wbeditentity-update-languages:0||LANG_COUNT */
    • where LANGS is a comma separated list of alphabeticall-sorted language codes of relevant languages (e.g. de, en, es, fi, fr, it). LANG_COUNT is a number of languages with changed descriptions
    • the boundary number of 50 languages is defined in ChangedLanguagesCounter::SHORTENED_SUMMARY_MAX_EDIT constant (not configurable)

Error cases considered:

error type HTTP Response codeResponse content
ID provided is not a valid property ID400"code": "invalid-property-id",
"message": "Not a valid property ID: '{property_id}'"
"context": {
"property-id": "{property-id}"
}
Invalid edit tag400"code": "invalid-edit-tag"
"message": "Invalid MediaWiki tag: {tag}"
Comment too long400"code": "comment-too-long"
"message": "Comment must not be longer than {limit} characters"
Invalid JSON patch (general error)400"code": "invalid-patch"
"message": "The provided patch is invalid"
incorrect JSON patch operation400"code": "invalid-patch-operation"
"message": "Incorrect JSON patch operation: '<op>'"
"context": { "operation": <operation_object> }
invalid field type in JSON patch
(either of op, path, from is not a string)
400"code": "invalid-patch-field-type"
"message": "The value of '<field>' must be of type string"
"context": { "operation": <operation_object>, "field": <field> }
missing mandatory field in JSON patch
(op, path, value, also from on copy/move patches)
400"code": "missing-json-patch-field"
"message": "Missing '<field>' in JSON patch"
"context": { "operation": <operation_object>, "field": <field> }
Property with the given ID does not exist404"code": "property-not-found",
"message": "Could not find a property with the ID: '{property_id}'"
Target of JSON Patch not found on the object409"code": "patch-target-not-found",
"message": "Target '<target>' not found on the resource",
"context": {
"operation": <operation_object>,
"field": <path>
}
JSON Patch test operation failed409"code": "patch-test-failed",
"message": "Test operation in the provided patch failed. At path '{path}' expected '{expected}', actual: '{actual}'",
"context": {
"operation": <operation_object>,
"actual-value": <actual>
}
After changes an invalid language code is used422"code": "patched-descriptions-invalid-language-code"
"message": "Not a valid language code '{language_code}' in changed descriptions"
"context": {
"language": <language_code>
}
After changes a description is invalid (empty, too long)422"code": "patched-description-empty"/"patched-description-too-long"
"message": "Changed description for '{lang_code}' cannot be empty" / "Changed description for '{lang_code}' must not be more than '{limit}' characters long"
"context": {
"language": <language_code>
"value": <description> (too long description case only)
"character-limit": <limit> (too long description case only)
}
After changes a description is invalid (not allowed characters used)422"code": "patched-description-invalid"
"message": "Changed description for '{lang_code}' is not valid; '{description-text}'"
"context": {
"language": <language_code>
"value": <description>
}
After changes the property has the exact same label and description in a given language422"code": "patched-property-label-description-same-value"
"message": "Label and description for language code {language} can not have the same value.
"context": {
"language": <language>
}

Additional notes:

Implementation steps:

  • add to OAS
  • happy path
    • use the use case validator for deserialization only, but don't handle or test any errors it throws yet
    • generate the expected edit summary
    • ETag and Last-Modified
  • Handle request validation errors
  • Respond 404 if property not found
  • Authorization
  • Handle errors that occur while patching the descriptions (test condition, addressing fields that don't exist, ...)
  • Validate the patched descriptions
    • don't try to reuse anything from existing PatchedDescriptionsValidator or the patched labels validator just yet. We'll do that after all of them are done.
    • handles all cases where the patched JSON structure cannot be deserialized into a valid descriptions TermList (empty description, description too long, description containing invalid characters, language code)
    • Collision detection (checking that no other property has the same combination of label and description in any changed language)
    • Check that no changed description is now the same as the label in any changed language
  • Use the usual middlewares and add the route handler to RouteHandlersTest
  • Add OpenAPI validation test
  • Mark as production ready

Event Timeline

Restricted Application added a subscriber: Aklapper. ยท View Herald TranscriptJul 28 2023, 1:56 PM
Ifrahkhanyaree_WMDE renamed this task from Modify data of descriptions on items & properties to Modify data of descriptions on properties.Jul 28 2023, 1:57 PM
Ollie.Shotton_WMDE renamed this task from Modify data of descriptions on properties to Modify data of descriptions on a property.Aug 25 2023, 1:21 PM
Ollie.Shotton_WMDE renamed this task from Modify data of descriptions on a property to ๐ŸŽ† Modify data of descriptions on a property.Nov 16 2023, 5:31 PM