Skip to content

Commit

Permalink
fixed bug which prevented bulk-edit operations via API for a large nu…
Browse files Browse the repository at this point in the history
…mber of users
  • Loading branch information
albogdano committed Oct 10, 2024
1 parent 46f5210 commit de6742b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/main/java/com/erudika/scoold/api/ApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,9 @@ public void bulkEditSpaces(HttpServletRequest req, HttpServletResponse res) {
Collections.emptyList())).stream().distinct().collect(Collectors.toSet());
Set<String> selectedBadges = ((List<String>) entity.getOrDefault("badges",
Collections.emptyList())).stream().distinct().collect(Collectors.toSet());
peopleController.bulkEdit(selectedUsers.toArray(new String[0]),
readSpaces(selectedSpaces).toArray(new String[0]),
selectedBadges.toArray(new String[0]), req);
peopleController.bulkEdit(selectedUsers.toArray(String[]::new),
readSpaces(selectedSpaces).toArray(String[]::new),
selectedBadges.toArray(String[]::new), req);
}

@PostMapping("/tags")
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/com/erudika/scoold/controllers/PeopleController.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.erudika.scoold.utils.HttpUtils;
import com.erudika.scoold.utils.ScooldUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import jakarta.inject.Inject;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.util.ArrayList;
Expand All @@ -46,7 +47,6 @@
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import jakarta.inject.Inject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
Expand Down Expand Up @@ -119,12 +119,18 @@ public String bulkEdit(@RequestParam(required = false) String[] selectedUsers,
Collections.emptyList() : Arrays.asList(selectedSpaces);
List<String> badges = (selectedBadges == null || selectedBadges.length == 0) ?
Collections.emptyList() : Arrays.asList(selectedBadges);
String query = (selection == null || "selected".equals(selection)) ?
Config._ID + ":(\"" + String.join("\" \"", selectedUsers) + "\")" : "*";

pc.updateAllPartially((toUpdate, pager) -> {
List<Profile> profiles = pc.findQuery(Utils.type(Profile.class), query, pager);
bulkEditSpacesAndBadges(profiles, operation, spaces, badges, toUpdate);
return profiles;
List<Profile> profiles;
if (selection == null || "selected".equals(selection)) {
profiles = pc.readAll(List.of(selectedUsers));
bulkEditSpacesAndBadges(profiles, operation, spaces, badges, toUpdate);
return Collections.emptyList();
} else {
profiles = pc.findQuery(Utils.type(Profile.class), "*", pager);
bulkEditSpacesAndBadges(profiles, operation, spaces, badges, toUpdate);
return profiles;
}
});
}
return "redirect:" + PEOPLELINK + (isAdmin ? "?" + req.getQueryString() : "");
Expand Down

0 comments on commit de6742b

Please sign in to comment.