Skip to content

expose blocked version as blocked and soft_blocked in the API#22750

Merged
eviljeff merged 2 commits intomozilla:masterfrom
eviljeff:15015-expose-soft-block-in-api
Oct 17, 2024
Merged

expose blocked version as blocked and soft_blocked in the API#22750
eviljeff merged 2 commits intomozilla:masterfrom
eviljeff:15015-expose-soft-block-in-api

Conversation

@eviljeff
Copy link
Member

@eviljeff eviljeff commented Oct 9, 2024

Fixes: mozilla/addons#15015

Description

Renames versions to blocked, adds soft_blocked, and drops unused max_version and min_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 blocked rather than versions we'll keep the shim block-versions-list-shim enabled for v5 too so it continues to work during the deploy, etc. min_version and max_version have 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

  • Add some blocked (signed) versions that are a mixture of hard and soft blocks, and see /api/v5/blocked/<guid>/ lists them as blocked and soft_blocked respectively.
  • See hard blocked are still there as versions as before
  • check /v4/ and see min_version and max_version are still there, and are the max and min hard blocked versions.
  • is_all_versions should be true if all signed versions are either hard or soft blocked AND the add-on is disabled to prevent further versions.

Checklist

  • Add #ISSUENUM at the top of your PR to an existing open issue in the mozilla/addons repository.
  • Successfully verified the change locally.
  • The change is covered by automated tests, or otherwise indicated why doing so is unnecessary/impossible.
  • Add before and after screenshots (Only for changes that impact the UI).
  • Add or update relevant docs reflecting the changes made.
@eviljeff eviljeff force-pushed the 15015-expose-soft-block-in-api branch from d2f00d0 to 3ea2f22 Compare October 9, 2024 17:51
@eviljeff eviljeff requested review from a team and KevinMind and removed request for a team October 11, 2024 13:37
@eviljeff eviljeff marked this pull request as ready for review October 11, 2024 13:40
@KevinMind
Copy link
Contributor

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.

@KevinMind
Copy link
Contributor

AND the add-on is disabled to prevent further versions.

Missed that part.

@KevinMind
Copy link
Contributor

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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@KevinMind KevinMind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit. Looks good. 🚢

@eviljeff
Copy link
Member Author

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 api docs are correct I just wrote the testing instructions from memory so got the url slightly wrong

@eviljeff eviljeff merged commit c2fddde into mozilla:master Oct 17, 2024
@willdurand willdurand mentioned this pull request Apr 3, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants