expose blocked version as blocked and soft_blocked in the API#22750
expose blocked version as blocked and soft_blocked in the API#22750eviljeff merged 2 commits intomozilla:masterfrom
Conversation
d2f00d0 to
3ea2f22
Compare
|
Testing instructions used the wrong URL. I actually found this very useful to test in the swagger UI as I can see the fields I expect and trigger that API to see the result. The URL I have a setup with only one block, for an addon with a single signed version, here is the json {
"id": 1,
"created": "2024-10-16T17:17:03Z",
"modified": "2024-10-16T17:17:03Z",
"addon_name": {
"en-US": "Addôn 8eaffd9aca3645399e98c316d3c78020"
},
"blocked": [
"23609.517.8654.43211"
],
"soft_blocked": [],
"guid": "{0f1fbd83-d0fe-42ef-b6ce-365860d6ca10}",
"reason": "",
"url": null,
"is_all_versions": false,
"versions": [
"23609.517.8654.43211"
]
}I think I should be expecting 'is_all_versions': True on this one right? Added another block version and still never getting is_all_versions to be true. {
"id": 1,
"created": "2024-10-16T17:17:03Z",
"modified": "2024-10-16T17:17:03Z",
"addon_name": {
"en-US": "Addôn 8eaffd9aca3645399e98c316d3c78020"
},
"blocked": [
"23609.517.8654.43211",
"60110.12408.26118.60798"
],
"soft_blocked": [],
"guid": "{0f1fbd83-d0fe-42ef-b6ce-365860d6ca10}",
"reason": "",
"url": null,
"is_all_versions": false,
"versions": [
"23609.517.8654.43211",
"60110.12408.26118.60798"
]
}What am I doing wrong? I can see that updating the soft property appropriately moves the block to the right list. |
Missed that part. |
|
Got it after force disabling from reviewer tools. That should also be mentioned it must be force disabled not just a version disabled by the developer. {
"id": 1,
"created": "2024-10-16T17:17:03Z",
"modified": "2024-10-16T17:17:03Z",
"addon_name": {
"en-US": "Addôn 8eaffd9aca3645399e98c316d3c78020"
},
"blocked": [
"23609.517.8654.43211",
"60110.12408.26118.60798"
],
"soft_blocked": [],
"guid": "{0f1fbd83-d0fe-42ef-b6ce-365860d6ca10}",
"reason": "",
"url": null,
"is_all_versions": true,
"versions": [
"23609.517.8654.43211",
"60110.12408.26118.60798"
]
} |
| def _get_blocked_for(self, obj, *, is_soft): | ||
| if not hasattr(obj, '_blockversion_set_qs_values_list'): | ||
| obj._blockversion_set_qs_values_list = sorted( | ||
| obj.blockversion_set.order_by('version__version').values_list( |
There was a problem hiding this comment.
Could you not add soft to the query here? I'm not totally sure if that's valid in django but
obj.blockversion_set.filter(soft=is_soft)...doesn't work? That would be better than filtering after the fact from a query perf perspective and much cleaner to look at.
There was a problem hiding this comment.
We could - it's a (potentially unnecessary) optimization to avoid 2 queries - one for soft=True, one for soft=False. After the first call to _get_blocked_for the query result is saved to be used for the next call.
KevinMind
left a comment
There was a problem hiding this comment.
One nit. Looks good. 🚢
The api docs are correct I just wrote the testing instructions from memory so got the url slightly wrong |
Fixes: mozilla/addons#15015
Description
Renames
versionstoblocked, addssoft_blocked, and drops unusedmax_versionandmin_version. Adds shims for v4 so functionality is as now.Context
Frontend consumes this API to display details of blocks, and in particular for this change, the versions that are blocked, to end-users. Until deploy+1 after frontend is updated to consume
blockedrather thanversionswe'll keep the shimblock-versions-list-shimenabled for v5 too so it continues to work during the deploy, etc.min_versionandmax_versionhave been unused for a long time on frontend - since we stopped implementing blocked versions as a range - but we overlooked removing and shim'ing them.Testing
/api/v5/blocked/<guid>/lists them asblockedandsoft_blockedrespectively.versionsas beforemin_versionandmax_versionare still there, and are the max and min hard blocked versions.is_all_versionsshould be true if all signed versions are either hard or soft blocked AND the add-on is disabled to prevent further versions.Checklist
#ISSUENUMat the top of your PR to an existing open issue in the mozilla/addons repository.