优化
This commit is contained in:
@@ -5,9 +5,19 @@ import (
|
||||
"time"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/conf"
|
||||
"kra/pkg/adminauth"
|
||||
)
|
||||
|
||||
type TokenService struct {
|
||||
uc *biz.TokenUsecase
|
||||
runtime *conf.Runtime
|
||||
}
|
||||
|
||||
func NewTokenService(uc *biz.TokenUsecase, runtime *conf.Runtime) *TokenService {
|
||||
return &TokenService{uc: uc, runtime: runtime}
|
||||
}
|
||||
|
||||
func tokenDTO(v *biz.APIToken) map[string]any {
|
||||
var user any = nil
|
||||
if v.User != nil {
|
||||
@@ -16,7 +26,7 @@ func tokenDTO(v *biz.APIToken) map[string]any {
|
||||
return map[string]any{"ID": v.ID, "CreatedAt": v.CreatedAt, "UpdatedAt": v.UpdatedAt, "DeletedAt": nil, "userId": v.UserID, "authorityId": v.AuthorityID, "token": v.Token, "status": v.Status, "expiresAt": v.ExpiresAt, "remark": v.Remark, "user": user}
|
||||
}
|
||||
|
||||
func (s *SettingsService) CreateAPIToken(ctx context.Context, userID, authorityID uint, days int, remark string) (string, error) {
|
||||
func (s *TokenService) CreateAPIToken(ctx context.Context, userID, authorityID uint, days int, remark string) (string, error) {
|
||||
user, duration, err := s.uc.PrepareAPIToken(ctx, userID, authorityID, days)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -43,7 +53,7 @@ func (s *SettingsService) CreateAPIToken(ctx context.Context, userID, authorityI
|
||||
}
|
||||
return token, nil
|
||||
}
|
||||
func (s *SettingsService) APITokens(ctx context.Context, page, size int, userID uint, status *bool) ([]map[string]any, int64, error) {
|
||||
func (s *TokenService) APITokens(ctx context.Context, page, size int, userID uint, status *bool) ([]map[string]any, int64, error) {
|
||||
items, total, err := s.uc.ListAPITokens(ctx, page, size, userID, status)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
@@ -54,12 +64,12 @@ func (s *SettingsService) APITokens(ctx context.Context, page, size int, userID
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
func (s *SettingsService) DisableAPIToken(ctx context.Context, id uint) error {
|
||||
func (s *TokenService) DisableAPIToken(ctx context.Context, id uint) error {
|
||||
return s.uc.DisableToken(ctx, id)
|
||||
}
|
||||
func (s *SettingsService) BlacklistToken(ctx context.Context, token string) error {
|
||||
func (s *TokenService) BlacklistToken(ctx context.Context, token string) error {
|
||||
return s.uc.BlacklistToken(ctx, token)
|
||||
}
|
||||
func (s *SettingsService) IsTokenDisabled(ctx context.Context, token string) (bool, error) {
|
||||
func (s *TokenService) IsTokenDisabled(ctx context.Context, token string) (bool, error) {
|
||||
return s.uc.IsTokenDisabled(ctx, token)
|
||||
}
|
||||
|
||||
@@ -24,10 +24,10 @@ type LoginResult struct {
|
||||
type AuthService struct {
|
||||
uc *biz.UserUsecase
|
||||
runtime *conf.Runtime
|
||||
settings *SettingsService
|
||||
settings *SecurityService
|
||||
}
|
||||
|
||||
func NewAuthService(uc *biz.UserUsecase, runtime *conf.Runtime, settings *SettingsService) *AuthService {
|
||||
func NewAuthService(uc *biz.UserUsecase, runtime *conf.Runtime, settings *SecurityService) *AuthService {
|
||||
return &AuthService{uc: uc, runtime: runtime, settings: settings}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@ import (
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type DictionaryService struct{ uc *biz.DictionaryUsecase }
|
||||
|
||||
func NewDictionaryService(uc *biz.DictionaryUsecase) *DictionaryService {
|
||||
return &DictionaryService{uc: uc}
|
||||
}
|
||||
|
||||
func dictionaryDomain(value *dto.DictionaryRequest) *biz.Dictionary {
|
||||
status := true
|
||||
if value.Status != nil {
|
||||
@@ -14,14 +20,14 @@ func dictionaryDomain(value *dto.DictionaryRequest) *biz.Dictionary {
|
||||
}
|
||||
return &biz.Dictionary{ID: value.ID, Name: value.Name, Type: value.Type, Status: status, Desc: value.Description, ParentID: value.ParentID}
|
||||
}
|
||||
func (s *SettingsService) CreateDictionaryRequest(ctx context.Context, req *dto.DictionaryRequest) (map[string]any, error) {
|
||||
func (s *DictionaryService) CreateDictionaryRequest(ctx context.Context, req *dto.DictionaryRequest) (map[string]any, error) {
|
||||
value := dictionaryDomain(req)
|
||||
if err := s.CreateDictionary(ctx, value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dictionaryDTO(value), nil
|
||||
}
|
||||
func (s *SettingsService) UpdateDictionaryRequest(ctx context.Context, req *dto.DictionaryRequest) error {
|
||||
func (s *DictionaryService) UpdateDictionaryRequest(ctx context.Context, req *dto.DictionaryRequest) error {
|
||||
return s.UpdateDictionary(ctx, dictionaryDomain(req))
|
||||
}
|
||||
func dictionaryDTO(v *biz.Dictionary) map[string]any {
|
||||
@@ -35,7 +41,7 @@ func dictionaryDTO(v *biz.Dictionary) map[string]any {
|
||||
}
|
||||
return map[string]any{"ID": v.ID, "CreatedAt": v.CreatedAt, "UpdatedAt": v.UpdatedAt, "DeletedAt": nil, "name": v.Name, "type": v.Type, "status": v.Status, "desc": v.Desc, "parentID": v.ParentID, "children": children, "sysDictionaryDetails": details}
|
||||
}
|
||||
func (s *SettingsService) Dictionaries(ctx context.Context, page, size int, name, typ string, details bool) ([]map[string]any, int64, error) {
|
||||
func (s *DictionaryService) Dictionaries(ctx context.Context, page, size int, name, typ string, details bool) ([]map[string]any, int64, error) {
|
||||
items, total, err := s.uc.ListDictionaries(ctx, page, size, name, typ, details)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
@@ -46,27 +52,27 @@ func (s *SettingsService) Dictionaries(ctx context.Context, page, size int, name
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
func (s *SettingsService) Dictionary(ctx context.Context, id uint, typ string, status *bool, details bool) (map[string]any, error) {
|
||||
func (s *DictionaryService) Dictionary(ctx context.Context, id uint, typ string, status *bool, details bool) (map[string]any, error) {
|
||||
v, err := s.uc.FindDictionary(ctx, id, typ, status, details)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dictionaryDTO(v), nil
|
||||
}
|
||||
func (s *SettingsService) ExportDictionary(ctx context.Context, id uint) (map[string]any, error) {
|
||||
func (s *DictionaryService) ExportDictionary(ctx context.Context, id uint) (map[string]any, error) {
|
||||
v, err := s.uc.ExportDictionary(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dictionaryDTO(v), nil
|
||||
}
|
||||
func (s *SettingsService) CreateDictionary(ctx context.Context, v *biz.Dictionary) error {
|
||||
func (s *DictionaryService) CreateDictionary(ctx context.Context, v *biz.Dictionary) error {
|
||||
return s.uc.CreateDictionary(ctx, v)
|
||||
}
|
||||
func (s *SettingsService) UpdateDictionary(ctx context.Context, v *biz.Dictionary) error {
|
||||
func (s *DictionaryService) UpdateDictionary(ctx context.Context, v *biz.Dictionary) error {
|
||||
return s.uc.UpdateDictionary(ctx, v)
|
||||
}
|
||||
func (s *SettingsService) DeleteDictionary(ctx context.Context, id uint) error {
|
||||
func (s *DictionaryService) DeleteDictionary(ctx context.Context, id uint) error {
|
||||
return s.uc.DeleteDictionary(ctx, id)
|
||||
}
|
||||
|
||||
@@ -77,10 +83,10 @@ func detailDomain(value *dto.DictionaryDetailRequest) *biz.DictionaryDetail {
|
||||
}
|
||||
return &biz.DictionaryDetail{ID: value.ID, Label: value.Label, Value: value.Value, Extend: value.Extend, Status: status, Sort: value.Sort, DictionaryID: value.DictionaryID, ParentID: value.ParentID, Level: value.Level, Path: value.Path}
|
||||
}
|
||||
func (s *SettingsService) CreateDictionaryDetailRequest(ctx context.Context, req *dto.DictionaryDetailRequest) error {
|
||||
func (s *DictionaryService) CreateDictionaryDetailRequest(ctx context.Context, req *dto.DictionaryDetailRequest) error {
|
||||
return s.CreateDictionaryDetail(ctx, detailDomain(req))
|
||||
}
|
||||
func (s *SettingsService) UpdateDictionaryDetailRequest(ctx context.Context, req *dto.DictionaryDetailRequest) error {
|
||||
func (s *DictionaryService) UpdateDictionaryDetailRequest(ctx context.Context, req *dto.DictionaryDetailRequest) error {
|
||||
return s.UpdateDictionaryDetail(ctx, detailDomain(req))
|
||||
}
|
||||
func detailDTO(v *biz.DictionaryDetail) map[string]any {
|
||||
@@ -90,7 +96,7 @@ func detailDTO(v *biz.DictionaryDetail) map[string]any {
|
||||
}
|
||||
return map[string]any{"ID": v.ID, "CreatedAt": v.CreatedAt, "UpdatedAt": v.UpdatedAt, "DeletedAt": nil, "label": v.Label, "value": v.Value, "extend": v.Extend, "status": v.Status, "sort": v.Sort, "sysDictionaryID": v.DictionaryID, "parentID": v.ParentID, "level": v.Level, "path": v.Path, "disabled": !v.Status, "children": children}
|
||||
}
|
||||
func (s *SettingsService) DictionaryDetails(ctx context.Context, page, size int, filter biz.DictionaryDetailFilter) ([]map[string]any, int64, error) {
|
||||
func (s *DictionaryService) DictionaryDetails(ctx context.Context, page, size int, filter biz.DictionaryDetailFilter) ([]map[string]any, int64, error) {
|
||||
items, total, err := s.uc.ListDictionaryDetails(ctx, page, size, filter)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
@@ -101,14 +107,14 @@ func (s *SettingsService) DictionaryDetails(ctx context.Context, page, size int,
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
func (s *SettingsService) DictionaryDetail(ctx context.Context, id uint) (map[string]any, error) {
|
||||
func (s *DictionaryService) DictionaryDetail(ctx context.Context, id uint) (map[string]any, error) {
|
||||
v, err := s.uc.FindDictionaryDetail(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return detailDTO(v), nil
|
||||
}
|
||||
func (s *SettingsService) DictionaryTree(ctx context.Context, id uint, typ string) ([]map[string]any, error) {
|
||||
func (s *DictionaryService) DictionaryTree(ctx context.Context, id uint, typ string) ([]map[string]any, error) {
|
||||
items, err := s.uc.DictionaryDetailTree(ctx, id, typ)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -119,12 +125,12 @@ func (s *SettingsService) DictionaryTree(ctx context.Context, id uint, typ strin
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (s *SettingsService) CreateDictionaryDetail(ctx context.Context, v *biz.DictionaryDetail) error {
|
||||
func (s *DictionaryService) CreateDictionaryDetail(ctx context.Context, v *biz.DictionaryDetail) error {
|
||||
return s.uc.CreateDictionaryDetail(ctx, v)
|
||||
}
|
||||
func (s *SettingsService) UpdateDictionaryDetail(ctx context.Context, v *biz.DictionaryDetail) error {
|
||||
func (s *DictionaryService) UpdateDictionaryDetail(ctx context.Context, v *biz.DictionaryDetail) error {
|
||||
return s.uc.UpdateDictionaryDetail(ctx, v)
|
||||
}
|
||||
func (s *SettingsService) DeleteDictionaryDetail(ctx context.Context, id uint) error {
|
||||
func (s *DictionaryService) DeleteDictionaryDetail(ctx context.Context, id uint) error {
|
||||
return s.uc.DeleteDictionaryDetail(ctx, id)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
func (s *SettingsService) ImportDictionaryJSON(ctx context.Context, raw string) error {
|
||||
func (s *DictionaryService) ImportDictionaryJSON(ctx context.Context, raw string) error {
|
||||
var payload struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
@@ -27,7 +27,7 @@ func (s *SettingsService) ImportDictionaryJSON(ctx context.Context, raw string)
|
||||
}
|
||||
return s.uc.ImportDictionary(ctx, dictionary, details)
|
||||
}
|
||||
func (s *SettingsService) DictionaryDetailsByParent(ctx context.Context, dictionaryID uint, parentID *uint, includeChildren bool) ([]map[string]any, error) {
|
||||
func (s *DictionaryService) DictionaryDetailsByParent(ctx context.Context, dictionaryID uint, parentID *uint, includeChildren bool) ([]map[string]any, error) {
|
||||
items, err := s.uc.DictionaryDetailsByParent(ctx, dictionaryID, parentID, includeChildren)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -8,22 +8,28 @@ import (
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type ParameterService struct{ uc *biz.ParameterUsecase }
|
||||
|
||||
func NewParameterService(uc *biz.ParameterUsecase) *ParameterService {
|
||||
return &ParameterService{uc: uc}
|
||||
}
|
||||
|
||||
func parameterDomain(value *dto.SystemParameterRequest) *biz.SystemParameter {
|
||||
return &biz.SystemParameter{ID: value.ID, Name: value.Name, Key: value.Key, Value: value.Value, Desc: value.Description}
|
||||
}
|
||||
func (s *SettingsService) CreateParameterRequest(ctx context.Context, req *dto.SystemParameterRequest) error {
|
||||
func (s *ParameterService) CreateParameterRequest(ctx context.Context, req *dto.SystemParameterRequest) error {
|
||||
return s.CreateParameter(ctx, parameterDomain(req))
|
||||
}
|
||||
func (s *SettingsService) UpdateParameterRequest(ctx context.Context, req *dto.SystemParameterRequest) error {
|
||||
func (s *ParameterService) UpdateParameterRequest(ctx context.Context, req *dto.SystemParameterRequest) error {
|
||||
return s.UpdateParameter(ctx, parameterDomain(req))
|
||||
}
|
||||
func (s *SettingsService) ParametersFilter(ctx context.Context, page, size int, name, key string, start, end *time.Time) ([]map[string]any, int64, error) {
|
||||
func (s *ParameterService) ParametersFilter(ctx context.Context, page, size int, name, key string, start, end *time.Time) ([]map[string]any, int64, error) {
|
||||
return s.Parameters(ctx, page, size, &biz.SystemParameter{Name: name, Key: key, StartCreatedAt: start, EndCreatedAt: end})
|
||||
}
|
||||
func parameterDTO(v *biz.SystemParameter) map[string]any {
|
||||
return map[string]any{"ID": v.ID, "CreatedAt": v.CreatedAt, "UpdatedAt": v.UpdatedAt, "DeletedAt": nil, "name": v.Name, "key": v.Key, "value": v.Value, "desc": v.Desc}
|
||||
}
|
||||
func (s *SettingsService) Parameters(ctx context.Context, page, size int, q *biz.SystemParameter) ([]map[string]any, int64, error) {
|
||||
func (s *ParameterService) Parameters(ctx context.Context, page, size int, q *biz.SystemParameter) ([]map[string]any, int64, error) {
|
||||
items, total, err := s.uc.ListParameters(ctx, page, size, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
@@ -34,19 +40,19 @@ func (s *SettingsService) Parameters(ctx context.Context, page, size int, q *biz
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
func (s *SettingsService) Parameter(ctx context.Context, id uint, key string) (map[string]any, error) {
|
||||
func (s *ParameterService) Parameter(ctx context.Context, id uint, key string) (map[string]any, error) {
|
||||
v, err := s.uc.FindParameter(ctx, id, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return parameterDTO(v), nil
|
||||
}
|
||||
func (s *SettingsService) CreateParameter(ctx context.Context, v *biz.SystemParameter) error {
|
||||
func (s *ParameterService) CreateParameter(ctx context.Context, v *biz.SystemParameter) error {
|
||||
return s.uc.CreateParameter(ctx, v)
|
||||
}
|
||||
func (s *SettingsService) UpdateParameter(ctx context.Context, v *biz.SystemParameter) error {
|
||||
func (s *ParameterService) UpdateParameter(ctx context.Context, v *biz.SystemParameter) error {
|
||||
return s.uc.UpdateParameter(ctx, v)
|
||||
}
|
||||
func (s *SettingsService) DeleteParameters(ctx context.Context, ids []uint) error {
|
||||
func (s *ParameterService) DeleteParameters(ctx context.Context, ids []uint) error {
|
||||
return s.uc.DeleteParameters(ctx, ids)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
func securityDTO(v *biz.SecurityConfig) map[string]any {
|
||||
return map[string]any{"ID": v.ID, "captchaOpen": v.CaptchaOpen, "captchaTimeout": v.CaptchaTimeout, "keyLong": v.KeyLong, "imgWidth": v.ImgWidth, "imgHeight": v.ImgHeight, "pwdMinLength": v.PwdMinLength, "pwdRequireUpper": v.PwdRequireUpper, "pwdRequireLower": v.PwdRequireLower, "pwdRequireDigit": v.PwdRequireDigit, "pwdRequireSpecial": v.PwdRequireSpecial, "limitEnable": v.LimitEnable, "limitWindow": v.LimitWindow, "limitCount": v.LimitCount, "lockEnable": v.LockEnable, "lockThreshold": v.LockThreshold, "lockDuration": v.LockDuration, "pwdExpireEnable": v.PwdExpireEnable, "pwdExpireDays": v.PwdExpireDays, "forceNewUserChangePassword": v.ForceNewUserChangePassword}
|
||||
}
|
||||
func (s *SettingsService) CurrentSecurity(ctx context.Context) (*biz.SecurityConfig, error) {
|
||||
func (s *SecurityService) CurrentSecurity(ctx context.Context) (*biz.SecurityConfig, error) {
|
||||
s.securityMu.RLock()
|
||||
if s.securityCache != nil {
|
||||
copy := *s.securityCache
|
||||
@@ -28,14 +28,14 @@ func (s *SettingsService) CurrentSecurity(ctx context.Context) (*biz.SecurityCon
|
||||
s.securityMu.Unlock()
|
||||
return ©, nil
|
||||
}
|
||||
func (s *SettingsService) Security(ctx context.Context) (map[string]any, error) {
|
||||
func (s *SecurityService) Security(ctx context.Context) (map[string]any, error) {
|
||||
value, err := s.CurrentSecurity(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return securityDTO(value), nil
|
||||
}
|
||||
func (s *SettingsService) SaveSecurity(ctx context.Context, value *biz.SecurityConfig) (map[string]any, error) {
|
||||
func (s *SecurityService) SaveSecurity(ctx context.Context, value *biz.SecurityConfig) (map[string]any, error) {
|
||||
if err := s.uc.UpdateSecurity(ctx, value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -44,7 +44,7 @@ func (s *SettingsService) SaveSecurity(ctx context.Context, value *biz.SecurityC
|
||||
s.securityMu.Unlock()
|
||||
return securityDTO(value), nil
|
||||
}
|
||||
func (s *SettingsService) SaveSecurityRequest(ctx context.Context, value *dto.SecurityConfigRequest) (map[string]any, error) {
|
||||
func (s *SecurityService) SaveSecurityRequest(ctx context.Context, value *dto.SecurityConfigRequest) (map[string]any, error) {
|
||||
return s.SaveSecurity(ctx, &biz.SecurityConfig{
|
||||
ID: value.ID, CaptchaOpen: value.CaptchaOpen, CaptchaTimeout: value.CaptchaTimeout,
|
||||
KeyLong: value.KeyLong, ImgWidth: value.ImgWidth, ImgHeight: value.ImgHeight,
|
||||
@@ -57,7 +57,7 @@ func (s *SettingsService) SaveSecurityRequest(ctx context.Context, value *dto.Se
|
||||
ForceNewUserChangePassword: value.ForceNewUserChangePassword,
|
||||
})
|
||||
}
|
||||
func (s *SettingsService) ValidatePassword(ctx context.Context, password string) error {
|
||||
func (s *SecurityService) ValidatePassword(ctx context.Context, password string) error {
|
||||
cfg, err := s.CurrentSecurity(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -9,42 +9,43 @@ import (
|
||||
"kra/internal/conf"
|
||||
)
|
||||
|
||||
type SettingsService struct {
|
||||
uc *biz.SettingsUsecase
|
||||
type SecurityService struct {
|
||||
uc *biz.SecurityUsecase
|
||||
runtime *conf.Runtime
|
||||
securityMu sync.RWMutex
|
||||
securityCache *biz.SecurityConfig
|
||||
cache biz.Cache
|
||||
tokens *TokenService
|
||||
}
|
||||
|
||||
func NewSettingsService(uc *biz.SettingsUsecase, runtime *conf.Runtime, cache biz.Cache) *SettingsService {
|
||||
return &SettingsService{uc: uc, runtime: runtime, cache: cache}
|
||||
func NewSecurityService(uc *biz.SecurityUsecase, runtime *conf.Runtime, cache biz.Cache, tokens *TokenService) *SecurityService {
|
||||
return &SecurityService{uc: uc, runtime: runtime, cache: cache, tokens: tokens}
|
||||
}
|
||||
|
||||
func (s *SettingsService) CacheGet(ctx context.Context, key string) (string, bool, error) {
|
||||
func (s *SecurityService) CacheGet(ctx context.Context, key string) (string, bool, error) {
|
||||
return s.cache.Get(ctx, key)
|
||||
}
|
||||
|
||||
func (s *SettingsService) CacheSet(ctx context.Context, key, value string, expiration time.Duration) error {
|
||||
func (s *SecurityService) CacheSet(ctx context.Context, key, value string, expiration time.Duration) error {
|
||||
return s.cache.Set(ctx, key, value, expiration)
|
||||
}
|
||||
|
||||
func (s *SettingsService) CacheDelete(ctx context.Context, key string) error {
|
||||
func (s *SecurityService) CacheDelete(ctx context.Context, key string) error {
|
||||
return s.cache.Delete(ctx, key)
|
||||
}
|
||||
|
||||
func (s *SettingsService) CacheIncrement(ctx context.Context, key string, expiration time.Duration) (int64, error) {
|
||||
func (s *SecurityService) CacheIncrement(ctx context.Context, key string, expiration time.Duration) (int64, error) {
|
||||
return s.cache.Increment(ctx, key, expiration)
|
||||
}
|
||||
|
||||
func (s *SettingsService) UseMultipoint() bool {
|
||||
func (s *SecurityService) UseMultipoint() bool {
|
||||
config := s.runtime.Admin()
|
||||
return config != nil && config.System != nil && config.System.UseMultipoint
|
||||
}
|
||||
|
||||
func activeTokenKey(username string) string { return "jwt:active:" + username }
|
||||
|
||||
func (s *SettingsService) ActiveTokenMatches(ctx context.Context, username, token string) (bool, error) {
|
||||
func (s *SecurityService) ActiveTokenMatches(ctx context.Context, username, token string) (bool, error) {
|
||||
if !s.UseMultipoint() {
|
||||
return true, nil
|
||||
}
|
||||
@@ -52,12 +53,12 @@ func (s *SettingsService) ActiveTokenMatches(ctx context.Context, username, toke
|
||||
return ok && active == token, err
|
||||
}
|
||||
|
||||
func (s *SettingsService) RotateActiveToken(ctx context.Context, username, oldToken, newToken string, expiration time.Duration) error {
|
||||
func (s *SecurityService) RotateActiveToken(ctx context.Context, username, oldToken, newToken string, expiration time.Duration) error {
|
||||
if !s.UseMultipoint() {
|
||||
return nil
|
||||
}
|
||||
if oldToken != "" && oldToken != newToken {
|
||||
if err := s.BlacklistToken(ctx, oldToken); err != nil {
|
||||
if err := s.tokens.BlacklistToken(ctx, oldToken); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -3,4 +3,4 @@ package service
|
||||
import "github.com/google/wire"
|
||||
|
||||
// ProviderSet is service providers.
|
||||
var ProviderSet = wire.NewSet(NewAuthService, NewUserService, NewSystemConfigService, NewAccessService, NewMenuService, NewOrganizationService, NewSettingsService, NewVersionService, NewExportService, NewAuditService, NewTaskService, NewMediaService, NewAnnouncementService, NewEmailService)
|
||||
var ProviderSet = wire.NewSet(NewAuthService, NewUserService, NewSystemConfigService, NewAccessService, NewMenuService, NewOrganizationService, NewDictionaryService, NewParameterService, NewTokenService, NewSecurityService, NewVersionService, NewExportService, NewAuditService, NewTaskService, NewMediaService, NewAnnouncementService, NewEmailService)
|
||||
|
||||
@@ -44,9 +44,6 @@ func (s *TaskService) Delete(ctx context.Context, id uint) error {
|
||||
func (s *TaskService) Toggle(ctx context.Context, id uint, enabled bool) error {
|
||||
return s.uc.ToggleTask(ctx, id, enabled)
|
||||
}
|
||||
func (s *TaskService) Task(ctx context.Context, id uint) (*biz.TimedTask, error) {
|
||||
return s.uc.FindTask(ctx, id)
|
||||
}
|
||||
func taskDTO(v *biz.TimedTask, next *time.Time) map[string]any {
|
||||
return map[string]any{"ID": v.ID, "CreatedAt": v.CreatedAt, "UpdatedAt": v.UpdatedAt, "DeletedAt": nil, "name": v.Name, "description": v.Description, "spec": v.Spec, "withSeconds": v.WithSeconds, "executorType": v.ExecutorType, "methodName": v.MethodName, "params": json.RawMessage(v.Params), "httpUrl": v.HTTPURL, "httpMethod": v.HTTPMethod, "httpHeader": json.RawMessage(v.HTTPHeader), "httpBody": v.HTTPBody, "httpAllowPrivate": v.HTTPAllowPrivate, "enabled": v.Enabled, "nextRunAt": next}
|
||||
}
|
||||
@@ -67,12 +64,6 @@ func (s *TaskService) Tasks(ctx context.Context, page, size int, q *biz.TimedTas
|
||||
return out, total, nil
|
||||
}
|
||||
|
||||
// ScheduledTasks is the typed internal contract used by the scheduler and
|
||||
// deliberately bypasses transport response maps.
|
||||
func (s *TaskService) ScheduledTasks(ctx context.Context) ([]*biz.TimedTask, error) {
|
||||
items, _, err := s.uc.ListTasks(ctx, 0, 0, nil)
|
||||
return items, err
|
||||
}
|
||||
func (s *TaskService) Logs(ctx context.Context, page, size int, taskID uint, status string) ([]map[string]any, int64, error) {
|
||||
items, total, err := s.uc.ListTaskLogs(ctx, page, size, taskID, status)
|
||||
if err != nil {
|
||||
|
||||
@@ -17,10 +17,10 @@ type UserInput struct {
|
||||
|
||||
type UserService struct {
|
||||
uc *biz.UserUsecase
|
||||
settings *SettingsService
|
||||
settings *SecurityService
|
||||
}
|
||||
|
||||
func NewUserService(uc *biz.UserUsecase, settings *SettingsService) *UserService {
|
||||
func NewUserService(uc *biz.UserUsecase, settings *SecurityService) *UserService {
|
||||
return &UserService{uc: uc, settings: settings}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user