Skip to content

FEATURE: Add paging to the admin users page #118

Description

@pconrad

After adding the toggle features to the admin users page, one thing that you'll notice is that as soon as you click on a row, it jumps to another spot.

This is because there is no sorting and paging in the backend for the admin users endpoint.

In addition, the users are not paged; if/when we release this app into real production, the number of users will be too many to display on a single page at once.

Fix this by adding sorting and paging in the backend.

Compare, this code from proj-dining:

  @Operation(summary = "Get a list of all users")
  @PreAuthorize("hasRole('ROLE_ADMIN')")
  @GetMapping("/admin/users")
  public ResponseEntity<String> users() throws JsonProcessingException {

    Iterable<User> users = userRepository.findAll();
    String body = mapper.writeValueAsString(users);
    return ResponseEntity.ok().body(body);
  }

Vs. proj-frontiers: https://github.com/ucsb-cs156/proj-frontiers/blob/main/src/main/java/edu/ucsb/cs156/frontiers/controllers/UsersController.java

@Tag(name = "User information (admin only)")
@RequestMapping("/api/admin/users")
@RestController
public class UsersController extends ApiController {
  @Autowired private UserDataDTOService userDataDTOService;

  /**
   * This method returns a list of all users. Accessible only to users with the role "ROLE_ADMIN".
   *
   * @return a list of all users
   * @throws JsonProcessingException if there is an error processing the JSON
   */
  @Operation(summary = "Get a list of all users")
  @PreAuthorize("hasRole('ROLE_ADMIN')")
  @GetMapping("")
  public Page<UserDataDTO> users(Pageable pageable) throws JsonProcessingException {
    return userDataDTOService.getUserDataDTOs(pageable);
  }
}

But we can't just change this in one step; that would break the frontend.

You'll need to proceed in stages. Each of these is a subissue.

Note that if you need to temporarily remove the ability to toggle users moderator and admin status, that's ok, as long as you can still add/delete moderators in some fashion through either swagger or through a dedicated page for adding and deleting admins and moderators by their email (as is done in frontiers.)

Subissues

  • Add an endpoint /api/admin/users/paged that matches the functionality in proj-frontiers. Look into how the userDataDTOService works; you'll need to add that as well.
  • Modify the frontend Admin Users Page to incorporate paging. Look at the frontend of frontiers admin users page for a guide as to how to proceed.
  • Adjust the code so that the pages of users are always sorted by user id.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions