Remediate the 2026-09-03 feature-test findings
This commit is contained in:
@@ -13,6 +13,7 @@ from shopdb.utils.responses import (
|
||||
ErrorCodes
|
||||
)
|
||||
from shopdb.utils.pagination import get_pagination_params, paginate_query
|
||||
from shopdb.utils.queryargs import intarg
|
||||
|
||||
from shopdb.utils.authz import require_permission
|
||||
from shopdb.utils.import_mode import apply_import_timestamps
|
||||
@@ -365,20 +366,20 @@ def list_assets():
|
||||
query = query.join(AssetType).filter(AssetType.assettype == type_name)
|
||||
|
||||
# Type filter by ID
|
||||
if type_id := request.args.get('typeid', request.args.get('type_id')):
|
||||
query = query.filter(Asset.assettypeid == int(type_id))
|
||||
if (type_id := intarg('typeid', intarg('type_id'))) is not None:
|
||||
query = query.filter(Asset.assettypeid == type_id)
|
||||
|
||||
# Status filter
|
||||
if status_id := request.args.get('statusid', request.args.get('status_id')):
|
||||
query = query.filter(Asset.statusid == int(status_id))
|
||||
if (status_id := intarg('statusid', intarg('status_id'))) is not None:
|
||||
query = query.filter(Asset.statusid == status_id)
|
||||
|
||||
# Location filter
|
||||
if location_id := request.args.get('locationid', request.args.get('location_id')):
|
||||
query = query.filter(Asset.locationid == int(location_id))
|
||||
if (location_id := intarg('locationid', intarg('location_id'))) is not None:
|
||||
query = query.filter(Asset.locationid == location_id)
|
||||
|
||||
# Business unit filter
|
||||
if bu_id := request.args.get('businessunitid', request.args.get('businessunit_id')):
|
||||
query = query.filter(Asset.businessunitid == int(bu_id))
|
||||
if (bu_id := intarg('businessunitid', intarg('businessunit_id'))) is not None:
|
||||
query = query.filter(Asset.businessunitid == bu_id)
|
||||
|
||||
# Sorting
|
||||
sort_by = request.args.get('sort', 'assetnumber')
|
||||
@@ -1011,17 +1012,26 @@ def get_assets_map():
|
||||
Asset.mapy.isnot(None)
|
||||
)
|
||||
|
||||
# Dualpath single-machine collapse: hide the secondary bay marker so a
|
||||
# dual-bay pair shows one marker; the primary carries the partner label.
|
||||
# Gated on the site setting (default on).
|
||||
# Dualpath single-machine collapse on the map: a secondary bay draws its
|
||||
# OWN marker when somebody has positioned it, and is represented by the
|
||||
# primary's marker when nobody has.
|
||||
#
|
||||
# It used to be excluded unconditionally, which made setting a position on
|
||||
# a secondary bay a silent no-op: the form accepted the pin, stored it, and
|
||||
# the map never drew it. One marker per pair is right when the pair sits in
|
||||
# one place, which is the common case and still the default - but a
|
||||
# dual-bay machine whose second bay is physically somewhere else is exactly
|
||||
# what positioning it separately means.
|
||||
#
|
||||
# No extra filtering is needed for the fallback half: the query above
|
||||
# already requires mapx/mapy, so an unpositioned secondary never reaches
|
||||
# here and the primary's marker stands for both, carrying the combined
|
||||
# label.
|
||||
from shopdb.core.services.dualpath import (
|
||||
resolve_dualpath_pairs, dualpath_single_machine_enabled)
|
||||
dualpath_collapse = None
|
||||
if dualpath_single_machine_enabled():
|
||||
dualpath_collapse = resolve_dualpath_pairs()
|
||||
if dualpath_collapse.secondaryassetids:
|
||||
query = query.filter(
|
||||
Asset.assetid.notin_(dualpath_collapse.secondaryassetids))
|
||||
|
||||
selected_assettype = request.args.get('assettype')
|
||||
|
||||
@@ -1030,8 +1040,7 @@ def get_assets_map():
|
||||
query = query.join(AssetType).filter(AssetType.assettype == selected_assettype)
|
||||
|
||||
# Filter by subtype (depends on asset type) - case-insensitive matching
|
||||
if subtype_id := request.args.get('subtype'):
|
||||
subtype_id = int(subtype_id)
|
||||
if (subtype_id := intarg('subtype')) is not None:
|
||||
# Normalize the underscore DB form (measuring_tool, network_device) to
|
||||
# the space form the branches below compare against.
|
||||
asset_type_lower = (
|
||||
@@ -1079,16 +1088,16 @@ def get_assets_map():
|
||||
pass
|
||||
|
||||
# Filter by business unit
|
||||
if bu_id := request.args.get('businessunitid'):
|
||||
query = query.filter(Asset.businessunitid == int(bu_id))
|
||||
if (bu_id := intarg('businessunitid')) is not None:
|
||||
query = query.filter(Asset.businessunitid == bu_id)
|
||||
|
||||
# Filter by status
|
||||
if status_id := request.args.get('statusid'):
|
||||
query = query.filter(Asset.statusid == int(status_id))
|
||||
if (status_id := intarg('statusid')) is not None:
|
||||
query = query.filter(Asset.statusid == status_id)
|
||||
|
||||
# Filter by location
|
||||
if location_id := request.args.get('locationid'):
|
||||
query = query.filter(Asset.locationid == int(location_id))
|
||||
if (location_id := intarg('locationid')) is not None:
|
||||
query = query.filter(Asset.locationid == location_id)
|
||||
|
||||
# Search filter
|
||||
if search := request.args.get('search'):
|
||||
@@ -1102,6 +1111,10 @@ def get_assets_map():
|
||||
|
||||
assets = query.all()
|
||||
|
||||
# Every asset that ends up with a marker. Used to decide whether a dual-bay
|
||||
# partner draws its own pin or is represented by this one.
|
||||
positioned_assetids = {asset.assetid for asset in assets}
|
||||
|
||||
# Batch-load primary IPs in a single query instead of N+1 per asset.
|
||||
# Prefer isprimary=True IP, fall back to any IP (comtypeid=1).
|
||||
asset_ids = [a.assetid for a in assets]
|
||||
@@ -1153,10 +1166,17 @@ def get_assets_map():
|
||||
if type_data:
|
||||
item['typedata'] = type_data
|
||||
|
||||
# combined-label partner for a collapsed dual-bay pair (label only)
|
||||
# Combined label for a dual-bay pair, and ONLY when this marker really
|
||||
# stands for both bays. A partner that draws its own marker gets its
|
||||
# own name: labelling two separate pins '2007 / 2008' would say the
|
||||
# same machine is in two places.
|
||||
if dualpath_collapse:
|
||||
partner = dualpath_collapse.partnerbyasset.get(asset.assetid)
|
||||
item['dualpathpartner'] = partner['assetnumber'] if partner else None
|
||||
partner_has_marker = bool(
|
||||
partner and partner['assetid'] in positioned_assetids)
|
||||
item['dualpathpartner'] = (
|
||||
partner['assetnumber'] if partner and not partner_has_marker
|
||||
else None)
|
||||
|
||||
data.append(item)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user