Skip to content

Commit

Permalink
Fix #7812 Backend : Leave Team is throwing an error (#7835)
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekratnavel authored Oct 1, 2022
1 parent 1e31245 commit 16e8778
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ private void assignTeams(User user, List<EntityReference> teams) {
}
addRelationship(team.getId(), user.getId(), Entity.TEAM, Entity.USER, Relationship.HAS);
}
if (teams.size() > 1) {
// Remove organization team from the response
teams = teams.stream().filter(t -> !t.getId().equals(organization.getId())).collect(Collectors.toList());
user.setTeams(teams);
}
}

/** Handles entity updated from PUT and POST operation. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import java.util.TimeZone;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.HttpResponseException;
Expand Down Expand Up @@ -519,6 +520,28 @@ void patch_userNameChange_as_same_user_200_ok(TestInfo test) throws HttpResponse
assertEquals(newDisplayName, user.getDisplayName());
}

@Test
void patch_teamAddition_200_ok(TestInfo test) throws HttpResponseException, JsonProcessingException {
TeamResourceTest teamResourceTest = new TeamResourceTest();
EntityReference team1 =
teamResourceTest.createEntity(teamResourceTest.createRequest(test, 1), ADMIN_AUTH_HEADERS).getEntityReference();
User user =
createEntity(
createRequest(test, 10)
.withName("testUser1")
.withDisplayName("displayName")
.withEmail("[email protected]"),
authHeaders("[email protected]"));
String userJson = JsonUtils.pojoToJson(user);
List<EntityReference> teams = user.getTeams();
teams.add(team1);
user.setTeams(teams); // Update the teams
user = patchEntity(user.getId(), userJson, user, ADMIN_AUTH_HEADERS); // Patch the user
// Ensure default "Organization" team is not part of the patch response
assertEquals(1, user.getTeams().size());
assertEquals(team1.getId(), user.getTeams().get(0).getId());
}

@Test
void patch_userAttributes_as_admin_200_ok(TestInfo test) throws IOException {
// Create user without any attributes - ***Note*** isAdmin by default is false.
Expand Down Expand Up @@ -793,6 +816,10 @@ public void validateCreatedEntity(User user, CreateUser createRequest, Map<Strin
}
if (expectedTeams.isEmpty()) {
expectedTeams = new ArrayList<>(List.of(ORG_TEAM.getEntityReference())); // Organization is default team
} else {
// Remove ORG_TEAM from the expected teams
expectedTeams =
expectedTeams.stream().filter(t -> !t.getId().equals(ORG_TEAM.getId())).collect(Collectors.toList());
}
assertEntityReferences(expectedTeams, user.getTeams());

Expand Down

0 comments on commit 16e8778

Please sign in to comment.