优化结构

This commit is contained in:
Yvan
2026-08-22 12:13:16 +08:00
parent d987244d0e
commit b27a66e9d3
200 changed files with 1794 additions and 1715 deletions
+8 -9
View File
@@ -3,10 +3,9 @@ package system
import (
"context"
"errors"
"kra/internal/biz/system"
"strconv"
"kra/internal/biz"
"github.com/casbin/casbin/v3"
casbinmodel "github.com/casbin/casbin/v3/model"
"gorm.io/gorm"
@@ -43,7 +42,7 @@ func (r *apiRepo) SetAPIRoles(ctx context.Context, path, method string, ids []ui
return errors.New("您提交的角色ID不合法")
}
}
if err := r.checkPolicyPathsAuth(ctx, []*biz.API{{Path: path, Method: method}}); err != nil {
if err := r.checkPolicyPathsAuth(ctx, []*system.API{{Path: path, Method: method}}); err != nil {
return err
}
}
@@ -105,21 +104,21 @@ m = r.sub == p.sub && keyMatch2(r.obj, p.obj) && r.act == p.act`)
}
return enforcer.Enforce(subject, path, method)
}
func (r *apiRepo) PolicyPaths(ctx context.Context, aid uint) ([]*biz.API, error) {
func (r *apiRepo) PolicyPaths(ctx context.Context, aid uint) ([]*system.API, error) {
rows, err := policyRowsForAuthority(r.data.DB().WithContext(ctx), aid)
if err != nil {
return nil, err
}
var out []*biz.API
var out []*system.API
if len(rows) > 0 {
out = make([]*biz.API, 0, len(rows))
out = make([]*system.API, 0, len(rows))
}
for _, row := range rows {
out = append(out, &biz.API{Path: row.V1, Method: row.V2})
out = append(out, &system.API{Path: row.V1, Method: row.V2})
}
return out, nil
}
func (r *apiRepo) SetPolicyPaths(ctx context.Context, aid uint, paths []*biz.API) error {
func (r *apiRepo) SetPolicyPaths(ctx context.Context, aid uint, paths []*system.API) error {
if err := (&authorityAccessRepo{data: r.data}).checkAuthorityIDAuth(ctx, aid); err != nil {
return err
}
@@ -155,7 +154,7 @@ func (r *apiRepo) SetPolicyPaths(ctx context.Context, aid uint, paths []*biz.API
return nil
}
func (r *apiRepo) checkPolicyPathsAuth(ctx context.Context, paths []*biz.API) error {
func (r *apiRepo) checkPolicyPathsAuth(ctx context.Context, paths []*system.API) error {
actor, _, strict, err := (&authorityAccessRepo{data: r.data}).strictAuthorityAccess(ctx)
if err != nil || !strict {
return err