fix: 新增店铺时为初始账号分配默认角色
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m0s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m0s
问题:创建店铺时只创建了 shop_roles 记录(店铺可用角色), 但没有创建 account_roles 记录,导致初始账号没有任何权限。 修复:在创建初始账号后,立即为其分配默认角色到 account_roles 表。 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -96,7 +96,7 @@ func initServices(s *stores, deps *Dependencies) *services {
|
|||||||
Role: roleSvc.New(s.Role, s.Permission, s.RolePermission),
|
Role: roleSvc.New(s.Role, s.Permission, s.RolePermission),
|
||||||
Permission: permissionSvc.New(s.Permission, s.AccountRole, s.RolePermission, account, deps.Redis),
|
Permission: permissionSvc.New(s.Permission, s.AccountRole, s.RolePermission, account, deps.Redis),
|
||||||
PersonalCustomer: personalCustomerSvc.NewService(s.PersonalCustomer, s.PersonalCustomerPhone, deps.VerificationService, deps.JWTManager, deps.WechatOfficialAccount, deps.Logger),
|
PersonalCustomer: personalCustomerSvc.NewService(s.PersonalCustomer, s.PersonalCustomerPhone, deps.VerificationService, deps.JWTManager, deps.WechatOfficialAccount, deps.Logger),
|
||||||
Shop: shopSvc.New(s.Shop, s.Account, s.ShopRole, s.Role),
|
Shop: shopSvc.New(s.Shop, s.Account, s.ShopRole, s.Role, s.AccountRole),
|
||||||
Auth: authSvc.New(s.Account, s.AccountRole, s.RolePermission, s.Permission, s.Shop, deps.TokenManager, deps.Logger),
|
Auth: authSvc.New(s.Account, s.AccountRole, s.RolePermission, s.Permission, s.Shop, deps.TokenManager, deps.Logger),
|
||||||
ShopCommission: shopCommissionSvc.New(s.Shop, s.Account, s.AgentWallet, s.CommissionWithdrawalRequest, s.CommissionRecord),
|
ShopCommission: shopCommissionSvc.New(s.Shop, s.Account, s.AgentWallet, s.CommissionWithdrawalRequest, s.CommissionRecord),
|
||||||
CommissionWithdrawal: commissionWithdrawalSvc.New(deps.DB, s.Shop, s.Account, s.AgentWallet, s.AgentWalletTransaction, s.CommissionWithdrawalRequest),
|
CommissionWithdrawal: commissionWithdrawalSvc.New(deps.DB, s.Shop, s.Account, s.AgentWallet, s.AgentWalletTransaction, s.CommissionWithdrawalRequest),
|
||||||
|
|||||||
@@ -15,10 +15,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
shopStore *postgres.ShopStore
|
shopStore *postgres.ShopStore
|
||||||
accountStore *postgres.AccountStore
|
accountStore *postgres.AccountStore
|
||||||
shopRoleStore *postgres.ShopRoleStore
|
shopRoleStore *postgres.ShopRoleStore
|
||||||
roleStore *postgres.RoleStore
|
roleStore *postgres.RoleStore
|
||||||
|
accountRoleStore *postgres.AccountRoleStore
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(
|
func New(
|
||||||
@@ -26,12 +27,14 @@ func New(
|
|||||||
accountStore *postgres.AccountStore,
|
accountStore *postgres.AccountStore,
|
||||||
shopRoleStore *postgres.ShopRoleStore,
|
shopRoleStore *postgres.ShopRoleStore,
|
||||||
roleStore *postgres.RoleStore,
|
roleStore *postgres.RoleStore,
|
||||||
|
accountRoleStore *postgres.AccountRoleStore,
|
||||||
) *Service {
|
) *Service {
|
||||||
return &Service{
|
return &Service{
|
||||||
shopStore: shopStore,
|
shopStore: shopStore,
|
||||||
accountStore: accountStore,
|
accountStore: accountStore,
|
||||||
shopRoleStore: shopRoleStore,
|
shopRoleStore: shopRoleStore,
|
||||||
roleStore: roleStore,
|
roleStore: roleStore,
|
||||||
|
accountRoleStore: accountRoleStore,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,6 +123,18 @@ func (s *Service) Create(ctx context.Context, req *dto.CreateShopRequest) (*dto.
|
|||||||
return nil, errors.Wrap(errors.CodeInternalError, err, "创建初始账号失败")
|
return nil, errors.Wrap(errors.CodeInternalError, err, "创建初始账号失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 为初始账号分配默认角色
|
||||||
|
accountRole := &model.AccountRole{
|
||||||
|
AccountID: account.ID,
|
||||||
|
RoleID: req.DefaultRoleID,
|
||||||
|
Status: constants.StatusEnabled,
|
||||||
|
Creator: currentUserID,
|
||||||
|
Updater: currentUserID,
|
||||||
|
}
|
||||||
|
if err := s.accountRoleStore.Create(ctx, accountRole); err != nil {
|
||||||
|
return nil, errors.Wrap(errors.CodeInternalError, err, "为初始账号分配角色失败")
|
||||||
|
}
|
||||||
|
|
||||||
// 设置店铺默认角色
|
// 设置店铺默认角色
|
||||||
shopRole := &model.ShopRole{
|
shopRole := &model.ShopRole{
|
||||||
ShopID: shop.ID,
|
ShopID: shop.ID,
|
||||||
|
|||||||
Reference in New Issue
Block a user