123 lines
4.0 KiB
Go
123 lines
4.0 KiB
Go
package biz
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
type API struct {
|
|
ID uint
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
Path string
|
|
Description string
|
|
APIGroup string
|
|
Method string
|
|
}
|
|
|
|
type MenuButton struct {
|
|
ID uint
|
|
Name string
|
|
Description string
|
|
MenuID uint
|
|
}
|
|
|
|
type Department struct {
|
|
ID uint
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
Name string
|
|
ParentID uint
|
|
Ancestors string
|
|
Sort int
|
|
LeaderID uint
|
|
Status bool
|
|
Children []*Department
|
|
}
|
|
|
|
type Position struct {
|
|
ID uint
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
Name string
|
|
Code string
|
|
Sort int
|
|
Status bool
|
|
Remark string
|
|
}
|
|
|
|
type AccessRepo interface {
|
|
CreateAuthority(context.Context, *Authority) error
|
|
CopyAuthority(context.Context, uint, *Authority) error
|
|
UpdateAuthority(context.Context, *Authority) error
|
|
DeleteAuthority(context.Context, uint) error
|
|
ListAuthorities(context.Context) ([]*Authority, error)
|
|
SetAuthorityMenus(context.Context, uint, []uint) error
|
|
AuthorityMenuIDs(context.Context, uint) ([]uint, error)
|
|
SetAuthorityUsers(context.Context, uint, []uint) error
|
|
AuthorityUserIDs(context.Context, uint) ([]uint, error)
|
|
SetDataScope(context.Context, uint, int, []uint) error
|
|
DataScopeDepartmentIDs(context.Context, uint) ([]uint, error)
|
|
ResolveDataScope(context.Context, uint, uint) (DataScope, error)
|
|
|
|
CreateMenu(context.Context, *Menu) error
|
|
UpdateMenu(context.Context, *Menu) error
|
|
DeleteMenu(context.Context, uint) error
|
|
FindMenu(context.Context, uint) (*Menu, error)
|
|
ListMenus(context.Context) ([]*Menu, error)
|
|
MenuRoleIDs(context.Context, uint) ([]uint, error)
|
|
SetMenuRoles(context.Context, uint, []uint) error
|
|
ReplaceMenuButtons(context.Context, uint, []*MenuButton) error
|
|
|
|
CreateAPI(context.Context, *API) error
|
|
UpdateAPI(context.Context, *API) error
|
|
DeleteAPIs(context.Context, []uint) error
|
|
FindAPI(context.Context, uint) (*API, error)
|
|
ListAPIs(context.Context, int, int, *API) ([]*API, int64, error)
|
|
APIRoleIDs(context.Context, uint) ([]uint, error)
|
|
SetAPIRoles(context.Context, uint, []uint) error
|
|
Authorize(context.Context, uint, string, string) (bool, error)
|
|
PolicyPaths(context.Context, uint) ([]*API, error)
|
|
SetPolicyPaths(context.Context, uint, []*API) error
|
|
IgnoredAPIs(context.Context) ([]*API, error)
|
|
SetAPIIgnored(context.Context, string, string, bool) error
|
|
ApplyAPISync(context.Context, []*API, []*API) error
|
|
|
|
Buttons(context.Context, uint) ([]*MenuButton, error)
|
|
SetAuthorityButtons(context.Context, uint, map[uint][]uint) error
|
|
AuthorityButtonIDs(context.Context, uint) ([]uint, error)
|
|
SelectedButtons(context.Context, uint, uint) ([]uint, error)
|
|
SetSelectedButtons(context.Context, uint, uint, []uint) error
|
|
CanRemoveButton(context.Context, uint) (bool, error)
|
|
|
|
CreateDepartment(context.Context, *Department) error
|
|
UpdateDepartment(context.Context, *Department) error
|
|
DeleteDepartment(context.Context, uint) error
|
|
FindDepartment(context.Context, uint) (*Department, error)
|
|
ListDepartments(context.Context, string) ([]*Department, error)
|
|
DepartmentUserIDs(context.Context, uint) ([]uint, error)
|
|
SetDepartmentUsers(context.Context, uint, []uint) error
|
|
SetUserDepartments(context.Context, uint, []uint, uint) error
|
|
|
|
CreatePosition(context.Context, *Position) error
|
|
UpdatePosition(context.Context, *Position) error
|
|
DeletePosition(context.Context, uint) error
|
|
FindPosition(context.Context, uint) (*Position, error)
|
|
ListPositions(context.Context, int, int, *Position) ([]*Position, int64, error)
|
|
PositionUserIDs(context.Context, uint) ([]uint, error)
|
|
SetPositionUsers(context.Context, uint, []uint) error
|
|
SetUserPositions(context.Context, uint, []uint) error
|
|
}
|
|
|
|
type AccessUsecase struct{ repo AccessRepo }
|
|
|
|
func NewAccessUsecase(repo AccessRepo) *AccessUsecase { return &AccessUsecase{repo: repo} }
|
|
|
|
func (uc *AccessUsecase) Repo() AccessRepo { return uc.repo }
|
|
func (uc *AccessUsecase) Authorize(ctx context.Context, authorityID uint, path, method string) (bool, error) {
|
|
if authorityID == 888 {
|
|
return true, nil
|
|
}
|
|
return uc.repo.Authorize(ctx, authorityID, path, method)
|
|
}
|