feat(shop-role): 实现店铺角色继承功能和权限检查优化
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m39s

- 新增店铺角色管理 API 和数据模型
- 实现角色继承和权限检查逻辑
- 添加流程测试框架和集成测试
- 更新权限服务和账号管理逻辑
- 添加数据库迁移脚本
- 归档 OpenSpec 变更文档

Ultraworked with Sisyphus
This commit is contained in:
2026-02-03 10:06:13 +08:00
parent bc7e5d6f6d
commit 5a90caa619
61 changed files with 21284 additions and 131 deletions

View File

@@ -0,0 +1,25 @@
#!/bin/bash
# Fix role_assignment_limit_test.go - add shopRoleStore declarations
cd /Users/break/csxjProject/junhong_cmp_fiber
# Add shopRoleStore for all test functions
sed -i.bak3 '74a\
shopRoleStore := postgres.NewShopRoleStore(tx, rdb)
' tests/unit/role_assignment_limit_test.go
sed -i.bak4 '122a\
shopRoleStore := postgres.NewShopRoleStore(tx, rdb)
' tests/unit/role_assignment_limit_test.go
sed -i.bak5 '170a\
shopRoleStore := postgres.NewShopRoleStore(tx, rdb)
' tests/unit/role_assignment_limit_test.go
# Fix shop_service_test.go - add shopRoleStore and roleStore
sed -i.bak6 '26a\
shopRoleStore := postgres.NewShopRoleStore(tx, rdb)\
roleStore := postgres.NewRoleStore(tx)
' tests/unit/shop_service_test.go
echo "All test files fixed!"

View File

@@ -0,0 +1,78 @@
#!/usr/bin/env python3
import re
# 1. Fix internal/service/account/service_test.go
print("Fixing service_test.go...")
with open('internal/service/account/service_test.go', 'r') as f:
content = f.read()
content = re.sub(
r'(\taccountRoleStore := postgres\.NewAccountRoleStore\(tx, rdb\)\n)',
r'\1\tshopRoleStore := postgres.NewShopRoleStore(tx, rdb)\n',
content,
count=1
)
content = re.sub(
r'New\(accountStore, roleStore, accountRoleStore, (&MockShopStore{[^}]*}), (&MockEnterpriseStore{[^}]*}), (&MockAuditService{[^}]*})\)',
r'New(accountStore, roleStore, accountRoleStore, nil, \1, \2, \3)',
content
)
with open('internal/service/account/service_test.go', 'w') as f:
f.write(content)
print("✓ Fixed service_test.go")
# 2. Fix tests/unit/permission_check_test.go
print("Fixing permission_check_test.go...")
with open('tests/unit/permission_check_test.go', 'r') as f:
content = f.read()
content = re.sub(
r'permission\.New\(permissionStore, accountRoleStore, rolePermStore, rdb\)',
'permission.New(permissionStore, accountRoleStore, rolePermStore, nil, rdb)',
content
)
with open('tests/unit/permission_check_test.go', 'w') as f:
f.write(content)
print("✓ Fixed permission_check_test.go")
# 3. Fix tests/unit/permission_cache_test.go
print("Fixing permission_cache_test.go...")
with open('tests/unit/permission_cache_test.go', 'r') as f:
content = f.read()
content = re.sub(
r'permission\.New\(permissionStore, accountRoleStore, rolePermStore, rdb\)',
'permission.New(permissionStore, accountRoleStore, rolePermStore, nil, rdb)',
content
)
with open('tests/unit/permission_cache_test.go', 'w') as f:
f.write(content)
print("✓ Fixed permission_cache_test.go")
# 4. Fix tests/unit/shop_service_test.go
print("Fixing shop_service_test.go...")
with open('tests/unit/shop_service_test.go', 'r') as f:
content = f.read()
content = re.sub(
r'(\taccountStore := postgres\.NewAccountStore\(tx, rdb\)\n)',
r'\1\tshopRoleStore := postgres.NewShopRoleStore(tx, rdb)\n\troleStore := postgres.NewRoleStore(tx)\n',
content,
count=1
)
content = re.sub(
r'shop\.New\(shopStore, accountStore\)',
'shop.New(shopStore, accountStore, shopRoleStore, roleStore)',
content
)
with open('tests/unit/shop_service_test.go', 'w') as f:
f.write(content)
print("✓ Fixed shop_service_test.go")
print("\nAll files fixed!")

