oms/backend/app/middleware/group_scope.js
liufumingren b59ca6a0a8 feat(warehouse): 外部仓库货主权限收敛与库存同步口径
- 新增 groupScope 中间件:接口配置、字段、快递映射、调用日志仅集团权限可用,仓库维护只读放行
- 仓库列表/下拉/详情限定为自己所属公司(货主),越权访问返回 403
- 仓库商品与库存仅展示、推送、同步该仓库所属货主的商品,越界商品直接拒绝
- 「外部仓库」页在所在公司范围下收起新增/导出/接口配置/操作列与无关标签页,默认进入商品页
- 所属公司文案统一为「货主」
- 库存同步结果按商品统计(skipped/skipped_kinds/invalid_count),提示改为「N 个商品数量一致无需同步」

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-05 00:50:49 +08:00

29 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/**
* 集团权限校验中间件
*
* 「所在公司」权限的账号只能在外部仓库做「推送商品 / 同步库存 / 查询库存」,
* 仓库与接口配置的维护(新增/编辑/删除/接口配置/快递映射/调用日志等)仅集团权限可用。
*
* @param {Object} [options] 配置项
* @param {boolean} [options.allowGet] 是否放行 GET(查询类接口,如仓库列表/详情)
* @return {Function} koa 中间件
*/
module.exports = (options = {}) => {
const allowGet = !!options.allowGet;
return async (ctx, next) => {
const principalId = ctx.state.principalId != null
? ctx.state.principalId
: (ctx.query.principal_id != null ? ctx.query.principal_id : (ctx.request.body || {}).principal_id);
const access = await ctx.service.access.resolve(ctx.userId, principalId);
if (!access.isGroup && !(allowGet && ctx.method === 'GET')) {
ctx.status = 403;
ctx.body = { code: 403, message: '所在公司权限仅支持推送商品、同步库存与查询库存' };
return;
}
await next();
};
};