fix: make order processing authorized and recoverable

This commit is contained in:
abaishu0730 committed 2026-10-21 09:32:50 +08:00
1 parent 0ab7d62aa6
commit 7e42a6dcc6
15 files changed
+219 -129

No files matched your search

+3 -1
View File
@@ -3,7 +3,7 @@ const {fail}=require('./validation.cjs');
async function orderRuleApi({orderRules,mail,workspace,user,route,method,body,reply,response}){
if(route!=='/api/order-rules'&&!route.startsWith('/api/order-rules/'))return false;
if(!orderRules)fail('分类通知规则服务未启动。',503);
if(route==='/api/order-rules'&&method==='GET'){reply(200,orderRules.snapshot());return true;}
if(route==='/api/order-rules'&&method==='GET'){reply(200,require('./access.cjs').publicSnapshot(orderRules,workspace,user));return true;}
if(route==='/api/order-rules/import-template'&&method==='GET'){
if(user.role!=='admin')fail('仅管理员可导出规则配置。',403);
const bytes=await require('./import-template.cjs').template(orderRules);response.writeHead(200,{'Content-Type':'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','Content-Disposition':"attachment; filename*=UTF-8''"+encodeURIComponent('分类规则.xlsx')});response.end(bytes);return true;
@@ -11,6 +11,8 @@ async function orderRuleApi({orderRules,mail,workspace,user,route,method,body,re
if(method!=='POST')fail('没有找到此规则操作。',404);
if(user.role==='viewer')fail('只读成员不能编辑规则或提交样本。',403);
const actor=user.username;
const migration=/^\/api\/order-rules\/rules\/([\w-]+)\/migration\/(preview|apply)$/.exec(route);
if(migration){if(user.role!=='admin')fail('仅管理员可迁移规则。',403);if(!body||Object.keys(body).some(k=>!['version','idempotencyKey','note'].includes(k)))fail('迁移参数无效。');reply(200,orderRules[migration[2]==='preview'?'previewMigration':'applyMigration'](migration[1],body,actor));return true;}
const trial=/^\/api\/order-rules\/rules\/([\w-]+)\/trial$/.exec(route);
if(trial){
if(body?.draft&&user.role!=='admin')fail('仅管理员可试运行编辑中的规则草稿。',403);