Skip to content

Commit

Permalink
General: Fix an issue when trying to delete too many users at once (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisknedl authored Oct 12, 2024
1 parent 87d73ec commit db90e89
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

Expand Down Expand Up @@ -281,7 +280,7 @@ public ResponseEntity<Void> deleteUser(@PathVariable String login) {
* @return the ResponseEntity with status 200 (OK)
*/
@DeleteMapping("users")
public ResponseEntity<List<String>> deleteUsers(@RequestParam(name = "login") List<String> logins) {
public ResponseEntity<List<String>> deleteUsers(@RequestBody List<String> logins) {
log.debug("REST request to delete {} users", logins.size());
List<String> deletedUsers = Collections.synchronizedList(new java.util.ArrayList<>());

Expand Down
8 changes: 2 additions & 6 deletions src/main/webapp/app/core/user/admin-user.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams, HttpResponse } from '@angular/common/http';
import { HttpClient, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';

import { createRequestOption } from 'app/shared/util/request.util';
Expand Down Expand Up @@ -94,11 +94,7 @@ export class AdminUserService {
* @return Observable<HttpResponse<void>>
*/
deleteUsers(logins: string[]): Observable<HttpResponse<void>> {
let params = new HttpParams();
for (const login of logins) {
params = params.append('login', login);
}
return this.http.delete<void>(`${this.resourceUrl}`, { params, observe: 'response' });
return this.http.delete<void>(`${this.resourceUrl}`, { body: logins, observe: 'response' });
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,8 @@ public void deleteUsers(String currentUserLogin) throws Exception {
var users = Set.of(userUtilService.getUserByLogin(TEST_PREFIX + "student1"), userUtilService.getUserByLogin(TEST_PREFIX + "tutor1"),
userUtilService.getUserByLogin(TEST_PREFIX + "editor1"), userUtilService.getUserByLogin(TEST_PREFIX + "instructor1"));

LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>();
users.stream().map(User::getLogin).forEach(login -> params.add("login", login));

request.delete("/api/admin/users", HttpStatus.OK, params);
var logins = users.stream().map(User::getLogin).toList();
request.delete("/api/admin/users", HttpStatus.OK, logins);

for (var user : users) {
final var deletedUser = userTestRepository.findById(user.getId()).orElseThrow();
Expand Down

0 comments on commit db90e89

Please sign in to comment.