优化结构
This commit is contained in:
@@ -131,15 +131,7 @@ func (r *authorityAccessRepo) ensureAuthorityParentAcyclic(ctx context.Context,
|
||||
}
|
||||
|
||||
func (r *authorityAccessRepo) CreateAuthority(ctx context.Context, value *system.Authority) error {
|
||||
if value.DataScope == 0 {
|
||||
value.DataScope = 1
|
||||
} else if value.DataScope < 1 || value.DataScope > 5 {
|
||||
return errInvalidDataScope
|
||||
}
|
||||
if err := r.checkDataScopeGrant(ctx, value.DataScope, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
actor, allowed, strict, err := r.strictAuthorityAccess(ctx)
|
||||
actor, allowed, strict, err := r.prepareAuthorityCreate(ctx, value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -208,16 +200,24 @@ func (r *authorityAccessRepo) CreateAuthority(ctx context.Context, value *system
|
||||
return nil
|
||||
})
|
||||
}
|
||||
func (r *authorityAccessRepo) CopyAuthority(ctx context.Context, sourceID uint, value *system.Authority) error {
|
||||
|
||||
func (r *authorityAccessRepo) prepareAuthorityCreate(ctx context.Context, value *system.Authority) (system.Actor, map[uint]bool, bool, error) {
|
||||
if value.DataScope == 0 {
|
||||
value.DataScope = 1
|
||||
} else if value.DataScope < 1 || value.DataScope > 5 {
|
||||
return errInvalidDataScope
|
||||
return system.Actor{}, nil, false, errInvalidDataScope
|
||||
}
|
||||
if err := r.checkDataScopeGrant(ctx, value.DataScope, nil); err != nil {
|
||||
return err
|
||||
return system.Actor{}, nil, false, err
|
||||
}
|
||||
actor, allowed, strict, err := r.strictAuthorityAccess(ctx)
|
||||
if err != nil {
|
||||
return system.Actor{}, nil, false, err
|
||||
}
|
||||
return actor, allowed, strict, nil
|
||||
}
|
||||
func (r *authorityAccessRepo) CopyAuthority(ctx context.Context, sourceID uint, value *system.Authority) error {
|
||||
actor, allowed, strict, err := r.prepareAuthorityCreate(ctx, value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user