(ctx context.Context, serviceId string)
| 1056 | } |
| 1057 | |
| 1058 | func (i *imlAppModule) SearchCanSubscribe(ctx context.Context, serviceId string) ([]*service_dto.SubscribeAppItem, bool, error) { |
| 1059 | apps, err := i.searchMyApps(ctx, "", "") |
| 1060 | if err != nil { |
| 1061 | return nil, false, err |
| 1062 | } |
| 1063 | subscribes, err := i.subscribeService.ListByServices(ctx, serviceId) |
| 1064 | if err != nil { |
| 1065 | return nil, false, err |
| 1066 | } |
| 1067 | subscribeMap := utils.SliceToMapO(subscribes, func(p *subscribe.Subscribe) (string, struct{}) { |
| 1068 | return p.Application, struct{}{} |
| 1069 | }, func(s *subscribe.Subscribe) bool { |
| 1070 | return s.ApplyStatus == subscribe.ApplyStatusSubscribe |
| 1071 | }) |
| 1072 | canSubscribe := false |
| 1073 | list, err := i.roleService.ListByPermit(ctx, access.SystemWorkspaceApplicationManagerAll) |
| 1074 | if err == nil && len(list) > 0 { |
| 1075 | return utils.SliceToSlice(apps, func(p *service.Service) *service_dto.SubscribeAppItem { |
| 1076 | _, isSubscribed := subscribeMap[p.Id] |
| 1077 | if !isSubscribed { |
| 1078 | canSubscribe = true |
| 1079 | } |
| 1080 | return &service_dto.SubscribeAppItem{ |
| 1081 | Id: p.Id, |
| 1082 | Name: p.Name, |
| 1083 | IsSubscribed: isSubscribed, |
| 1084 | } |
| 1085 | }), canSubscribe, nil |
| 1086 | } |
| 1087 | list, err = i.roleService.ListByPermit(ctx, access.TeamConsumerSubscriptionSubscribe) |
| 1088 | if err != nil { |
| 1089 | return nil, false, nil |
| 1090 | } |
| 1091 | roleIds := utils.SliceToSlice(list, func(p *role.RoleByPermit) string { |
| 1092 | return p.Id |
| 1093 | }) |
| 1094 | members, err := i.roleMemberService.ListByRoleIds(ctx, utils.UserId(ctx), roleIds...) |
| 1095 | if err != nil { |
| 1096 | return nil, false, err |
| 1097 | } |
| 1098 | if len(members) == 0 { |
| 1099 | return nil, false, nil |
| 1100 | } |
| 1101 | |
| 1102 | teamMap := utils.SliceToMapO(members, func(p *role.Member) (string, struct{}) { |
| 1103 | return role.TrimTeamTarget(p.Target), struct{}{} |
| 1104 | }) |
| 1105 | result := make([]*service_dto.SubscribeAppItem, 0, len(apps)) |
| 1106 | for _, app := range apps { |
| 1107 | if _, ok := teamMap[app.Team]; !ok { |
| 1108 | continue |
| 1109 | } |
| 1110 | _, isSubscribed := subscribeMap[app.Id] |
| 1111 | if !isSubscribed { |
| 1112 | canSubscribe = true |
| 1113 | } |
| 1114 | result = append(result, &service_dto.SubscribeAppItem{ |
| 1115 | Id: app.Id, |
nothing calls this directly
no test coverage detected