优化
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package biz
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
type AuthorityAccessRepo interface {
|
||||
CreateAuthority(context.Context, *Authority) error
|
||||
@@ -15,6 +18,21 @@ type AuthorityAccessRepo interface {
|
||||
ResolveDataScope(context.Context, uint, uint) (DataScope, error)
|
||||
}
|
||||
|
||||
// Authority is the domain representation of an administration role. Keep the
|
||||
// audit timestamps because exports and API clients use them even though the
|
||||
// administration screens do not display them.
|
||||
type Authority struct {
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt *time.Time
|
||||
AuthorityID uint
|
||||
AuthorityName string
|
||||
ParentID *uint
|
||||
DataScope int
|
||||
DefaultRouter string
|
||||
Children []*Authority
|
||||
}
|
||||
|
||||
type AuthorityUsecase struct{ AuthorityAccessRepo }
|
||||
|
||||
func NewAuthorityUsecase(repo AuthorityAccessRepo) *AuthorityUsecase {
|
||||
@@ -36,11 +54,11 @@ func (uc *AuthorityUsecase) AuthorityTree(ctx context.Context) ([]*Authority, er
|
||||
if item.ParentID != nil && *item.ParentID != 0 && byID[*item.ParentID] != nil {
|
||||
parent := byID[*item.ParentID]
|
||||
parent.Children = append(parent.Children, item)
|
||||
} else if item.ParentID == nil || *item.ParentID == 0 {
|
||||
} else if item.ParentID != nil && *item.ParentID == 0 {
|
||||
roots = append(roots, item)
|
||||
}
|
||||
}
|
||||
// In GVA strict-authority mode a non-root actor receives its direct
|
||||
// In strict-authority mode a non-root actor receives its direct
|
||||
// children as the top-level result even though their parent is omitted.
|
||||
if len(roots) == 0 {
|
||||
if actor, ok := ActorFromContext(ctx); ok {
|
||||
|
||||
Reference in New Issue
Block a user