mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-04 10:13:53 +08:00
add strategy permit
This commit is contained in:
@@ -25,6 +25,14 @@ type imlStrategyController struct {
|
||||
serviceModule service.IServiceModule `autowired:""`
|
||||
}
|
||||
|
||||
func (i *imlStrategyController) Restore(ctx *gin.Context, id string) error {
|
||||
return i.strategyModule.Restore(ctx, id)
|
||||
}
|
||||
|
||||
func (i *imlStrategyController) DeleteServiceStrategy(ctx *gin.Context, serviceId string, id string) error {
|
||||
return i.strategyModule.DeleteServiceStrategy(ctx, serviceId, id)
|
||||
}
|
||||
|
||||
func (i *imlStrategyController) ToPublish(ctx *gin.Context, driver string) ([]*strategy_dto.ToPublishItem, string, string, bool, error) {
|
||||
list, err := i.strategyModule.ToPublish(ctx, driver)
|
||||
if err != nil {
|
||||
|
||||
@@ -22,6 +22,9 @@ type IStrategyController interface {
|
||||
DisableStrategy(ctx *gin.Context, id string) error
|
||||
|
||||
DeleteStrategy(ctx *gin.Context, id string) error
|
||||
DeleteServiceStrategy(ctx *gin.Context, serviceId string, id string) error
|
||||
|
||||
Restore(ctx *gin.Context, id string) error
|
||||
|
||||
FilterGlobalOptions(ctx *gin.Context) ([]*strategy_dto.FilterOption, error)
|
||||
FilterServiceOptions(ctx *gin.Context) ([]*strategy_dto.FilterOption, error)
|
||||
|
||||
+21
-2
@@ -35,6 +35,22 @@ type imlStrategyModule struct {
|
||||
transaction store.ITransaction `autowired:""`
|
||||
}
|
||||
|
||||
func (i *imlStrategyModule) Restore(ctx context.Context, id string) error {
|
||||
return i.strategyService.Restore(ctx, id)
|
||||
}
|
||||
|
||||
func (i *imlStrategyModule) DeleteServiceStrategy(ctx context.Context, serviceId string, id string) error {
|
||||
_, err := i.strategyService.LatestStrategyCommit(ctx, strategy_dto.ScopeService, serviceId, id)
|
||||
if err != nil {
|
||||
// 判断是否已经发布,如果未发布则直接删除
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return err
|
||||
}
|
||||
return i.strategyService.Delete(ctx, id)
|
||||
}
|
||||
return i.strategyService.SortDelete(ctx, id)
|
||||
}
|
||||
|
||||
func (i *imlStrategyModule) ToPublish(ctx context.Context, driver string) ([]*strategy_dto.ToPublishItem, error) {
|
||||
scope := strategy_dto.ToScope(strategy_dto.ScopeGlobal)
|
||||
list, err := i.strategyService.SearchAll(ctx, "", driver, scope.Int(), "")
|
||||
@@ -46,7 +62,7 @@ func (i *imlStrategyModule) ToPublish(ctx context.Context, driver string) ([]*st
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
commitMap := utils.SliceToMapO(commits, func(c *commit.Commit[strategy.StrategyCommit]) (string, string) { return c.Key, c.Data.Version })
|
||||
commitMap := utils.SliceToMapO(commits, func(c *commit.Commit[strategy.StrategyCommit]) (string, string) { return c.Data.Id, c.Data.Version })
|
||||
items := make([]*strategy_dto.ToPublishItem, 0, len(list))
|
||||
for _, l := range list {
|
||||
status := strategy_dto.StrategyStatus(l, commitMap[l.Id])
|
||||
@@ -73,7 +89,7 @@ func (i *imlStrategyModule) Search(ctx context.Context, keyword string, driver s
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
commitMap := utils.SliceToMapO(commits, func(c *commit.Commit[strategy.StrategyCommit]) (string, string) { return c.Key, c.Data.Version })
|
||||
commitMap := utils.SliceToMapO(commits, func(c *commit.Commit[strategy.StrategyCommit]) (string, string) { return c.Data.Id, c.Data.Version })
|
||||
items := make([]*strategy_dto.StrategyItem, 0, len(list))
|
||||
for _, l := range list {
|
||||
fs := make([]*strategy_dto.Filter, 0)
|
||||
@@ -210,6 +226,9 @@ func (i *imlStrategyModule) Publish(ctx context.Context, driver string, scope st
|
||||
}
|
||||
}
|
||||
|
||||
if l.IsStop {
|
||||
continue
|
||||
}
|
||||
// TODO:同步到网关
|
||||
err = i.strategyService.CommitStrategy(txCtx, scope, target, l.Id, l)
|
||||
if err != nil {
|
||||
|
||||
@@ -20,6 +20,9 @@ type IStrategyModule interface {
|
||||
Publish(ctx context.Context, driver string, scope string, target string) error
|
||||
Delete(ctx context.Context, id string) error
|
||||
ToPublish(ctx context.Context, driver string) ([]*strategy_dto.ToPublishItem, error)
|
||||
Restore(ctx context.Context, id string) error
|
||||
|
||||
DeleteServiceStrategy(ctx context.Context, serviceId string, id string) error
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -16,12 +16,15 @@ func (p *plugin) strategyApis() []pm3.Api {
|
||||
pm3.CreateApiWidthDoc(http.MethodPatch, "/api/v1/strategy/global/:driver/enable", []string{"context", "query:strategy"}, nil, p.strategyController.EnableStrategy),
|
||||
pm3.CreateApiWidthDoc(http.MethodPatch, "/api/v1/strategy/global/:driver/disable", []string{"context", "query:strategy"}, nil, p.strategyController.DisableStrategy),
|
||||
pm3.CreateApiWidthDoc(http.MethodPost, "/api/v1/strategy/global/:driver/publish", []string{"context", "rest:driver"}, nil, p.strategyController.PublishGlobalStrategy),
|
||||
pm3.CreateApiWidthDoc(http.MethodPatch, "/api/v1/strategy/global/:driver/restore", []string{"context", "query:strategy"}, nil, p.strategyController.Restore),
|
||||
|
||||
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/strategy/service/:driver/list", []string{"context", "query:keyword", "query:service", "rest:driver", "query:page", "query:page_size", "query:order", "query:sort", "query:filters"}, []string{"list", "total"}, p.strategyController.ServiceStrategyList),
|
||||
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/strategy/service/:driver", []string{"context", "query:strategy"}, []string{"strategy"}, p.strategyController.GetStrategy),
|
||||
pm3.CreateApiWidthDoc(http.MethodPost, "/api/v1/strategy/service/:driver", []string{"context", "query:service", "rest:driver", "body"}, nil, p.strategyController.CreateServiceStrategy),
|
||||
pm3.CreateApiWidthDoc(http.MethodPatch, "/api/v1/strategy/service/:driver/enable", []string{"context", "query:strategy"}, nil, p.strategyController.EnableStrategy),
|
||||
pm3.CreateApiWidthDoc(http.MethodPatch, "/api/v1/strategy/service/:driver/disable", []string{"context", "query:strategy"}, nil, p.strategyController.DisableStrategy),
|
||||
pm3.CreateApiWidthDoc(http.MethodDelete, "/api/v1/strategy/service/:driver", []string{"context", "query:service", "query:strategy"}, nil, p.strategyController.DeleteServiceStrategy),
|
||||
pm3.CreateApiWidthDoc(http.MethodPatch, "/api/v1/strategy/service/:driver/restore", []string{"context", "query:strategy"}, nil, p.strategyController.Restore),
|
||||
|
||||
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/strategy/global/filter-options", []string{"context"}, []string{"options"}, p.strategyController.FilterGlobalOptions),
|
||||
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/strategy/service/filter-options", []string{"context"}, []string{"options"}, p.strategyController.FilterServiceOptions),
|
||||
|
||||
@@ -131,6 +131,16 @@ system:
|
||||
value: 'manager'
|
||||
dependents:
|
||||
- system.settings.log_configuration.view
|
||||
- name: global strategy
|
||||
value: "strategy"
|
||||
children:
|
||||
- name: view
|
||||
value: 'view'
|
||||
guest_allow: true
|
||||
- name: manager
|
||||
value: 'manager'
|
||||
dependents:
|
||||
- system.settings.strategy.view
|
||||
team:
|
||||
- name: service
|
||||
value: 'service'
|
||||
@@ -197,6 +207,16 @@ team:
|
||||
value: 'manager'
|
||||
dependents:
|
||||
- team.service.subscription.view
|
||||
- name: service strategy
|
||||
value: 'strategy'
|
||||
children:
|
||||
- name: view
|
||||
value: 'view'
|
||||
guest_allow: true
|
||||
- name: manager
|
||||
value: 'manager'
|
||||
dependents:
|
||||
- team.service.strategy.view
|
||||
- name: consumer
|
||||
value: 'consumer'
|
||||
children:
|
||||
|
||||
@@ -19,6 +19,8 @@ system:
|
||||
- system.settings.role.view
|
||||
- system.settings.ssl_certificate.manager
|
||||
- system.settings.ssl_certificate.view
|
||||
- system.settings.strategy.view
|
||||
- system.settings.strategy.manager
|
||||
- system.workspace.application.manager_all
|
||||
- system.workspace.application.view_all
|
||||
- system.workspace.service.manager_all
|
||||
@@ -49,6 +51,8 @@ system:
|
||||
- system.settings.log_configuration.view
|
||||
- system.settings.ssl_certificate.manager
|
||||
- system.settings.ssl_certificate.view
|
||||
- system.settings.strategy.view
|
||||
- system.settings.strategy.manager
|
||||
- system.workspace.application.view_all
|
||||
- system.workspace.service.view_all
|
||||
- system.workspace.team.view_all
|
||||
@@ -75,6 +79,8 @@ team:
|
||||
- team.service.release.view
|
||||
- team.service.service_intro.manager
|
||||
- team.service.service_intro.view
|
||||
- team.service.strategy.view
|
||||
- team.service.strategy.manager
|
||||
- team.service.subscription.manager
|
||||
- team.service.subscription.view
|
||||
- team.service.upstream.manager
|
||||
@@ -99,6 +105,8 @@ team:
|
||||
- team.service.release.view
|
||||
- team.service.service_intro.manager
|
||||
- team.service.service_intro.view
|
||||
- team.service.strategy.view
|
||||
- team.service.strategy.manager
|
||||
- team.service.subscription.manager
|
||||
- team.service.subscription.view
|
||||
- team.service.upstream.manager
|
||||
@@ -120,7 +128,7 @@ team:
|
||||
- team.service.service.manager
|
||||
- team.service.service_intro.manager
|
||||
- team.service.service_intro.view
|
||||
- team.service.subscription.manager
|
||||
- team.service.strategy.view
|
||||
- team.service.subscription.view
|
||||
- team.service.upstream.manager
|
||||
- team.service.upstream.view
|
||||
|
||||
@@ -22,6 +22,11 @@ type imlStrategyService struct {
|
||||
universally.IServiceEdit[Edit]
|
||||
}
|
||||
|
||||
func (i *imlStrategyService) Restore(ctx context.Context, id string) error {
|
||||
_, err := i.store.UpdateWhere(ctx, map[string]interface{}{"uuid": id}, map[string]interface{}{"is_delete": false})
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *imlStrategyService) SearchAll(ctx context.Context, keyword string, driver string, scope int, target string) ([]*Strategy, error) {
|
||||
w := make(map[string]interface{})
|
||||
w["scope"] = scope
|
||||
|
||||
@@ -21,6 +21,8 @@ type IStrategyService interface {
|
||||
SortDelete(ctx context.Context, id string) error
|
||||
Delete(ctx context.Context, id ...string) error
|
||||
|
||||
Restore(ctx context.Context, id string) error
|
||||
|
||||
CommitStrategy(ctx context.Context, scope string, target string, strategyId string, data *Strategy) error
|
||||
GetStrategyCommit(ctx context.Context, commitId string) (*commit.Commit[StrategyCommit], error)
|
||||
LatestStrategyCommit(ctx context.Context, scope string, target string, strategyId string) (*commit.Commit[StrategyCommit], error)
|
||||
|
||||
Reference in New Issue
Block a user