product_management/wwwroot/api/product_delete.dspy
yumoqing 43787a63a4 fix: spec compliance pass - ServerEnv removal in .dspy, core.py DBPools singleton, scripts/load_path.py
- All .dspy files: replace ServerEnv() org_id access with await get_userorgid()
  (get_userorgid is registered as global in ahserver processorResource)
- core.py: simplify _get_db to use DBPools() singleton directly (DBPools is @SingletonDecorator)
  remove unnecessary db.databases = config.databases assignment
- core.py: add MODULE_NAME constant, use env.get_module_dbname(MODULE_NAME) pattern
- Create scripts/load_path.py with all RBAC paths per module-development-spec
  Covers: entry pages, feature .ui files, CRUD directories, all API .dspy endpoints
- .gitignore: add __pycache__/ exclusion
- All models/*.json and json/*.json pass spec validation checks
2026-05-25 17:03:08 +08:00

32 lines
1.0 KiB
Python

#!/usr/bin/env python3
import json
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
try:
user_id = await get_user()
org_id = (await get_userorgid()) or '0'
dbname = get_module_dbname('product_management')
data = dict(params_kw)
record_id = data.get('id')
if not record_id:
raise ValueError('Missing id')
async with DBPools().sqlorContext(dbname) as sor:
check = await sor.sqlExe(
"SELECT id FROM product WHERE id = ${id}$ AND org_id = ${org_id}$",
{'id': record_id, 'org_id': org_id}
)
if not check:
raise ValueError('无权删除该记录')
await sor.D('product', {'id': record_id, 'org_id': org_id})
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '产品删除成功', 'type': 'success'}}
except Exception as e:
result['options'] = {'title': 'Error', 'message': '删除失败: ' + str(e), 'type': 'error'}
return json.dumps(result, ensure_ascii=False)