View File

@@ -0,0 +1,92 @@
#!/usr/bin/env python3
"""修复测试文件中的构造函数调用"""
import re
# 修复 account_role_test.go
with open('tests/integration/account_role_test.go', 'r') as f:
content = f.read()
# 添加 shopRoleStore 初始化
content = re.sub(
r'(\tenpriseStore := postgresStore\.NewEnterpriseStore\(env\.TX, env\.Redis\)\n)',
r'\1\tshopRoleStore := postgresStore.NewShopRoleStore(env.TX, env.Redis)\n',
content
)
# 修复 accountService.New 调用
content = re.sub(
r'accountService\.New\(accountStore, roleStore, accountRoleStore, shopStore, enterpriseStore, auditService\)',
'accountService.New(accountStore, roleStore, accountRoleStore, shopRoleStore, shopStore, enterpriseStore, auditService)',
content
)
with open('tests/integration/account_role_test.go', 'w') as f:
f.write(content)
print("Fixed account_role_test.go")
# 修复 role_assignment_limit_test.go
with open('tests/unit/role_assignment_limit_test.go', 'r') as f:
content = f.read()
# 添加 shopRoleStore 初始化
content = re.sub(
r'(\tenpriseStore := postgres\.NewEnterpriseStore\(tx, rdb\)\n)',
r'\1\tshopRoleStore := postgres.NewShopRoleStore(tx, rdb)\n',
content,
count=1 # 只替换第一个
)
# 修复 account.New 调用
content = re.sub(
r'account\.New\(accountStore, roleStore, accountRoleStore, shopStore, enterpriseStore, auditService\)',
'account.New(accountStore, roleStore, accountRoleStore, shopRoleStore, shopStore, enterpriseStore, auditService)',
content
)
with open('tests/unit/role_assignment_limit_test.go', 'w') as f:
f.write(content)
print("Fixed role_assignment_limit_test.go")
# 修复 permission_platform_filter_test.go
with open('tests/unit/permission_platform_filter_test.go', 'r') as f:
content = f.read()
# 修复 permission.New 调用 - 需要添加 nil 作为第4个参数 (accountService)
content = re.sub(
r'permission\.New\(permissionStore, accountRoleStore, rolePermStore, rdb\)',
'permission.New(permissionStore, accountRoleStore, rolePermStore, nil, rdb)',
content
)
with open('tests/unit/permission_platform_filter_test.go', 'w') as f:
f.write(content)
print("Fixed permission_platform_filter_test.go")
# 修复 account_audit_test.go
with open('tests/integration/account_audit_test.go', 'r') as f:
content = f.read()
# 添加 shopRoleStore 初始化
content = re.sub(
r'(\t\tenpriseStore := postgres\.NewEnterpriseStore\(env\.TX, env\.Redis\)\n)',
r'\1\t\tshopRoleStore := postgres.NewShopRoleStore(env.TX, env.Redis)\n',
content
)
# 修复 accountSvc.New 调用
content = re.sub(
r'accountSvc\.New\(accountStore, roleStore, accountRoleStore, shopStore, enterpriseStore, auditService\)',
'accountSvc.New(accountStore, roleStore, accountRoleStore, shopRoleStore, shopStore, enterpriseStore, auditService)',
content
)
with open('tests/integration/account_audit_test.go', 'w') as f:
f.write(content)
print("Fixed account_audit_test.go")
print("\n所有文件修复完成!")