Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
fix(apis): search by context-path doesn't work for non admin users
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGeraud committed May 28, 2019
1 parent 08a9f2c commit b20c7f1
Showing 1 changed file with 9 additions and 4 deletions.
Expand Up @@ -625,13 +625,20 @@ public Set<ApiEntity> findByUser(String userId, ApiQuery apiQuery) {
apis.addAll(convert(publicApis));
apis.addAll(convert(userApis));
apis.addAll(convert(groupApis));
return apis;
return filterApiByQuery(apis.stream(), apiQuery).collect(Collectors.toSet());
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to find APIs for user {}", userId, ex);
throw new TechnicalManagementException("An error occurs while trying to find APIs for user " + userId, ex);
}
}

private Stream<ApiEntity> filterApiByQuery(Stream<ApiEntity> apiEntityStream, ApiQuery query) {
return apiEntityStream
.filter(api -> query.getTag() == null || (api.getTags() != null && api.getTags().contains(query.getTag())))
.filter(api -> query.getContextPath() == null || query.getContextPath().equals(api.getProxy().getContextPath()));

}

@Override
public ApiEntity update(String apiId, UpdateApiEntity updateApiEntity) {
try {
Expand Down Expand Up @@ -1323,9 +1330,7 @@ public ApiEntity importPathMappingsFromPage(final ApiEntity apiEntity, final Str
public Collection<ApiEntity> search(final ApiQuery query) {
try {
LOGGER.debug("Search APIs by {}", query);
return convert(apiRepository.search(queryToCriteria(query).build())).stream()
.filter(api -> query.getTag() == null || (api.getTags() != null && api.getTags().contains(query.getTag())))
.filter(api -> query.getContextPath() == null || query.getContextPath().equals(api.getProxy().getContextPath()))
return filterApiByQuery(this.convert(apiRepository.search(queryToCriteria(query).build())).stream(), query)
.collect(toList());
} catch (TechnicalException ex) {
final String errorMessage = "An error occurs while trying to search for APIs: " + query;
Expand Down

0 comments on commit b20c7f1

Please sign in to comment.