mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-04 10:13:53 +08:00
update permit
This commit is contained in:
@@ -7,6 +7,10 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/APIParkLab/APIPark/resources/access"
|
||||
|
||||
"github.com/eolinker/ap-account/service/role"
|
||||
|
||||
application_authorization "github.com/APIParkLab/APIPark/service/application-authorization"
|
||||
|
||||
api_doc "github.com/APIParkLab/APIPark/service/api-doc"
|
||||
@@ -539,9 +543,72 @@ type imlAppModule struct {
|
||||
teamMemberService team_member.ITeamMemberService `autowired:""`
|
||||
subscribeService subscribe.ISubscribeService `autowired:""`
|
||||
authService application_authorization.IAuthorizationService `autowired:""`
|
||||
roleService role.IRoleService `autowired:""`
|
||||
roleMemberService role.IRoleMemberService `autowired:""`
|
||||
transaction store.ITransaction `autowired:""`
|
||||
}
|
||||
|
||||
func (i *imlAppModule) SearchCanSubscribe(ctx context.Context, serviceId string) ([]*service_dto.SimpleAppItem, error) {
|
||||
apps, err := i.searchMyApps(ctx, "", "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list, err := i.roleService.ListByPermit(ctx, access.SystemWorkspaceApplicationManagerAll)
|
||||
if err == nil && len(list) > 0 {
|
||||
return utils.SliceToSlice(apps, func(p *service.Service) *service_dto.SimpleAppItem {
|
||||
return &service_dto.SimpleAppItem{
|
||||
Id: p.Id,
|
||||
Name: p.Name,
|
||||
Description: p.Description,
|
||||
Team: auto.UUID(p.Team),
|
||||
}
|
||||
}), nil
|
||||
}
|
||||
list, err = i.roleService.ListByPermit(ctx, access.TeamConsumerSubscriptionSubscribe)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
roleIds := utils.SliceToSlice(list, func(p *role.RoleByPermit) string {
|
||||
return p.Id
|
||||
})
|
||||
members, err := i.roleMemberService.ListByRoleIds(ctx, utils.UserId(ctx), roleIds...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(members) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
subscribes, err := i.subscribeService.ListByServices(ctx, serviceId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
subscribeMap := utils.SliceToMapO(subscribes, func(p *subscribe.Subscribe) (string, struct{}) {
|
||||
return p.Application, struct{}{}
|
||||
}, func(s *subscribe.Subscribe) bool {
|
||||
return s.ApplyStatus == subscribe.ApplyStatusSubscribe
|
||||
})
|
||||
teamMap := utils.SliceToMapO(members, func(p *role.Member) (string, struct{}) {
|
||||
return role.TrimTeamTarget(p.Target), struct{}{}
|
||||
})
|
||||
result := make([]*service_dto.SimpleAppItem, 0, len(apps))
|
||||
for _, app := range apps {
|
||||
if _, ok := teamMap[app.Team]; !ok {
|
||||
continue
|
||||
}
|
||||
if _, ok := subscribeMap[app.Id]; ok {
|
||||
continue
|
||||
}
|
||||
result = append(result, &service_dto.SimpleAppItem{
|
||||
Id: app.Id,
|
||||
Name: app.Name,
|
||||
Description: app.Description,
|
||||
Team: auto.UUID(app.Team),
|
||||
})
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (i *imlAppModule) ExportAll(ctx context.Context) ([]*service_dto.ExportApp, error) {
|
||||
apps, err := i.serviceService.AppList(ctx)
|
||||
if err != nil {
|
||||
|
||||
@@ -47,6 +47,7 @@ type IAppModule interface {
|
||||
UpdateApp(ctx context.Context, appId string, input *service_dto.UpdateApp) (*service_dto.App, error)
|
||||
Search(ctx context.Context, teamId string, keyword string) ([]*service_dto.AppItem, error)
|
||||
SearchMyApps(ctx context.Context, teamId string, keyword string) ([]*service_dto.AppItem, error)
|
||||
SearchCanSubscribe(ctx context.Context, serviceId string) ([]*service_dto.SimpleAppItem, error)
|
||||
// SimpleApps 获取简易项目列表
|
||||
SimpleApps(ctx context.Context, keyword string) ([]*service_dto.SimpleAppItem, error)
|
||||
MySimpleApps(ctx context.Context, keyword string) ([]*service_dto.SimpleAppItem, error)
|
||||
|
||||
Reference in New Issue
Block a user