Files
xenia-pos-local/local_backend/models/site_module.py
T
bonaminandClaude Opus 5.5 231a97c186 feat(backend): module registry, manifests, enable/disable without restart
Platform v2 step 1.3 (APPS_PLATFORM §4, §5.3, D-4, D-19).
- core/modules: Module/Perm/Limit/SettingDef/DeviceApp/Mount model; registry
  that discovers modules/<key>/manifest.py and validates it (keys, kinds,
  dependencies and cycles, permission prefixes and roles, unique settings,
  each router claimed once and importable, device_app only on apps, workers);
  free_tier.py (D-5 constant, used from 1.4)
- 25 manifests (the §4.2 map) with permission keys + default roles derived
  from today's perm_* meaning, limits, device apps and the 55 settings
- main.py mounts every router from the manifests; non-core routers carry
  Depends(module_required(key)) -> 403 module.disabled while off
- site_modules table (revision 0004), cached enablement; disabling a module
  also turns off modules that depend on it; core can't be disabled
- worker supervisor: connect_menu / connect_orders / connect_remote are now
  separate workers (v1's single _connect_loop split), started and stopped as
  their modules turn on and off; crashes are logged and restarted
- GET /api/platform/bootstrap (venue name/tz/language/currency, effective
  modules, user, language, role-template permission keys), GET /modules,
  PUT /modules/{key}
- settings API derives its key list and defaults from the manifests
- reports router split: history endpoints on history_router (`history`
  module, free tier later) under the same /api/reports prefix
- tests: registry validation, mount coverage, toggle round-trip, dependency
  propagation, bootstrap/catalogue shape, supervisor; pack rule CS-13

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 17:46:52 +02:00

20 lines
743 B
Python

"""Site enablement of modules (APPS_PLATFORM §5.3, D-4).
A module with no row is enabled (opt-out). Disabling keeps all data; it hides the UI,
makes the module's endpoints answer `module.disabled` and stops its workers.
Read and written through core/modules/state.py only.
"""
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
from core.timeutil import UTCDateTime, utcnow
from database import Base
class SiteModule(Base):
__tablename__ = "site_modules"
key = Column(String, primary_key=True)
enabled = Column(Boolean, nullable=False, default=True)
updated_at = Column(UTCDateTime, nullable=False, default=utcnow, onupdate=utcnow)
updated_by = Column(Integer, ForeignKey("users.id"), nullable=True)