Multi-site distribution readiness: settings-driven site config, security closeout, release engineering, v0.5.0
Make the app distributable to other GE Aerospace sites (one self-hosted
instance per site, ADR-004). GE values remain the shipped defaults; every
site-specific behavior is now a Setting an admin can change in the UI.
Settings-driven site config:
- Branding: site/QR/badge logos, favicon, primary color (upload endpoints
mirror the map-blueprint pattern; new Settings > Branding section).
- ServiceNow: search/incident/change URL templates ({ticket}), ticket
prefixes, enable toggle. Defaults point at the current
geaerospaceqa.service-now.com global search. Disabled = plain-text tickets.
- Employee-id regex (employeeid_pattern), printer hostname template,
QR label targets (qr_target_printer / qr_target_usb, blank = asset page,
else URL template with placeholders), usb_label_style (barcode|qr).
- West Jefferson floor-plan PNGs removed from the tree; generic placeholder
ships as the map default and sites upload their own blueprint.
Security closeout:
- dashboarddefaults writes now require admin.
- Collector: generic error messages (no str(exc) leak); API key accepted
via X-API-Key header only (BREAKING: querystring api_key removed).
- IP-based login rate limiting (AUTH_RATELIMIT_* knobs) atop account lockout.
- Setting.set() creation race fixed (IntegrityError retry).
Release engineering and docs:
- __version__ 0.5.0 (distinct from __contract_version__, ADR-007),
CHANGELOG.md, Gitea Actions CI config, frontend version aligned.
- One wizard-first install story across README/DEPLOY; new CONFIG.md,
UPGRADE.md, BACKUP-RESTORE.md; CLAUDE.md and ROADMAP de-staled.
- Dockerfile multi-stage build now bundles the frontend; compose binds
MySQL to 127.0.0.1; stale database/schema.sql and one-off SQL removed.
Debt and fixes:
- .query.get() -> db.session.get() sweep; datetime.utcnow() removed
(naive-UTC via timezone-aware now); users.py on authz decorators.
- Fixed 4 stale tests (slides feed shape, shopfloor splitperemployee,
plugin contract purity) and the USB label page field mapping (both usb
modes emit the cmmc shape: device_id/device_desc).
- Health endpoint reports the real version.
248 tests pass; naming/style check green; frontend builds; fresh-DB
flask db upgrade + seeds verified; QR targets verified by decoding
rendered codes.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
from flask import Blueprint, request
|
||||
from flask_jwt_extended import jwt_required
|
||||
|
||||
from shopdb.api import db, Asset, AssetType, OperatingSystem, Application, AppVersion, AuditLog, Communication, CommunicationType, success_response, error_response, paginated_response, ErrorCodes, get_pagination_params, paginate_query
|
||||
from shopdb.api import db, Asset, AssetType, OperatingSystem, Application, AppVersion, AuditLog, Communication, CommunicationType, Setting, success_response, error_response, paginated_response, ErrorCodes, get_pagination_params, paginate_query
|
||||
|
||||
from ..models import Computer, ComputerType, ComputerInstalledApp, AccessProtocol, ComputerAccess
|
||||
|
||||
@@ -42,7 +42,7 @@ def list_computer_types():
|
||||
@jwt_required(optional=True)
|
||||
def get_computer_type(type_id: int):
|
||||
"""Get a single computer type."""
|
||||
t = ComputerType.query.get(type_id)
|
||||
t = db.session.get(ComputerType, type_id)
|
||||
|
||||
if not t:
|
||||
return error_response(
|
||||
@@ -97,7 +97,7 @@ def create_computer_type():
|
||||
@require_permission('computers.edit')
|
||||
def update_computer_type(type_id: int):
|
||||
"""Update a computer type."""
|
||||
t = ComputerType.query.get(type_id)
|
||||
t = db.session.get(ComputerType, type_id)
|
||||
|
||||
if not t:
|
||||
return error_response(
|
||||
@@ -131,7 +131,7 @@ def update_computer_type(type_id: int):
|
||||
@require_permission('computers.delete')
|
||||
def delete_computer_type(type_id: int):
|
||||
"""Delete a computer type. Refused if any PC still uses it."""
|
||||
t = ComputerType.query.get(type_id)
|
||||
t = db.session.get(ComputerType, type_id)
|
||||
if not t:
|
||||
return error_response(ErrorCodes.NOT_FOUND, 'Computer type not found', http_code=404)
|
||||
inuse = Computer.query.filter_by(computertypeid=type_id).count()
|
||||
@@ -183,7 +183,7 @@ def create_protocol():
|
||||
@jwt_required()
|
||||
@require_permission('computers.edit')
|
||||
def update_protocol(protocol_id):
|
||||
p = AccessProtocol.query.get(protocol_id)
|
||||
p = db.session.get(AccessProtocol, protocol_id)
|
||||
if not p:
|
||||
return error_response(ErrorCodes.NOT_FOUND, 'Protocol not found', http_code=404)
|
||||
data = request.get_json() or {}
|
||||
@@ -202,7 +202,7 @@ def update_protocol(protocol_id):
|
||||
@jwt_required()
|
||||
@require_permission('computers.edit')
|
||||
def delete_protocol(protocol_id):
|
||||
p = AccessProtocol.query.get(protocol_id)
|
||||
p = db.session.get(AccessProtocol, protocol_id)
|
||||
if not p:
|
||||
return error_response(ErrorCodes.NOT_FOUND, 'Protocol not found', http_code=404)
|
||||
# If any PC still references it, deactivate rather than hard-delete.
|
||||
@@ -215,13 +215,19 @@ def delete_protocol(protocol_id):
|
||||
return success_response(message='Protocol deleted')
|
||||
|
||||
|
||||
def _computer_access_links(comp):
|
||||
def _pc_access_domain():
|
||||
# Contract-pure read of the pc_access_domain setting (no core.api import).
|
||||
row = Setting.query.filter_by(key='pc_access_domain').first()
|
||||
return ((row.value if row else '') or '').strip()
|
||||
|
||||
|
||||
def _computer_access_links(comp, domain=None):
|
||||
"""Resolved remote-access links for a computer: each enabled protocol's
|
||||
template filled with the PC hostname joined to the pc_access_domain setting.
|
||||
A hostname that is already an FQDN (has a dot) is used as-is."""
|
||||
from shopdb.core.api.settings import get_cached_settings
|
||||
settings = get_cached_settings()
|
||||
domain = (settings.get('pc_access_domain') or '').strip()
|
||||
A hostname that is already an FQDN (has a dot) is used as-is. Pass domain
|
||||
when calling in a loop to avoid one settings lookup per computer."""
|
||||
if domain is None:
|
||||
domain = _pc_access_domain()
|
||||
hostname = (comp.hostname or '').strip()
|
||||
if not hostname:
|
||||
host = ''
|
||||
@@ -375,10 +381,11 @@ def list_computers():
|
||||
|
||||
# Build response with both asset and computer data
|
||||
data = []
|
||||
accessdomain = _pc_access_domain()
|
||||
for comp in items:
|
||||
item = comp.asset.to_dict() if comp.asset else {}
|
||||
item['computer'] = comp.to_dict()
|
||||
item['accessmethods'] = _computer_access_links(comp)
|
||||
item['accessmethods'] = _computer_access_links(comp, domain=accessdomain)
|
||||
data.append(item)
|
||||
|
||||
return paginated_response(data, page, per_page, total)
|
||||
@@ -388,7 +395,7 @@ def list_computers():
|
||||
@jwt_required(optional=True)
|
||||
def get_computer(computer_id: int):
|
||||
"""Get a single computer with full details."""
|
||||
comp = Computer.query.get(computer_id)
|
||||
comp = db.session.get(Computer, computer_id)
|
||||
|
||||
if not comp:
|
||||
return error_response(
|
||||
@@ -562,7 +569,7 @@ def create_computer():
|
||||
@require_permission('computers.edit')
|
||||
def update_computer(computer_id: int):
|
||||
"""Update computer (both Asset and Computer records)."""
|
||||
comp = Computer.query.get(computer_id)
|
||||
comp = db.session.get(Computer, computer_id)
|
||||
|
||||
if not comp:
|
||||
return error_response(
|
||||
@@ -662,7 +669,7 @@ def update_computer(computer_id: int):
|
||||
@require_permission('computers.delete')
|
||||
def delete_computer(computer_id: int):
|
||||
"""Delete (soft delete) computer."""
|
||||
comp = Computer.query.get(computer_id)
|
||||
comp = db.session.get(Computer, computer_id)
|
||||
|
||||
if not comp:
|
||||
return error_response(
|
||||
@@ -691,7 +698,7 @@ def delete_computer(computer_id: int):
|
||||
@jwt_required(optional=True)
|
||||
def get_installed_apps(computer_id: int):
|
||||
"""Get all installed applications for a computer."""
|
||||
comp = Computer.query.get(computer_id)
|
||||
comp = db.session.get(Computer, computer_id)
|
||||
|
||||
if not comp:
|
||||
return error_response(
|
||||
@@ -715,7 +722,7 @@ def get_installed_apps(computer_id: int):
|
||||
@require_permission('computers.create')
|
||||
def add_installed_app(computer_id: int):
|
||||
"""Add an installed application to a computer."""
|
||||
comp = Computer.query.get(computer_id)
|
||||
comp = db.session.get(Computer, computer_id)
|
||||
|
||||
if not comp:
|
||||
return error_response(
|
||||
@@ -731,7 +738,7 @@ def add_installed_app(computer_id: int):
|
||||
appid = data['appid']
|
||||
|
||||
# Validate app exists
|
||||
if not Application.query.get(appid):
|
||||
if not db.session.get(Application, appid):
|
||||
return error_response(ErrorCodes.NOT_FOUND, f'Application {appid} not found', http_code=404)
|
||||
|
||||
# Check for duplicate
|
||||
@@ -805,7 +812,7 @@ def report_status(computer_id: int):
|
||||
This endpoint can be called periodically by a client agent
|
||||
to update status information.
|
||||
"""
|
||||
comp = Computer.query.get(computer_id)
|
||||
comp = db.session.get(Computer, computer_id)
|
||||
|
||||
if not comp:
|
||||
return error_response(
|
||||
@@ -817,8 +824,8 @@ def report_status(computer_id: int):
|
||||
data = request.get_json() or {}
|
||||
|
||||
# Update status fields
|
||||
from datetime import datetime
|
||||
comp.lastreporteddate = datetime.utcnow()
|
||||
from datetime import datetime, timezone
|
||||
comp.lastreporteddate = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
|
||||
if 'loggedinuser' in data:
|
||||
comp.loggedinuser = data['loggedinuser']
|
||||
|
||||
Reference in New Issue
Block a user