mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 06:25:45 +01:00
modify the autocomplete link structure of the index resources
This commit is contained in:
@@ -534,9 +534,8 @@ public class ScmRequests {
|
||||
}
|
||||
|
||||
public class IndexResponse extends ModelResponse<IndexResponse> {
|
||||
|
||||
public static final String AUTOCOMPLETE_USERS = "_links.autocompleteUsers.href";
|
||||
public static final String AUTOCOMPLETE_GROUPS = "_links.autocompleteGroups.href";
|
||||
public static final String AUTOCOMPLETE_USERS = "_links.autocomplete.find{it.name=='users'}.href";
|
||||
public static final String AUTOCOMPLETE_GROUPS = "_links.autocomplete.find{it.name=='groups'}.href";
|
||||
|
||||
public IndexResponse(Response response) {
|
||||
super(response);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import de.otto.edison.hal.Link;
|
||||
import de.otto.edison.hal.Links;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
@@ -8,6 +10,7 @@ import sonia.scm.group.GroupPermissions;
|
||||
import sonia.scm.user.UserPermissions;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
import static de.otto.edison.hal.Link.link;
|
||||
|
||||
@@ -24,6 +27,7 @@ public class IndexDtoGenerator {
|
||||
|
||||
public IndexDto generate() {
|
||||
Links.Builder builder = Links.linkingTo();
|
||||
List<Link> autoCompleteLinks = Lists.newArrayList();
|
||||
builder.self(resourceLinks.index().self());
|
||||
builder.single(link("uiPlugins", resourceLinks.uiPluginCollection().self()));
|
||||
if (SecurityUtils.getSubject().isAuthenticated()) {
|
||||
@@ -35,11 +39,12 @@ public class IndexDtoGenerator {
|
||||
builder.single(link("users", resourceLinks.userCollection().self()));
|
||||
}
|
||||
if (UserPermissions.autocomplete().isPermitted()) {
|
||||
builder.single(link("autocompleteUsers", resourceLinks.autoComplete().users()));
|
||||
autoCompleteLinks.add(Link.linkBuilder("autocomplete", resourceLinks.autoComplete().users()).withName("users").build());
|
||||
}
|
||||
if (GroupPermissions.autocomplete().isPermitted()) {
|
||||
builder.single(link("autocompleteGroups", resourceLinks.autoComplete().groups()));
|
||||
autoCompleteLinks.add(Link.linkBuilder("autocomplete", resourceLinks.autoComplete().groups()).withName("groups").build());
|
||||
}
|
||||
builder.array(autoCompleteLinks);
|
||||
if (GroupPermissions.list().isPermitted()) {
|
||||
builder.single(link("groups", resourceLinks.groupCollection().self()));
|
||||
}
|
||||
|
||||
@@ -99,8 +99,9 @@ public class IndexResourceTest {
|
||||
public void shouldRenderAutoCompleteLinks() {
|
||||
IndexDto index = indexResource.getIndex();
|
||||
|
||||
Assertions.assertThat(index.getLinks().getLinkBy("autocompleteUsers")).matches(Optional::isPresent);
|
||||
Assertions.assertThat(index.getLinks().getLinkBy("autocompleteGroups")).matches(Optional::isPresent);
|
||||
Assertions.assertThat(index.getLinks().getLinksBy("autocomplete"))
|
||||
.extracting("name")
|
||||
.containsExactlyInAnyOrder("users", "groups");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,8 +109,9 @@ public class IndexResourceTest {
|
||||
public void userWithoutAutocompletePermissionShouldNotSeeAutoCompleteLinks() {
|
||||
IndexDto index = indexResource.getIndex();
|
||||
|
||||
Assertions.assertThat(index.getLinks().getLinkBy("autocompleteUsers")).matches(o -> !o.isPresent());
|
||||
Assertions.assertThat(index.getLinks().getLinkBy("autocompleteGroups")).matches(o -> !o.isPresent());
|
||||
Assertions.assertThat(index.getLinks().getLinksBy("autocomplete"))
|
||||
.extracting("name")
|
||||
.doesNotContainSequence("users", "groups");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user