Make main the lean product a site receives
main was 16 days and 259 commits behind the line the product is actually built on, at contract 0.30.0 against 0.35.0, with no per-PC credential code at all. It was neither current nor curated - just stale. This brings it forward and, at the same time, makes it mean something: main is what a receiving site installs, and nothing else. WHAT IT CARRIES. Twelve plugins - backups, computers, endpoints, guides, knowledgebase, machines, network, notifications, printers, slides, tools, warranty - plus applications, which is manifest-less core and always ships. The only manifest dependency inside that set is endpoints on computers, and both are in it, so the closure is self-contained. WHAT IT DOES NOT. employees, geenforce, measuringtools, printedparts and usb stay on the site line. So do the Windows installer tree, the VM rehearsal helpers, the agent tooling config, one site's data loader, the internal audit and findings records, and the planner spreadsheet. 1,135 tracked files against 1,438. A REMOVAL THAT BREAKS THE APP IS NOT A REMOVAL, and two nearly shipped: deploy/site-profile-universal.json still named all seventeen plugins. It is the file docs/DEPLOY.md tells a site to provision from, so a fresh install would have failed at `flask plugin apply-profile` with PluginError - the first thing a receiving site does, broken by the branch meant to serve them. It now names the twelve that exist, and its comment says the two must agree. agent/ was never refreshed. Whoever populated this branch copied shopdb/, plugins/, frontend/ and tests/ from the site line and left the agent tree at its September state: 22 C# and PowerShell sources missing, including AgentCredentials, EnrollmentService, AgentHttpFactory and the fleet-alert client, plus one file the site line had deleted still present. The old tree is internally consistent, so it compiles, and nothing in CI builds it - every gate was green over a server that speaks enrollment and per-PC credentials to a bundled agent source that cannot. Resynced whole. DECISIONS THIS ENCODES, rather than defers: - The plugin-authoring lab builds printedparts, whose manifest depends on employees, so it could not stay. The lab remains on the site line and main ships no build-along tutorial. That is a real loss for an adopting developer and is recorded here rather than discovered later. - Recognition, Training and Recertification notifications are no longer seeded. Each splits one notification into a card per employee and renders a photo, which needs a plugin this branch does not bundle. Seeding them would offer an author a type that cannot resolve anybody. A site that installs employees gets them from that plugin's own seed. - Windows/IIS is documented as the legacy path throughout, and the README leads with Docker, because that is what a receiving site gets. The API description is regenerated for THIS branch - 347 paths and 483 operations, down from 415 and 573 - so the published contract describes what is here rather than what the site line serves. docs/CONFIG.md lost the two measuring-tool label keys the code no longer declares, which two lanes had decided opposite ways. Suite: 3124 passed, 6 skipped. Naming and style gates pass. The docs gates run rather than skip, and every index line count is derived from the file it names.
This commit is contained in:
@@ -199,6 +199,32 @@ def seed_cli():
|
||||
pass
|
||||
|
||||
|
||||
@seed_cli.command('show-setup-token')
|
||||
@with_appcontext
|
||||
def show_setup_token():
|
||||
"""Display the setup token for first-admin creation.
|
||||
|
||||
The token gates POST /api/setup/create-admin so a network race cannot claim
|
||||
the instance during the install window. Startup only logs that a token is
|
||||
active (never the secret itself); this command is where it is read.
|
||||
"""
|
||||
import os
|
||||
from flask import current_app
|
||||
from shopdb.core.models import User
|
||||
|
||||
if User.query.count() > 0:
|
||||
click.echo(click.style("Setup already complete (users exist).", fg='green'))
|
||||
return
|
||||
|
||||
token = current_app.config.get('SETUP_TOKEN') or os.environ.get('SETUP_TOKEN')
|
||||
if token:
|
||||
click.echo(click.style("Setup token: ", fg='cyan') + token)
|
||||
click.echo("Use: curl -X POST .../api/setup/create-admin -H 'X-Setup-Token: <token>' ...")
|
||||
else:
|
||||
click.echo(click.style("No SETUP_TOKEN configured.", fg='yellow'))
|
||||
click.echo("Use 'flask seed admin' from inside the container (no token needed).")
|
||||
|
||||
|
||||
@seed_cli.command('catalog')
|
||||
@click.option('--file', 'path', default=None,
|
||||
help='catalog JSON to load (default shopdb/data/catalog.json)')
|
||||
@@ -317,8 +343,7 @@ def seed_catalog(path, dry_run):
|
||||
|
||||
# Small plugin vocabularies, loaded through the registry so a lean build
|
||||
# missing that plugin skips them instead of failing to import.
|
||||
for key, model_table, column in (('measuringtooltypes', 'measuringtooltypes', 'name'),
|
||||
('notificationtypes', 'notificationtypes', 'typename'),
|
||||
for key, model_table, column in (('notificationtypes', 'notificationtypes', 'typename'),
|
||||
('accessprotocols', 'accessprotocols', 'name')):
|
||||
model = by_table.get(model_table)
|
||||
if model is not None:
|
||||
@@ -713,9 +738,9 @@ def fix_controls_direction():
|
||||
computer and whose source is not. If the flipped row already exists, the
|
||||
reversed duplicate is deactivated instead. Idempotent.
|
||||
|
||||
Covers machines, measuring tools, printers and network devices. It used to
|
||||
match machines ONLY, so a CMM PC kept showing "<- controls from CMM4"
|
||||
alongside its own outgoing link and no amount of running this fixed it.
|
||||
Covers every non-computer asset type, not machines alone. It used to match
|
||||
machines ONLY, so a CMM PC kept showing "<- controls from CMM4" alongside
|
||||
its own outgoing link and no amount of running this fixed it.
|
||||
"""
|
||||
from sqlalchemy.orm import aliased
|
||||
from shopdb.extensions import db
|
||||
@@ -743,7 +768,7 @@ def fix_controls_direction():
|
||||
AssetRelationship.isactive == True,
|
||||
# ANY non-computer controlled BY a computer, not just machines. The
|
||||
# original filter said assettype == 'machine', which left every
|
||||
# measuring_tool -> computer row untouched - a CMM PC showing
|
||||
# non-machine -> computer row untouched - a CMM PC showing
|
||||
# "<- controls from CMM4" beside its own outgoing link, which is
|
||||
# exactly the shape this command exists to clean. Printers and
|
||||
# network devices reach shopdb the same way and had the same gap.
|
||||
@@ -784,7 +809,7 @@ def fix_controls_direction():
|
||||
@seed_cli.command('permissions')
|
||||
@with_appcontext
|
||||
def seed_permissions():
|
||||
"""Seed predefined permissions, and the guest role that can hold them."""
|
||||
"""Seed predefined permissions, the guest role, and the prebuilt scopes."""
|
||||
from shopdb.extensions import db
|
||||
from shopdb.core.models import Permission, Role
|
||||
|
||||
@@ -793,11 +818,23 @@ def seed_permissions():
|
||||
# on the upgrade it already runs. It holds nothing until somebody grants
|
||||
# it something, so seeding it changes no behaviour.
|
||||
guest = Role.seedguest()
|
||||
# AFTER Permission.seed(), which is load-bearing: seedscopes only links
|
||||
# permissions that exist as rows, so seeding the catalog first is what
|
||||
# lets a newly installed plugin's permissions reach the scopes in the
|
||||
# same command rather than on the next run.
|
||||
scopes = Role.seedscopes()
|
||||
db.session.commit()
|
||||
click.echo(click.style(f"{created} permissions created.", fg='green'))
|
||||
if guest:
|
||||
click.echo(click.style(
|
||||
"guest role created (holds no permissions).", fg='green'))
|
||||
for rolename in scopes['created']:
|
||||
click.echo(click.style(f"{rolename} role created.", fg='green'))
|
||||
for rolename, count in sorted(scopes['granted'].items()):
|
||||
click.echo(click.style(
|
||||
f"{rolename}: {count} permission(s) granted.", fg='green'))
|
||||
if not scopes['created'] and not scopes['granted']:
|
||||
click.echo("Prebuilt scopes already up to date.")
|
||||
|
||||
|
||||
@seed_cli.command('settings')
|
||||
@@ -834,9 +871,9 @@ def seed_demo(force):
|
||||
"""Seed a small, broad sample dataset for a dev/eval site.
|
||||
|
||||
Populates a handful of rows across every asset-based plugin (machines,
|
||||
computers, printers, network devices, measuring tools) plus 3D-printed
|
||||
parts, with supporting vendors/business-units/locations and a few
|
||||
relationships, so every screen has something to show. Run AFTER
|
||||
computers, printers, network devices), with supporting
|
||||
vendors/business-units/locations and a few relationships, so every screen
|
||||
has something to show. Run AFTER
|
||||
`flask seed reference-data` and after the plugins are installed. Idempotent:
|
||||
all rows are keyed on the DEMO- prefix and skipped if already present.
|
||||
|
||||
@@ -926,7 +963,6 @@ def seed_demo(force):
|
||||
Computer = _subtype_model('computers', 'Computer')
|
||||
Printer = _subtype_model('printers', 'Printer')
|
||||
NetworkDevice = _subtype_model('network', 'NetworkDevice')
|
||||
MeasuringTool = _subtype_model('measuringtools', 'MeasuringTool')
|
||||
|
||||
machines = [
|
||||
('MILL-01', 'Haas VF-2 Mill', 'In Use', 'Cell A', 'Machining'),
|
||||
@@ -972,42 +1008,6 @@ def seed_demo(force):
|
||||
make_asset('network_device', num, name, NetworkDevice, status=st,
|
||||
location=loc, unit='IT')
|
||||
|
||||
tools = [
|
||||
('CMM-01', 'Zeiss CMM', 'In Use', 'QA Lab'),
|
||||
('GAGE-01', 'Height Gage', 'In Use', 'QA Lab'),
|
||||
('GAGE-02', 'Bore Gage', 'In Use', 'QA Lab'),
|
||||
('MIC-01', 'Digital Micrometer', 'In Use', 'Cell A'),
|
||||
('CAL-01', 'Digital Caliper', 'Inventory', 'QA Lab'),
|
||||
]
|
||||
for num, name, st, loc in tools:
|
||||
make_asset('measuring_tool', num, name, MeasuringTool, status=st,
|
||||
location=loc, unit='Inspection')
|
||||
|
||||
# 3D-printed parts are not assets - own table. A couple sit below their
|
||||
# low-stock threshold on purpose so the low-stock alert has something to fire.
|
||||
printedparts_made = 0
|
||||
try:
|
||||
from plugins.printedparts.models import PrintedItem
|
||||
parts = [
|
||||
# itemname, itemcode, gagelabtag, qty, threshold, bin
|
||||
('Fixture Bracket', 'PP0001', 'WJRP10021', 12, 4, 'A1'),
|
||||
('Gage Holder', 'PP0002', 'WJRP10022', 3, 5, 'A2'),
|
||||
('Cable Clip', 'PP0003', None, 40, 10, 'B1'),
|
||||
('Sensor Mount', 'PP0004', 'WJRP10023', 2, 6, 'B2'),
|
||||
('Label Guide', 'PP0005', None, 25, 8, 'C1'),
|
||||
('Knob Cover', 'PP0006', None, 0, 3, 'C2'),
|
||||
]
|
||||
for name, code, tag, qty, thr, binloc in parts:
|
||||
if PrintedItem.query.filter_by(itemcode=code).first():
|
||||
continue
|
||||
db.session.add(PrintedItem(
|
||||
itemname=name, itemcode=code, gagelabtag=tag,
|
||||
quantityonhand=qty, lowstockthreshold=thr, binlocation=binloc,
|
||||
itemdescription=f'Sample 3D-printed part: {name}.'))
|
||||
printedparts_made += 1
|
||||
except ImportError:
|
||||
pass # printedparts plugin not installed - skip
|
||||
|
||||
db.session.flush()
|
||||
|
||||
# A few relationships so the map + relationship cards are not empty.
|
||||
@@ -1048,7 +1048,7 @@ def seed_demo(force):
|
||||
db.session.commit()
|
||||
click.echo(click.style(
|
||||
f"Demo data seeded: {made['assets']} assets, "
|
||||
f"{printedparts_made} printed parts, {rels_made} relationships "
|
||||
f"{rels_made} relationships "
|
||||
f"({made['skipped']} already existed).", fg='green'))
|
||||
click.echo("Remove later with: flask seed demo-clear")
|
||||
|
||||
@@ -1057,31 +1057,22 @@ def seed_demo(force):
|
||||
@click.option('--yes', is_flag=True, help='Skip the confirmation prompt.')
|
||||
@with_appcontext
|
||||
def seed_demo_clear(yes):
|
||||
"""Delete everything `flask seed demo` created (DEMO- assets + sample parts).
|
||||
"""Delete everything `flask seed demo` created (the DEMO- assets).
|
||||
|
||||
Only touches rows the demo seeder made: assets with the DEMO- prefix (their
|
||||
plugin subtype rows cascade) and the PP000x sample printed parts. Leaves
|
||||
reference data, settings, users, and any real/imported rows alone.
|
||||
Only touches rows the demo seeder made: assets with the DEMO- prefix, whose
|
||||
plugin subtype rows cascade. Leaves reference data, settings, users, and any
|
||||
real/imported rows alone.
|
||||
"""
|
||||
from shopdb.extensions import db
|
||||
from shopdb.core.models import Asset
|
||||
|
||||
demo_ids = [a.assetid for a in Asset.query.filter(
|
||||
Asset.assetnumber.like(f'{DEMO_PREFIX}%')).all()]
|
||||
try:
|
||||
from plugins.printedparts.models import PrintedItem
|
||||
parts_count = PrintedItem.query.filter(
|
||||
PrintedItem.itemcode.like('PP000%')).count()
|
||||
except ImportError:
|
||||
parts_count = 0
|
||||
|
||||
if not demo_ids and not parts_count:
|
||||
if not demo_ids:
|
||||
click.echo(click.style("No demo data found.", fg='yellow'))
|
||||
return
|
||||
if not yes:
|
||||
click.confirm(
|
||||
f"Delete {len(demo_ids)} demo assets and "
|
||||
f"{parts_count} sample parts?", abort=True)
|
||||
click.confirm(f"Delete {len(demo_ids)} demo assets?", abort=True)
|
||||
|
||||
if demo_ids:
|
||||
# Drop the demo relationships first - assetrelationships has no cascade
|
||||
@@ -1098,16 +1089,9 @@ def seed_demo_clear(yes):
|
||||
Asset.query.filter(Asset.assetid.in_(demo_ids)).delete(
|
||||
synchronize_session=False)
|
||||
|
||||
parts_deleted = 0
|
||||
if parts_count:
|
||||
parts_deleted = PrintedItem.query.filter(
|
||||
PrintedItem.itemcode.like('PP000%')).delete(
|
||||
synchronize_session=False)
|
||||
|
||||
db.session.commit()
|
||||
click.echo(click.style(
|
||||
f"Removed {len(demo_ids)} demo assets and "
|
||||
f"{parts_deleted} sample parts.", fg='green'))
|
||||
f"Removed {len(demo_ids)} demo assets.", fg='green'))
|
||||
|
||||
|
||||
@click.group('csv')
|
||||
@@ -1372,7 +1356,7 @@ def audit_relationships():
|
||||
its own page and is never meaningful.
|
||||
|
||||
3. DUPLICATE DEVICES. One PC controlling several assets of the same type -
|
||||
three measuring tools for one physical CMM, say. The collector keys its
|
||||
three machine rows for one physical CMM, say. The collector keys its
|
||||
idempotency on its own label, so a device somebody created by hand, or
|
||||
the legacy import created, is invisible to it and it mints another one on
|
||||
every fresh PC.
|
||||
|
||||
Reference in New Issue
Block a user