@Test public void testGetRoutingRules_AssignedRepositoriesMultipleHiddenByPerms() { when(routingRuleStore.list()).thenReturn(Arrays.asList(rule1, rule2, rule3)); Map<EntityId,List<Repository>> ruleRepoMap = new HashMap<>(); ruleRepoMap.put(new DetachedEntityId("rule1"), Arrays.asList(repository1, repository2, repository3)); ruleRepoMap.put(new DetachedEntityId("rule2"), Collections.emptyList()); ruleRepoMap.put(new DetachedEntityId("rule3"), Collections.emptyList()); when(routingRuleHelper.calculateAssignedRepositories()).thenReturn(ruleRepoMap); when(repositoryPermissionChecker .userHasRepositoryAdminPermission(Arrays.asList(repository1, repository2, repository3), "read")) .thenReturn(Arrays.asList(repository1, repository3)); when(repositoryPermissionChecker.userCanBrowseRepository(repository1)).thenReturn(true); when(repositoryPermissionChecker.userCanBrowseRepository(repository2)).thenReturn(false); when(repositoryPermissionChecker.userCanBrowseRepository(repository3)).thenReturn(true); List<RoutingRuleXO> xos = underTest.getRoutingRules(true); assertThat(xos.size(), is(3)); assertXO(xos.get(0), "rule1", 3, "repository1", "repository3"); assertXO(xos.get(1), "rule2", 0); assertXO(xos.get(2), "rule3", 0); }
@GET public List<RoutingRuleXO> getRoutingRules(@QueryParam("includeRepositoryNames") boolean includeRepositoryNames) { routingRuleHelper.ensureUserHasPermissionToRead(); List<RoutingRuleXO> rules = routingRuleStore.list() .stream() .map(RoutingRulesResource::toXO) .collect(toList()); if (includeRepositoryNames) { setAssignedRepositories(rules); } return rules; }
RoutingRulesResource extends ComponentSupport implements Resource { @GET public List<RoutingRuleXO> getRoutingRules(@QueryParam("includeRepositoryNames") boolean includeRepositoryNames) { routingRuleHelper.ensureUserHasPermissionToRead(); List<RoutingRuleXO> rules = routingRuleStore.list() .stream() .map(RoutingRulesResource::toXO) .collect(toList()); if (includeRepositoryNames) { setAssignedRepositories(rules); } return rules; } }
RoutingRulesResource extends ComponentSupport implements Resource { @GET public List<RoutingRuleXO> getRoutingRules(@QueryParam("includeRepositoryNames") boolean includeRepositoryNames) { routingRuleHelper.ensureUserHasPermissionToRead(); List<RoutingRuleXO> rules = routingRuleStore.list() .stream() .map(RoutingRulesResource::toXO) .collect(toList()); if (includeRepositoryNames) { setAssignedRepositories(rules); } return rules; } @Inject  RoutingRulesResource(final RoutingRuleStore routingRuleStore,
                              final RoutingRuleHelper routingRuleHelper,
                              final RepositoryPermissionChecker repositoryPermissionChecker); }
RoutingRulesResource extends ComponentSupport implements Resource { @GET public List<RoutingRuleXO> getRoutingRules(@QueryParam("includeRepositoryNames") boolean includeRepositoryNames) { routingRuleHelper.ensureUserHasPermissionToRead(); List<RoutingRuleXO> rules = routingRuleStore.list() .stream() .map(RoutingRulesResource::toXO) .collect(toList()); if (includeRepositoryNames) { setAssignedRepositories(rules); } return rules; } @Inject  RoutingRulesResource(final RoutingRuleStore routingRuleStore,
                              final RoutingRuleHelper routingRuleHelper,
                              final RepositoryPermissionChecker repositoryPermissionChecker); @POST @RequiresAuthentication @RequiresPermissions("nexus:*") void createRoutingRule(RoutingRuleXO routingRuleXO); @POST @Path("/test") @RequiresAuthentication @RequiresPermissions("nexus:*") boolean isAllowed(RoutingRuleTestXO routingRuleTestXO); @GET List<RoutingRuleXO> getRoutingRules(@QueryParam("includeRepositoryNames") boolean includeRepositoryNames); @PUT @Path("/{name}") @RequiresAuthentication @RequiresPermissions("nexus:*") void updateRoutingRule(@PathParam("name") final String name, RoutingRuleXO routingRuleXO); @DELETE @Path("/{name}") @RequiresAuthentication @RequiresPermissions("nexus:*") void deleteRoutingRule(@PathParam("name") final String name); @GET @Path("/preview") @RequiresPermissions("nexus:*") @RequiresAuthentication RoutingRulePreviewXO getRoutingRulesPreview(@QueryParam("path") final String path,
                                                     @QueryParam("filter") final String filter); }
RoutingRulesResource extends ComponentSupport implements Resource { @GET public List<RoutingRuleXO> getRoutingRules(@QueryParam("includeRepositoryNames") boolean includeRepositoryNames) { routingRuleHelper.ensureUserHasPermissionToRead(); List<RoutingRuleXO> rules = routingRuleStore.list() .stream() .map(RoutingRulesResource::toXO) .collect(toList()); if (includeRepositoryNames) { setAssignedRepositories(rules); } return rules; } @Inject  RoutingRulesResource(final RoutingRuleStore routingRuleStore,
                              final RoutingRuleHelper routingRuleHelper,
                              final RepositoryPermissionChecker repositoryPermissionChecker); @POST @RequiresAuthentication @RequiresPermissions("nexus:*") void createRoutingRule(RoutingRuleXO routingRuleXO); @POST @Path("/test") @RequiresAuthentication @RequiresPermissions("nexus:*") boolean isAllowed(RoutingRuleTestXO routingRuleTestXO); @GET List<RoutingRuleXO> getRoutingRules(@QueryParam("includeRepositoryNames") boolean includeRepositoryNames); @PUT @Path("/{name}") @RequiresAuthentication @RequiresPermissions("nexus:*") void updateRoutingRule(@PathParam("name") final String name, RoutingRuleXO routingRuleXO); @DELETE @Path("/{name}") @RequiresAuthentication @RequiresPermissions("nexus:*") void deleteRoutingRule(@PathParam("name") final String name); @GET @Path("/preview") @RequiresPermissions("nexus:*") @RequiresAuthentication RoutingRulePreviewXO getRoutingRulesPreview(@QueryParam("path") final String path,
                                                     @QueryParam("filter") final String filter);  }