优化
This commit is contained in:
+29
-10
@@ -57,21 +57,40 @@ type PermissionRepo interface {
|
||||
CanRemoveButton(context.Context, uint) (bool, error)
|
||||
}
|
||||
|
||||
type AccessRepo interface {
|
||||
AuthorityAccessRepo
|
||||
APIRepo
|
||||
PermissionRepo
|
||||
type AuthorityUsecase struct{ AuthorityAccessRepo }
|
||||
|
||||
func NewAuthorityUsecase(repo AuthorityAccessRepo) *AuthorityUsecase {
|
||||
return &AuthorityUsecase{AuthorityAccessRepo: repo}
|
||||
}
|
||||
|
||||
type AccessUsecase struct{ AccessRepo }
|
||||
type APIUsecase struct{ APIRepo }
|
||||
|
||||
func NewAccessUsecase(repo AccessRepo) *AccessUsecase { return &AccessUsecase{AccessRepo: repo} }
|
||||
func NewAPIUsecase(repo APIRepo) *APIUsecase { return &APIUsecase{APIRepo: repo} }
|
||||
|
||||
func (uc *AccessUsecase) Authorize(ctx context.Context, authorityID uint, path, method string) (bool, error) {
|
||||
type PermissionUsecase struct{ PermissionRepo }
|
||||
|
||||
func NewPermissionUsecase(repo PermissionRepo) *PermissionUsecase {
|
||||
return &PermissionUsecase{PermissionRepo: repo}
|
||||
}
|
||||
|
||||
type AccessControlUsecase struct {
|
||||
authorities AuthorityAccessRepo
|
||||
apis APIRepo
|
||||
}
|
||||
|
||||
func NewAccessControlUsecase(authorities AuthorityAccessRepo, apis APIRepo) *AccessControlUsecase {
|
||||
return &AccessControlUsecase{authorities: authorities, apis: apis}
|
||||
}
|
||||
|
||||
func (uc *AccessControlUsecase) Authorize(ctx context.Context, authorityID uint, path, method string) (bool, error) {
|
||||
if authorityID == 888 {
|
||||
return true, nil
|
||||
}
|
||||
return uc.AccessRepo.Authorize(ctx, authorityID, path, method)
|
||||
return uc.apis.Authorize(ctx, authorityID, path, method)
|
||||
}
|
||||
|
||||
func (uc *AccessControlUsecase) ResolveDataScope(ctx context.Context, authorityID, userID uint) (DataScope, error) {
|
||||
return uc.authorities.ResolveDataScope(ctx, authorityID, userID)
|
||||
}
|
||||
|
||||
type APISyncDiff struct {
|
||||
@@ -80,7 +99,7 @@ type APISyncDiff struct {
|
||||
Ignored []*API
|
||||
}
|
||||
|
||||
func (uc *AccessUsecase) SyncAPIs(ctx context.Context, routes []*API) (*APISyncDiff, error) {
|
||||
func (uc *APIUsecase) SyncAPIs(ctx context.Context, routes []*API) (*APISyncDiff, error) {
|
||||
stored, _, err := uc.ListAPIs(ctx, 0, 0, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -118,7 +137,7 @@ func (uc *AccessUsecase) SyncAPIs(ctx context.Context, routes []*API) (*APISyncD
|
||||
return diff, nil
|
||||
}
|
||||
|
||||
func (uc *AccessUsecase) AuthorityTree(ctx context.Context) ([]*Authority, error) {
|
||||
func (uc *AuthorityUsecase) AuthorityTree(ctx context.Context) ([]*Authority, error) {
|
||||
items, err := uc.ListAuthorities(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+36
-8
@@ -91,6 +91,12 @@ type LogFileRepo interface {
|
||||
LogContent(context.Context, string, string, *int64) (*LogContent, error)
|
||||
}
|
||||
|
||||
type LogViewerUsecase struct{ LogFileRepo }
|
||||
|
||||
func NewLogViewerUsecase(repo LogFileRepo) *LogViewerUsecase {
|
||||
return &LogViewerUsecase{LogFileRepo: repo}
|
||||
}
|
||||
|
||||
type ErrorRecord struct {
|
||||
ID uint
|
||||
CreatedAt time.Time
|
||||
@@ -106,14 +112,36 @@ type ErrorRecordRepo interface {
|
||||
ListErrors(context.Context, int, int, *ErrorRecord) ([]*ErrorRecord, int64, error)
|
||||
}
|
||||
|
||||
type AuditRepo interface {
|
||||
OperationLogRepo
|
||||
LoginLogRepo
|
||||
DataAccessLogRepo
|
||||
LogFileRepo
|
||||
ErrorRecordRepo
|
||||
type AuditRecordRepo interface {
|
||||
RecordOperation(context.Context, *OperationRecord) error
|
||||
RecordLogin(context.Context, *LoginLog) error
|
||||
RecordDataAccess(context.Context, *DataAccessLog) error
|
||||
CreateError(context.Context, *ErrorRecord) error
|
||||
}
|
||||
|
||||
type AuditUsecase struct{ AuditRepo }
|
||||
type AuditQueryRepo interface {
|
||||
ListOperations(context.Context, int, int, *OperationRecord) ([]*OperationRecord, int64, error)
|
||||
FindOperation(context.Context, uint) (*OperationRecord, error)
|
||||
DeleteOperations(context.Context, []uint) error
|
||||
ListLogins(context.Context, int, int, *LoginLog) ([]*LoginLog, int64, error)
|
||||
FindLogin(context.Context, uint) (*LoginLog, error)
|
||||
DeleteLogins(context.Context, []uint) error
|
||||
ListDataAccess(context.Context, int, int, *DataAccessLog) ([]*DataAccessLog, int64, error)
|
||||
DeleteDataAccess(context.Context, []uint) error
|
||||
UpdateError(context.Context, *ErrorRecord) error
|
||||
DeleteErrors(context.Context, []uint) error
|
||||
FindError(context.Context, uint) (*ErrorRecord, error)
|
||||
ListErrors(context.Context, int, int, *ErrorRecord) ([]*ErrorRecord, int64, error)
|
||||
}
|
||||
|
||||
func NewAuditUsecase(repo AuditRepo) *AuditUsecase { return &AuditUsecase{AuditRepo: repo} }
|
||||
type AuditUsecase struct{ AuditQueryRepo }
|
||||
|
||||
func NewAuditUsecase(repo AuditQueryRepo) *AuditUsecase {
|
||||
return &AuditUsecase{AuditQueryRepo: repo}
|
||||
}
|
||||
|
||||
type AuditRecorderUsecase struct{ AuditRecordRepo }
|
||||
|
||||
func NewAuditRecorderUsecase(repo AuditRecordRepo) *AuditRecorderUsecase {
|
||||
return &AuditRecorderUsecase{AuditRecordRepo: repo}
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,4 +3,4 @@ package biz
|
||||
import "github.com/google/wire"
|
||||
|
||||
// ProviderSet is biz providers.
|
||||
var ProviderSet = wire.NewSet(NewUserUsecase, NewSystemConfigUsecase, NewAccessUsecase, NewMenuUsecase, NewDepartmentUsecase, NewPositionUsecase, NewDictionaryUsecase, NewParameterUsecase, NewTokenUsecase, NewSecurityUsecase, NewVersionUsecase, NewExportUsecase, NewAuditUsecase, NewTaskUsecase, NewMediaUsecase, NewAnnouncementUsecase, NewEmailUsecase)
|
||||
var ProviderSet = wire.NewSet(NewUserUsecase, NewSystemConfigUsecase, NewAuthorityUsecase, NewAPIUsecase, NewPermissionUsecase, NewAccessControlUsecase, NewMenuUsecase, NewDepartmentUsecase, NewPositionUsecase, NewDictionaryUsecase, NewParameterUsecase, NewTokenUsecase, NewSecurityUsecase, NewVersionUsecase, NewExportUsecase, NewAuditUsecase, NewAuditRecorderUsecase, NewLogViewerUsecase, NewTaskUsecase, NewMediaUsecase, NewAnnouncementUsecase, NewEmailUsecase)
|
||||
|
||||
Reference in New Issue
Block a user