Skip to content

Commit

Permalink
LITE-28676 Fix ppr marketplace validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Hairash committed Oct 10, 2023
1 parent 8466659 commit 1c642b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions connect_ext_ppr/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from fastapi import status

from connect_ext_ppr.errors import ExtensionValidationError
from connect_ext_ppr.models.ppr import PPRVersion


def validate_deployment(deployment, account_id):
Expand Down Expand Up @@ -84,16 +85,18 @@ def validate_pricelist_ids(client, product_id, req_mp_configs, dep_mp_configs):
})


def validate_marketplaces_ppr(ppr, dr_marketplaces, dep_marketplaces):
def validate_marketplaces_ppr(ppr, dr_marketplaces, dep_marketplaces, db):
"""
Validates that we can apply the ppr to all marketplaces
"""
dep_mkplc_map = {m.marketplace: m for m in dep_marketplaces}
mkplcs_w_erros = []
for mp_data in dr_marketplaces:
mp_id = mp_data.id
if dep_mkplc_map[mp_id].ppr_id and dep_mkplc_map[mp_id].ppr_id > ppr.id:
mkplcs_w_erros.append(mp_id)
if mp_ppr_id := dep_mkplc_map[mp_id].ppr_id:
mp_ppr = db.query(PPRVersion).filter_by(id=mp_ppr_id).first()
if mp_ppr.version > ppr.version:
mkplcs_w_erros.append(mp_id)

if mkplcs_w_erros:
raise ExtensionValidationError.VAL_004(
Expand Down
2 changes: 1 addition & 1 deletion connect_ext_ppr/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def add_dep_request(
dr_marketplaces=deployment_request.marketplaces,
dep_marketplaces=dep_marketplaces,
)
validate_marketplaces_ppr(ppr, deployment_request.marketplaces, dep_marketplaces)
validate_marketplaces_ppr(ppr, deployment_request.marketplaces, dep_marketplaces, db)

instance = add_new_deployment_request(
db, deployment_request, deployment, account_id, logger,
Expand Down

0 comments on commit 1c642b7

Please sign in to comment.