Make gauge/maintenance identifiers per-asset-type and extend to all types
Optional asset identifiers (gauge lab reference, maintenance reference, FQDN) were global per-identifier and only surfaced on equipment. Now they are toggleable per asset type and rendered on every asset type. - settings: replace 3 global identifier toggles with a per-type matrix. New keys identifier_<name>_<assettype>_enabled (3 identifiers x 4 types). IDENTIFIER_LABELS / IDENTIFIER_ASSETTYPES constants drive the seed (API seed and CLI seed settings). - composable: identifierSettings now exposes isEnabled(name, assettype), per-type flag winning over the legacy global key, defaulting on. - backend writes: computers, network, printers asset create + update now accept gaugelabreference and maintenancereference (equipment already did). Reads already flowed through Asset.to_dict. - frontend: Settings page renders an identifier x asset-type toggle matrix. Equipment, PC, printer, network forms and detail pages show gauge/maintenance (and FQDN where applicable) gated by isEnabled(name, type). Legacy global identifier_<name>_enabled keys are still honored as a fallback for older installs. SystemSettings toggles upsert (create on 404) so a deploy that has not re-seeded still works on first toggle. 144 tests pass, naming/style check green, frontend builds. Verified live: matrix renders, PC form shows the fields, PUT persists gauge/maintenance on a PC and reads back. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -361,6 +361,18 @@ def seed_settings():
|
||||
},
|
||||
]
|
||||
|
||||
# Asset identifier toggles, per identifier AND per asset type (ADR-001).
|
||||
from shopdb.core.api.settings import IDENTIFIER_LABELS, IDENTIFIER_ASSETTYPES
|
||||
for name, label in IDENTIFIER_LABELS.items():
|
||||
for assettype in IDENTIFIER_ASSETTYPES:
|
||||
defaults.append({
|
||||
'key': f'identifier_{name}_{assettype}_enabled',
|
||||
'value': 'true',
|
||||
'valuetype': 'boolean',
|
||||
'category': 'identifiers',
|
||||
'description': f'Show the {label} identifier on {assettype} assets',
|
||||
})
|
||||
|
||||
created = 0
|
||||
for d in defaults:
|
||||
if not Setting.query.filter_by(key=d['key']).first():
|
||||
|
||||
@@ -17,6 +17,16 @@ SETTINGS_CACHE_TTL = 300 # 5 minutes
|
||||
# exposed in plaintext. Sending it back on update is treated as "unchanged".
|
||||
SECRET_MASK = '********'
|
||||
|
||||
# Optional asset identifiers and the asset types they can be toggled on.
|
||||
# Drives per-type seed keys and the Settings matrix UI. The asset type names
|
||||
# match the AssetType.assettype values seeded by each plugin.
|
||||
IDENTIFIER_LABELS = {
|
||||
'gaugelabreference': 'Gauge Lab Reference',
|
||||
'maintenancereference': 'Maintenance Reference',
|
||||
'fqdn': 'FQDN / hostname',
|
||||
}
|
||||
IDENTIFIER_ASSETTYPES = ['equipment', 'computer', 'printer', 'network_device']
|
||||
|
||||
|
||||
def _is_secret(key: str) -> bool:
|
||||
return 'password' in key or 'token' in key or 'secret' in key
|
||||
@@ -155,29 +165,22 @@ def create_setting():
|
||||
@jwt_required()
|
||||
def seed_default_settings():
|
||||
"""Seed default settings if they don't exist."""
|
||||
defaults = [
|
||||
# Asset identifier feature toggles (global, per identifier)
|
||||
# Asset identifier feature toggles, per identifier AND per asset type.
|
||||
# Key format: identifier_<name>_<assettype>_enabled (boolean). Admins pick
|
||||
# which optional identifiers show on which asset types. See ADR-001.
|
||||
identifierdefaults = [
|
||||
{
|
||||
'key': 'identifier_gaugelabreference_enabled',
|
||||
'key': f'identifier_{name}_{assettype}_enabled',
|
||||
'value': 'true',
|
||||
'valuetype': 'boolean',
|
||||
'category': 'identifiers',
|
||||
'description': 'Show the Gauge Lab Reference identifier on assets'
|
||||
},
|
||||
{
|
||||
'key': 'identifier_maintenancereference_enabled',
|
||||
'value': 'true',
|
||||
'valuetype': 'boolean',
|
||||
'category': 'identifiers',
|
||||
'description': 'Show the Maintenance Reference identifier on assets'
|
||||
},
|
||||
{
|
||||
'key': 'identifier_fqdn_enabled',
|
||||
'value': 'true',
|
||||
'valuetype': 'boolean',
|
||||
'category': 'identifiers',
|
||||
'description': 'Show the FQDN / hostname identifier on assets'
|
||||
},
|
||||
'description': f'Show the {label} identifier on {assettype} assets',
|
||||
}
|
||||
for name, label in IDENTIFIER_LABELS.items()
|
||||
for assettype in IDENTIFIER_ASSETTYPES
|
||||
]
|
||||
|
||||
defaults = identifierdefaults + [
|
||||
# Zabbix integration
|
||||
{
|
||||
'key': 'zabbix_enabled',
|
||||
|
||||
Reference in New Issue
Block a user