Page MenuHomePhabricator

Modify data of aliases on a property
Closed, ResolvedPublic13 Estimated Story Points

Description

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

PATCH /entities/properties/{property_id}/aliases

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 aliases data, using the similar structure as GET /entities/properties/{property_id}/aliases.
  • Handle HTTP conditional request headers as in PATCH /entities/properties/{property_id}/aliases
  • Handle user authentication/authorization like in PATCH /entities/properties/{property_id}/aliases
  • duplicate aliases are not allowed per language
  • cross-language "collision detection" does not apply for aliases
  • All edit data is validated

Autocomments:

  • should mimic the wbeditentity behavior when editing aliases:
    • If the change results in changing aliases in not more than 50 languages: /* wbeditentity-update-languages-short:0||LANGS */
    • If the change results in changing aliases 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 aliases
    • 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
Property with the given ID does not exist404"code": "property-not-found",
"message": "Could not find a property with the ID: '{property_id}'"
ID provided is not a valid property ID400 "code": "invalid-property-id",
"message": "Not a valid property ID: '{item_id}'"
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> }
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-alias-invalid-language-code"
"message": "Not a valid language code '{language_code}' in changed aliases"
"context": {
"language": <language_code>
}
After changes an alias is invalid (empty, too long)422"code": "patched-alias-empty"/"patched-alias-too-long"
"message": "Changed alias for '{lang_code}' cannot be empty" / "Changed alias for '{lang_code}' must not be more than '{limit}' characters long"
"context": {
"language": <language_code>
"value": <alias> (too long alias case only)
"character-limit": <limit> (too long alias case only)
}
After changes alias/aliases are invalid. Three cases are as follows: 1) Entire value for aliases is invalid, 2) an alias in the list contains invalid character and 3) aliases haven't been added as a list422"code": "patched-aliases-invalid-field"
"message": "Patched value for '{field}' is invalid"
"context": { "path": <field>, "value": <value>}
}
Duplicates in aliases not allowed 422"code": "patched-duplicate-alias"
"message": "Aliases in language {language_code} contain duplicate alias: '{alias}' "
"context": {
"value": <alias>
"language": <language_code>
}
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"}

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
    • create an AliasesDeserializer
    • don't generate and edit summary yet
    • ETag and Last-Modified
  • generate the expected edit summary
    • try to make TermsEditSummaryToFormattableSummaryConverter reusable for aliases
  • Handle request validation errors
  • Respond 404 if property not found
  • Authorization
  • Handle errors that occur while patching the aliases (test condition, addressing fields that don't exist, ...)
  • Validate the patched aliases
    • handles all cases where the patched JSON structure cannot be deserialized into a valid aliases AliasGroupList (empty alias, alias too long, alias containing invalid characters, duplicate aliases, language code)
  • Use the usual middlewares and add the route handler to RouteHandlersTest
  • Add OpenAPI validation test
  • Mark as production ready

Event Timeline

Change 964462 had a related patch set uploaded (by Jakob; author: Jakob):

[mediawiki/extensions/Wikibase@master] REST: Add "Patch Property Aliases" to OAS

https://gerrit.wikimedia.org/r/964462

Change 964462 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Add "Patch Property Aliases" to OAS

https://gerrit.wikimedia.org/r/964462

Change 964879 had a related patch set uploaded (by Jakob; author: Jakob):

[mediawiki/extensions/Wikibase@master] REST: Add aliases to Property read model

https://gerrit.wikimedia.org/r/964879

Change 964879 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Add aliases to Property read model

https://gerrit.wikimedia.org/r/964879

Change 964927 had a related patch set uploaded (by Jakob; author: Jakob):

[mediawiki/extensions/Wikibase@master] REST: Add PatchPropertyAliases happy path

https://gerrit.wikimedia.org/r/964927

Change 965182 had a related patch set uploaded (by Jakob; author: Jakob):

[mediawiki/extensions/Wikibase@master] REST: Validate PatchPropertyAliases requests

https://gerrit.wikimedia.org/r/965182

Change 964927 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Add PatchPropertyAliases happy path

https://gerrit.wikimedia.org/r/964927

Change 965526 had a related patch set uploaded (by Jakob; author: Jakob):

[mediawiki/extensions/Wikibase@master] REST: Generate edit summaries for PatchPropertyAliases

https://gerrit.wikimedia.org/r/965526

Change 965182 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Validate PatchPropertyAliases requests

https://gerrit.wikimedia.org/r/965182

Change 965526 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Generate edit summaries for PatchPropertyAliases

https://gerrit.wikimedia.org/r/965526

Change 965759 had a related patch set uploaded (by Jakob; author: Jakob):

[mediawiki/extensions/Wikibase@master] REST: Validate patched property aliases

https://gerrit.wikimedia.org/r/965759

Change 966122 had a related patch set uploaded (by Jakob; author: Jakob):

[mediawiki/extensions/Wikibase@master] REST: Respond 404 if property not found in PatchPropertyAliases

https://gerrit.wikimedia.org/r/966122

Change 966127 had a related patch set uploaded (by Jakob; author: Jakob):

[mediawiki/extensions/Wikibase@master] REST: Handle patch errors in PatchPropertyAliases

https://gerrit.wikimedia.org/r/966127

Change 966155 had a related patch set uploaded (by Jakob; author: Jakob):

[mediawiki/extensions/Wikibase@master] REST: Check authorization in PatchPropertyAliases

https://gerrit.wikimedia.org/r/966155

Change 966185 had a related patch set uploaded (by Jakob; author: Jakob):

[mediawiki/extensions/Wikibase@master] REST: Add middlewares to PatchPropertyAliases

https://gerrit.wikimedia.org/r/966185

Change 965759 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Validate patched property aliases

https://gerrit.wikimedia.org/r/965759

Change 966122 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Respond 404 if property not found in PatchPropertyAliases

https://gerrit.wikimedia.org/r/966122

Change 966127 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Handle patch errors in PatchPropertyAliases

https://gerrit.wikimedia.org/r/966127

Change 966155 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Check authorization in PatchPropertyAliases

https://gerrit.wikimedia.org/r/966155

Change 966185 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Add middlewares to PatchPropertyAliases

https://gerrit.wikimedia.org/r/966185

Change 966811 had a related patch set uploaded (by Silvan Heintze; author: Silvan Heintze):

[mediawiki/extensions/Wikibase@master] REST: Add spec tests for PatchPropertyAliases

https://gerrit.wikimedia.org/r/966811

Change 966811 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Add spec tests for PatchPropertyAliases

https://gerrit.wikimedia.org/r/966811

Change 967138 had a related patch set uploaded (by Ollie Shotton; author: Ollie Shotton):

[mediawiki/extensions/Wikibase@master] REST: Fix "Patch Item/Property Aliases" errors

https://gerrit.wikimedia.org/r/967138

Change 967138 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Fix "Patch Item/Property Aliases" errors

https://gerrit.wikimedia.org/r/967138

Change 969467 had a related patch set uploaded (by Muhammad Jaziraly; author: Muhammad Jaziraly):

[mediawiki/extensions/Wikibase@master] REST: Mark PatchItemAliases as production-ready

https://gerrit.wikimedia.org/r/969467

Change 969467 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Mark PatchPropertyAliases as production-ready

https://gerrit.wikimedia.org/r/969467