Files
junhong_cmp_fiber/internal/service/account/role_resolver.go
huang 5a90caa619
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m39s
feat(shop-role): 实现店铺角色继承功能和权限检查优化
- 新增店铺角色管理 API 和数据模型
- 实现角色继承和权限检查逻辑
- 添加流程测试框架和集成测试
- 更新权限服务和账号管理逻辑
- 添加数据库迁移脚本
- 归档 OpenSpec 变更文档

Ultraworked with Sisyphus
2026-02-03 10:06:13 +08:00

38 lines
1.0 KiB
Go

package account
import (
"context"
"github.com/break/junhong_cmp_fiber/pkg/constants"
"github.com/break/junhong_cmp_fiber/pkg/errors"
)
func (s *Service) GetRoleIDsForAccount(ctx context.Context, accountID uint) ([]uint, error) {
account, err := s.accountStore.GetByID(ctx, accountID)
if err != nil {
return nil, errors.Wrap(errors.CodeInternalError, err, "查询账号失败")
}
if account.UserType == constants.UserTypeSuperAdmin {
return []uint{}, nil
}
accountRoles, err := s.accountRoleStore.GetRoleIDsByAccountID(ctx, accountID)
if err != nil {
return nil, errors.Wrap(errors.CodeInternalError, err, "查询账号角色失败")
}
if len(accountRoles) > 0 {
return accountRoles, nil
}
if account.UserType == constants.UserTypeAgent && account.ShopID != nil {
shopRoles, err := s.shopRoleStore.GetRoleIDsByShopID(ctx, *account.ShopID)
if err != nil {
return nil, errors.Wrap(errors.CodeInternalError, err, "查询店铺角色失败")
}
return shopRoles, nil
}
return []uint{}, nil
}