Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small UX improvements #213

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public List<String> testIamPermissions(
}
}

public List<ProjectId> searchProjectIds(String query) throws NotAuthenticatedException, IOException {
public Set<ProjectId> searchProjectIds(String query) throws NotAuthenticatedException, IOException {
try {
var client = createClient();

Expand Down Expand Up @@ -287,7 +287,7 @@ public List<ProjectId> searchProjectIds(String query) throws NotAuthenticatedExc

return allProjects.stream()
.map(p -> new ProjectId(p.getProjectId()))
.collect(Collectors.toList());
.collect(Collectors.toCollection(TreeSet::new));
jpassing marked this conversation as resolved.
Show resolved Hide resolved
}
catch (GoogleJsonResponseException e) {
switch (e.getStatusCode()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* Project ID for a Google Cloud project.
*/
public class ProjectId {
public class ProjectId implements Comparable<ProjectId> {
private static final String PROJECT_RESOURCE_NAME_PREFIX = "//cloudresourcemanager.googleapis.com/projects/";

public final String id;
Expand Down Expand Up @@ -94,4 +94,9 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(this.id);
}

@Override
public int compareTo(ProjectId o) {
return this.id.compareTo(o.id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* Represents an eligible role on a project.
*/
public class ProjectRole {
public class ProjectRole implements Comparable<ProjectRole> {
public final RoleBinding roleBinding;
public final Status status;

Expand Down Expand Up @@ -76,6 +76,11 @@ public int hashCode() {
return Objects.hash(this.roleBinding, this.status);
}

@Override
public int compareTo(ProjectRole o) {
return this.roleBinding.compareTo(o.roleBinding);
}

// -------------------------------------------------------------------------
// Inner classes.
// -------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@

import com.google.common.base.Preconditions;

import java.util.Comparator;
import java.util.Objects;

/**
* Represents a role that has been granted on a resource.
*/
public class RoleBinding {
public class RoleBinding implements Comparable<RoleBinding> {
public final String fullResourceName;
public final String role;

Expand Down Expand Up @@ -71,4 +72,11 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(this.fullResourceName, this.role);
}

@Override
public int compareTo(RoleBinding o) {
return Comparator.comparing((RoleBinding r) -> r.fullResourceName)
.thenComparing(r -> r.role)
.compare(this, o);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import java.util.Objects;

public class UserId {
public class UserId implements Comparable<UserId> {
public final transient String id;
public final String email;

Expand Down Expand Up @@ -67,4 +67,9 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(email);
}

@Override
public int compareTo(UserId o) {
return this.email.compareTo(o.email);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ public Set<ProjectId> listAvailableProjects(
return roleBindings
.stream()
.map(b -> ProjectId.fromFullResourceName(b.fullResourceName))
.collect(Collectors.toSet());
.collect(Collectors.toCollection(TreeSet::new));
}
else {
// Used as alternative option if availableProjectsQuery is set and the main approach with Asset API is not working fast enough.
return new HashSet<>(resourceManagerAdapter.searchProjectIds(this.options.availableProjectsQuery));
return resourceManagerAdapter.searchProjectIds(this.options.availableProjectsQuery);
}
}

Expand Down Expand Up @@ -291,9 +291,7 @@ public Result<ProjectRole> listEligibleProjectRoles(
consolidatedRoles.addAll(activatedRoles);
jpassing marked this conversation as resolved.
Show resolved Hide resolved

return new Result<>(
consolidatedRoles.stream()
.sorted(Comparator.comparing(r -> r.roleBinding.fullResourceName))
.collect(Collectors.toList()),
consolidatedRoles.stream().sorted().collect(Collectors.toList()),
jpassing marked this conversation as resolved.
Show resolved Hide resolved
Stream.ofNullable(analysisResult.getNonCriticalErrors())
.flatMap(Collection::stream)
.map(e -> e.getCause())
Expand Down Expand Up @@ -353,7 +351,7 @@ public Set<UserId> listEligibleUsersForProjectRole(

// Remove the caller.
.filter(user -> !user.equals(callerUserId))
.collect(Collectors.toSet());
.collect(Collectors.toCollection(TreeSet::new));
jpassing marked this conversation as resolved.
Show resolved Hide resolved
}

// -------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions sources/src/main/resources/META-INF/resources/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ a {
height: auto;
}

.mdl-stepper {
max-width: 1024px;
}

.mdl-step__transient {
height: calc(100% - 32px);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.TreeSet;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.*;

public class TestProjectId {
Expand Down Expand Up @@ -104,4 +108,14 @@ public void whenObjectIsDifferentType_ThenEqualsReturnsFalse() {

assertFalse(id1.equals(""));
}

@Test
public void whenInTreeSet_ThenReturnsInExpectedOrder() {
var projects = List.of(new ProjectId("project-3"),new ProjectId("project-1"), new ProjectId("project-2"));
var sortedProjects = new TreeSet<>(projects);
var sortedIter = sortedProjects.iterator();
assertEquals(sortedIter.next(), new ProjectId("project-1"));
assertEquals(sortedIter.next(), new ProjectId("project-2"));
assertEquals(sortedIter.next(), new ProjectId("project-3"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.TreeSet;

import static org.junit.jupiter.api.Assertions.*;

public class TestProjectRole {
Expand Down Expand Up @@ -133,4 +136,26 @@ public void equalsNullIsFalse() {

assertFalse(role.equals(null));
}

@Test
public void whenInTreeSet_ThenReturnsInExpectedOrder() {
var role1 = new ProjectRole(
new RoleBinding("//cloudresourcemanager.googleapis.com/projects/project-1", "role/sample1"),
ProjectRole.Status.ELIGIBLE_FOR_JIT
);
var role2 = new ProjectRole(
new RoleBinding("//cloudresourcemanager.googleapis.com/projects/project-1", "role/sample2"),
ProjectRole.Status.ELIGIBLE_FOR_JIT
);
var role3 = new ProjectRole(
new RoleBinding("//cloudresourcemanager.googleapis.com/projects/project-2", "role/sample1"),
ProjectRole.Status.ELIGIBLE_FOR_JIT
);
var roles = List.of(role3,role1,role2);
var sorted = new TreeSet<>(roles);
var sortedIter = sorted.iterator();
assertEquals(sortedIter.next(), role1);
assertEquals(sortedIter.next(), role2);
assertEquals(sortedIter.next(), role3);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1101,8 +1101,7 @@ public void whenResourceManagerEmpty_ThenListAvailableProjectsReturnsEmptyList()
var assetAdapter = Mockito.mock(AssetInventoryAdapter.class);
var resourceManagerAdapter = Mockito.mock(ResourceManagerAdapter.class);

when(resourceManagerAdapter.searchProjectIds(eq("parent:folder/0")))
.thenReturn(List.of());
when(resourceManagerAdapter.searchProjectIds(eq("parent:folder/0"))).thenReturn(Set.of());

var service = new RoleDiscoveryService(
assetAdapter,
Expand All @@ -1118,7 +1117,7 @@ public void whenResourceManagerEmpty_ThenListAvailableProjectsReturnsEmptyList()
public void whenResourceManagerReturnsList_ThenListAvailableProjectsReturnsTheSameList() throws Exception {
var assetAdapter = Mockito.mock(AssetInventoryAdapter.class);
var resourceManagerAdapter = Mockito.mock(ResourceManagerAdapter.class);
var expectedProjectIds = List.of(new ProjectId("project-1"), new ProjectId("project-2"));
var expectedProjectIds = Set.of(new ProjectId("project-1"), new ProjectId("project-2"));

when(resourceManagerAdapter.searchProjectIds(eq("parent:folder/0")))
.thenReturn(expectedProjectIds);
Expand Down