mirror of
https://github.com/quay/quay.git
synced 2025-04-18 10:44:06 +03:00
billing: stop modifying subscription list that is being iterated over (PROJQUAY-8712) (#3725)
Fixes bug where removing a MW02702 sub after all it's quantities have been bound causes the next item in the subscription list to be skipped over, resulting in a malformed api response for the marketplace endpoint.
This commit is contained in:
parent
f0c153fab5
commit
6720be4b8c
@ -1136,10 +1136,13 @@ class UserSkuList(ApiResource):
|
|||||||
)
|
)
|
||||||
|
|
||||||
child_subscriptions = []
|
child_subscriptions = []
|
||||||
|
subscriptions_to_return = []
|
||||||
|
|
||||||
for subscription in user_subscriptions:
|
for subscription in user_subscriptions:
|
||||||
bound_to_org, bindings = organization_skus.subscription_bound_to_org(subscription["id"])
|
bound_to_org, bindings = organization_skus.subscription_bound_to_org(subscription["id"])
|
||||||
# fill in information for whether a subscription is bound to an org
|
# fill in information for whether a subscription is bound to an org
|
||||||
metadata = get_plan_using_rh_sku(subscription["sku"])
|
metadata = get_plan_using_rh_sku(subscription["sku"])
|
||||||
|
subscription["metadata"] = metadata
|
||||||
if bound_to_org:
|
if bound_to_org:
|
||||||
# special case for MW02702, which can be split across orgs
|
# special case for MW02702, which can be split across orgs
|
||||||
if subscription["sku"] == "MW02702":
|
if subscription["sku"] == "MW02702":
|
||||||
@ -1161,19 +1164,16 @@ class UserSkuList(ApiResource):
|
|||||||
if remaining_unbound > 0:
|
if remaining_unbound > 0:
|
||||||
subscription["quantity"] = remaining_unbound
|
subscription["quantity"] = remaining_unbound
|
||||||
subscription["assigned_to_org"] = None
|
subscription["assigned_to_org"] = None
|
||||||
else:
|
subscriptions_to_return.append(subscription)
|
||||||
# all quantities for this subscription are bound, remove it from
|
|
||||||
# the response body
|
|
||||||
user_subscriptions.remove(subscription)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# default case, only one org is bound
|
# default case, only one org is bound
|
||||||
subscription["assigned_to_org"] = model.organization.get_organization_by_id(
|
subscription["assigned_to_org"] = model.organization.get_organization_by_id(
|
||||||
bindings[0]["org_id"]
|
bindings[0]["org_id"]
|
||||||
).username
|
).username
|
||||||
|
subscriptions_to_return.append(subscription)
|
||||||
else:
|
else:
|
||||||
subscription["assigned_to_org"] = None
|
subscription["assigned_to_org"] = None
|
||||||
|
subscriptions_to_return.append(subscription)
|
||||||
|
|
||||||
subscription["metadata"] = metadata
|
return subscriptions_to_return + child_subscriptions
|
||||||
|
|
||||||
return user_subscriptions + child_subscriptions
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user