fix(douyu): 台账投影限制仅约束非管理员
- 人工 source_type=manual 订单完全不受投影限制 - 平台来源订单普通客服/运营只读,超级管理员可修正并审计 - 前端管理员解锁投影字段,普通账号仍只读 - 补充管理员/客服两条权限测试
This commit is contained in:
@@ -636,13 +636,15 @@ manual_override_at
|
|||||||
|
|
||||||
- 「斗鱼外部单协作」改名为「斗鱼订单台账」,菜单同步改名;
|
- 「斗鱼外部单协作」改名为「斗鱼订单台账」,菜单同步改名;
|
||||||
- 平台来源订单(`source_type=platform_fulfillment`)在台账里:
|
- 平台来源订单(`source_type=platform_fulfillment`)在台账里:
|
||||||
- 订单号、账号、礼包、商品、积分字段只读;
|
- 非管理员:订单号、账号、礼包、商品、积分字段只读;
|
||||||
|
- 超级管理员:可修正,操作会记录审计;
|
||||||
- 页面显示「来源:直播账号履约任务 #ID」;
|
- 页面显示「来源:直播账号履约任务 #ID」;
|
||||||
- 解除账号、推荐账号入口隐藏;
|
- 解除账号、推荐账号入口隐藏;
|
||||||
- 后端 `update_order` 拒绝平台来源订单修改投影字段:
|
- 后端 `update_order` 对**非管理员**拒绝平台来源订单修改投影字段:
|
||||||
`platform_projection_readonly`;
|
`platform_projection_readonly`;
|
||||||
- 后端 `set_account` 对平台来源订单要求显式
|
- 后端 `set_account` 对**非管理员**要求显式
|
||||||
`takeover_platform_lease=True`,否则拒绝;
|
`takeover_platform_lease=True`,否则拒绝;
|
||||||
|
- **超级管理员保留全部修正权限**;人工新建的 `source_type=manual` 订单完全不受限制。
|
||||||
- 保留显式接管流程(服务层),供特殊异常单使用。
|
- 保留显式接管流程(服务层),供特殊异常单使用。
|
||||||
|
|
||||||
尚未完成(下一刀):
|
尚未完成(下一刀):
|
||||||
|
|||||||
@@ -762,12 +762,19 @@ class TestDouyuCollabOrders:
|
|||||||
created_by=self.admin.id,
|
created_by=self.admin.id,
|
||||||
)
|
)
|
||||||
self.session.add(order)
|
self.session.add(order)
|
||||||
|
support = User(
|
||||||
|
username="douyu-collab-support-projection",
|
||||||
|
password_hash="hash",
|
||||||
|
role="support",
|
||||||
|
is_active=True,
|
||||||
|
)
|
||||||
|
self.session.add(support)
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
|
|
||||||
with pytest.raises(collab.CollabError) as exc_info:
|
with pytest.raises(collab.CollabError) as exc_info:
|
||||||
collab.update_order(
|
collab.update_order(
|
||||||
self.session,
|
self.session,
|
||||||
self.admin,
|
support,
|
||||||
order,
|
order,
|
||||||
{"gift_name": "礼包B"},
|
{"gift_name": "礼包B"},
|
||||||
expected_version=order.version,
|
expected_version=order.version,
|
||||||
@@ -775,14 +782,16 @@ class TestDouyuCollabOrders:
|
|||||||
assert exc_info.value.code == "platform_projection_readonly"
|
assert exc_info.value.code == "platform_projection_readonly"
|
||||||
assert order.gift_name == "礼包A"
|
assert order.gift_name == "礼包A"
|
||||||
|
|
||||||
|
# 管理员保留全部修正权限
|
||||||
collab.update_order(
|
collab.update_order(
|
||||||
self.session,
|
self.session,
|
||||||
self.admin,
|
self.admin,
|
||||||
order,
|
order,
|
||||||
{"remark": "财务补充备注"},
|
{"gift_name": "礼包B", "remark": "管理员修正投影"},
|
||||||
expected_version=order.version,
|
expected_version=order.version,
|
||||||
)
|
)
|
||||||
assert order.remark == "财务补充备注"
|
assert order.gift_name == "礼包B"
|
||||||
|
assert order.remark == "管理员修正投影"
|
||||||
|
|
||||||
def test_platform_source_set_account_requires_explicit_takeover(self):
|
def test_platform_source_set_account_requires_explicit_takeover(self):
|
||||||
order = collab.DouyuExternalOrder(
|
order = collab.DouyuExternalOrder(
|
||||||
@@ -796,12 +805,19 @@ class TestDouyuCollabOrders:
|
|||||||
created_by=self.admin.id,
|
created_by=self.admin.id,
|
||||||
)
|
)
|
||||||
self.session.add(order)
|
self.session.add(order)
|
||||||
|
support = User(
|
||||||
|
username="douyu-collab-support-set-account",
|
||||||
|
password_hash="hash",
|
||||||
|
role="support",
|
||||||
|
is_active=True,
|
||||||
|
)
|
||||||
|
self.session.add(support)
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
|
|
||||||
with pytest.raises(collab.CollabError) as exc_info:
|
with pytest.raises(collab.CollabError) as exc_info:
|
||||||
collab.set_account(
|
collab.set_account(
|
||||||
self.session,
|
self.session,
|
||||||
self.admin,
|
support,
|
||||||
order,
|
order,
|
||||||
self.account.username,
|
self.account.username,
|
||||||
client=FakeClient(),
|
client=FakeClient(),
|
||||||
|
|||||||
@@ -959,8 +959,12 @@ def update_order(
|
|||||||
if new != old:
|
if new != old:
|
||||||
changes[field] = {"old": old, "new": new}
|
changes[field] = {"old": old, "new": new}
|
||||||
|
|
||||||
if order.source_type == SOURCE_TYPE_PLATFORM_FULFILLMENT:
|
if (
|
||||||
|
order.source_type == SOURCE_TYPE_PLATFORM_FULFILLMENT
|
||||||
|
and current.role != "super_admin"
|
||||||
|
):
|
||||||
# 平台来源台账单是履约任务的投影:订单号/商品/积分/账号由平台维护。
|
# 平台来源台账单是履约任务的投影:订单号/商品/积分/账号由平台维护。
|
||||||
|
# 超级管理员保留全部修正权限;普通运营/客服只能走接管转人工。
|
||||||
# 账号变更只有显式“接管转人工”才允许,避免协作页静默改出两个账号。
|
# 账号变更只有显式“接管转人工”才允许,避免协作页静默改出两个账号。
|
||||||
projected = PLATFORM_PROJECTED_FIELDS.intersection(changes)
|
projected = PLATFORM_PROJECTED_FIELDS.intersection(changes)
|
||||||
if "account_username" in projected and takeover_platform_lease:
|
if "account_username" in projected and takeover_platform_lease:
|
||||||
@@ -1099,6 +1103,7 @@ def set_account(
|
|||||||
_assert_version(order, expected_version)
|
_assert_version(order, expected_version)
|
||||||
if (
|
if (
|
||||||
order.source_type == SOURCE_TYPE_PLATFORM_FULFILLMENT
|
order.source_type == SOURCE_TYPE_PLATFORM_FULFILLMENT
|
||||||
|
and current.role != "super_admin"
|
||||||
and not takeover_platform_lease
|
and not takeover_platform_lease
|
||||||
):
|
):
|
||||||
raise CollabError(
|
raise CollabError(
|
||||||
|
|||||||
@@ -168,6 +168,7 @@ export default function DouyuCollabPage() {
|
|||||||
const [editing, setEditing] = useState<DouyuCollabOrder | null>(null);
|
const [editing, setEditing] = useState<DouyuCollabOrder | null>(null);
|
||||||
const successfulPurchaseFieldsLocked = Boolean(editing?.succeeded_at && !isAdmin);
|
const successfulPurchaseFieldsLocked = Boolean(editing?.succeeded_at && !isAdmin);
|
||||||
const isPlatformProjection = editing?.source_type === 'platform_fulfillment';
|
const isPlatformProjection = editing?.source_type === 'platform_fulfillment';
|
||||||
|
const platformProjectionLocked = isPlatformProjection && !isAdmin;
|
||||||
const [form, setForm] = useState<OrderFormState>(EMPTY_FORM);
|
const [form, setForm] = useState<OrderFormState>(EMPTY_FORM);
|
||||||
const [lookup, setLookup] = useState<DouyuCollabAccountLookup | null>(null);
|
const [lookup, setLookup] = useState<DouyuCollabAccountLookup | null>(null);
|
||||||
const lookupSeq = useRef(0);
|
const lookupSeq = useRef(0);
|
||||||
@@ -624,7 +625,7 @@ export default function DouyuCollabPage() {
|
|||||||
expected_version: editing.version,
|
expected_version: editing.version,
|
||||||
confirm_purchase_change: confirmPurchaseChange,
|
confirm_purchase_change: confirmPurchaseChange,
|
||||||
takeover_platform_lease: takeoverPlatformLease,
|
takeover_platform_lease: takeoverPlatformLease,
|
||||||
...(!isPlatformProjection
|
...(!platformProjectionLocked
|
||||||
? {
|
? {
|
||||||
order_no: form.order_no.trim(),
|
order_no: form.order_no.trim(),
|
||||||
account_username: form.account_username.trim(),
|
account_username: form.account_username.trim(),
|
||||||
@@ -2183,7 +2184,11 @@ export default function DouyuCollabPage() {
|
|||||||
type="info"
|
type="info"
|
||||||
showIcon
|
showIcon
|
||||||
message="本单来自直播账号履约工作台"
|
message="本单来自直播账号履约工作台"
|
||||||
description={`履约任务 #${editing?.source_task_id ?? '-'} 的账号、订单号、礼包和积分由履约工作台维护;这里只维护财务、备注和主页截图。`}
|
description={
|
||||||
|
isAdmin
|
||||||
|
? `履约任务 #${editing?.source_task_id ?? '-'} 的投影字段由履约工作台维护;管理员可直接修正,修正会记录审计。`
|
||||||
|
: `履约任务 #${editing?.source_task_id ?? '-'} 的账号、订单号、礼包和积分由履约工作台维护;这里只维护财务、备注和主页截图。`
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{!editing && (
|
{!editing && (
|
||||||
@@ -2230,7 +2235,7 @@ export default function DouyuCollabPage() {
|
|||||||
value={form.order_no}
|
value={form.order_no}
|
||||||
maxLength={64}
|
maxLength={64}
|
||||||
placeholder="订单编号"
|
placeholder="订单编号"
|
||||||
disabled={successfulPurchaseFieldsLocked || isPlatformProjection}
|
disabled={successfulPurchaseFieldsLocked || platformProjectionLocked}
|
||||||
onChange={(event) => updateForm('order_no', event.target.value)}
|
onChange={(event) => updateForm('order_no', event.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -2272,12 +2277,12 @@ export default function DouyuCollabPage() {
|
|||||||
<Input
|
<Input
|
||||||
value={form.account_username}
|
value={form.account_username}
|
||||||
placeholder="输入内部斗鱼账号用户名,停止输入后自动查询"
|
placeholder="输入内部斗鱼账号用户名,停止输入后自动查询"
|
||||||
disabled={successfulPurchaseFieldsLocked || isPlatformProjection}
|
disabled={successfulPurchaseFieldsLocked || platformProjectionLocked}
|
||||||
onChange={(event) => updateForm('account_username', event.target.value)}
|
onChange={(event) => updateForm('account_username', event.target.value)}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
loading={lookupLoading}
|
loading={lookupLoading}
|
||||||
disabled={successfulPurchaseFieldsLocked || isPlatformProjection}
|
disabled={successfulPurchaseFieldsLocked || platformProjectionLocked}
|
||||||
onClick={() => void handleLookup()}
|
onClick={() => void handleLookup()}
|
||||||
>
|
>
|
||||||
查询账号
|
查询账号
|
||||||
@@ -2301,7 +2306,7 @@ export default function DouyuCollabPage() {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{editing &&
|
{editing &&
|
||||||
!isPlatformProjection &&
|
!platformProjectionLocked &&
|
||||||
canReplaceAccount &&
|
canReplaceAccount &&
|
||||||
!editing.succeeded_at &&
|
!editing.succeeded_at &&
|
||||||
editing.status !== 'done' &&
|
editing.status !== 'done' &&
|
||||||
@@ -2338,7 +2343,7 @@ export default function DouyuCollabPage() {
|
|||||||
allowClear
|
allowClear
|
||||||
value={form.gift_name}
|
value={form.gift_name}
|
||||||
options={giftNameOptions}
|
options={giftNameOptions}
|
||||||
disabled={successfulPurchaseFieldsLocked || isPlatformProjection}
|
disabled={successfulPurchaseFieldsLocked || platformProjectionLocked}
|
||||||
placeholder={
|
placeholder={
|
||||||
goodsPool.length || giftRecords.length
|
goodsPool.length || giftRecords.length
|
||||||
? '输入礼包名称,或选择已有礼包'
|
? '输入礼包名称,或选择已有礼包'
|
||||||
@@ -2354,7 +2359,7 @@ export default function DouyuCollabPage() {
|
|||||||
optionFilterProp="label"
|
optionFilterProp="label"
|
||||||
value={form.gift_name || undefined}
|
value={form.gift_name || undefined}
|
||||||
options={giftNameOptions}
|
options={giftNameOptions}
|
||||||
disabled={successfulPurchaseFieldsLocked || isPlatformProjection}
|
disabled={successfulPurchaseFieldsLocked || platformProjectionLocked}
|
||||||
placeholder={
|
placeholder={
|
||||||
giftNameOptions.length
|
giftNameOptions.length
|
||||||
? '选择礼包(由管理员统一维护)'
|
? '选择礼包(由管理员统一维护)'
|
||||||
@@ -2380,7 +2385,7 @@ export default function DouyuCollabPage() {
|
|||||||
min={0}
|
min={0}
|
||||||
precision={0}
|
precision={0}
|
||||||
value={form.required_points}
|
value={form.required_points}
|
||||||
disabled={!canManage || successfulPurchaseFieldsLocked || isPlatformProjection}
|
disabled={!canManage || successfulPurchaseFieldsLocked || platformProjectionLocked}
|
||||||
placeholder={canManage ? '手动填写;选择礼包后自动带出' : '由管理员统一配置'}
|
placeholder={canManage ? '手动填写;选择礼包后自动带出' : '由管理员统一配置'}
|
||||||
onChange={(value) => updateForm('required_points', value ?? null)}
|
onChange={(value) => updateForm('required_points', value ?? null)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user