Skip to content

Commit

Permalink
Merge branch 'master' into java-17
Browse files Browse the repository at this point in the history
  • Loading branch information
dkfellows committed Jun 26, 2023
2 parents f71b53c + 47fe32a commit 335c9c2
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,32 @@ public interface AdminController {
/**
* Get supported ops.
*
* @param model
* Overall model
* @return the view
*/
@GetMapping("/")
ModelAndView mainUI();
ModelAndView mainUI(ModelMap model);

/**
* List all users.
*
* @param model
* Overall model
* @return the model and view
*/
@GetMapping(USERS_PATH)
ModelAndView listUsers();
ModelAndView listUsers(ModelMap model);

/**
* Get the form for creating a user.
*
* @param model
* Overall model
* @return the model and view
*/
@GetMapping(CREATE_USER_PATH)
ModelAndView getUserCreationForm();
ModelAndView getUserCreationForm(ModelMap model);

/**
* Create a user.
Expand Down Expand Up @@ -197,10 +203,12 @@ ModelAndView deleteUser(@PathVariable("id") int id, Principal principal,
/**
* List all groups.
*
* @param model
* Overall model
* @return the model and view
*/
@GetMapping(GROUPS_PATH)
ModelAndView listGroups();
ModelAndView listGroups(ModelMap model);

/**
* Get info about a particular group.
Expand All @@ -215,10 +223,12 @@ ModelAndView deleteUser(@PathVariable("id") int id, Principal principal,
/**
* Get the form for creating a group.
*
* @param model
* Overall model
* @return the model (a {@link CreateGroupModel}) and view
*/
@GetMapping(CREATE_GROUP_PATH)
ModelAndView getGroupCreationForm();
ModelAndView getGroupCreationForm(ModelMap model);

/**
* Create a group.
Expand Down Expand Up @@ -372,10 +382,12 @@ ModelAndView deleteGroup(@PathVariable("id") int id,
/**
* UI for boards.
*
* @param model
* Overall model
* @return the model and view
*/
@GetMapping(BOARDS_PATH)
ModelAndView boards();
ModelAndView boards(ModelMap model);

/**
* Manipulate a board.
Expand Down Expand Up @@ -437,10 +449,12 @@ CompletableFuture<ModelAndView> blacklistPush(
/**
* Provide the form for uploading a machine definition.
*
* @param model
* Overall model
* @return the model and view
*/
@GetMapping(MACHINE_PATH)
ModelAndView machineManagement();
ModelAndView machineManagement(ModelMap model);

/**
* Handle the change of the tags of a machine.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ public class AdminControllerImpl extends DatabaseAwareBean
/** One board-hour in board-seconds. */
private static final int BOARD_HOUR = 3600;

/** Dummy map. */
private static final ModelMap NULL_MAP = null;

/** Dummy user. */
private static final Principal NULL_USER = null;

/** Dummy attributes. */
private static final RedirectAttributes NULL_ATTR = null;

@Autowired
private UserControl userManager;

Expand Down Expand Up @@ -192,12 +201,13 @@ private static void addStandardContextAttrs(Map<String, Object> model) {

model.put(BASE_URI, fromCurrentRequestUri().toUriString());
model.put(TRUST_LEVELS, TrustLevel.values());
model.put(USERS_URI, uri(admin().listUsers()));
model.put(CREATE_USER_URI, uri(admin().getUserCreationForm()));
model.put(CREATE_GROUP_URI, uri(admin().getGroupCreationForm()));
model.put(GROUPS_URI, uri(admin().listGroups()));
model.put(BOARDS_URI, uri(admin().boards()));
model.put(MACHINE_URI, uri(admin().machineManagement()));
model.put(USERS_URI, uri(admin().listUsers(NULL_MAP)));
model.put(CREATE_USER_URI, uri(admin().getUserCreationForm(NULL_MAP)));
model.put(CREATE_GROUP_URI,
uri(admin().getGroupCreationForm(NULL_MAP)));
model.put(GROUPS_URI, uri(admin().listGroups(NULL_MAP)));
model.put(BOARDS_URI, uri(admin().boards(NULL_MAP)));
model.put(MACHINE_URI, uri(admin().machineManagement(NULL_MAP)));
model.put(USER_MAY_CHANGE_PASSWORD, mayChangePassword);
}

Expand Down Expand Up @@ -355,13 +365,13 @@ ModelAndView adminException(AdminException e, HandlerMethod hm) {

@Override
@Action("getting the main admin UI")
public ModelAndView mainUI() {
public ModelAndView mainUI(ModelMap ignored) {
return addStandardContext(MAIN_VIEW.view());
}

@Override
@Action("listing the users")
public ModelAndView listUsers() {
public ModelAndView listUsers(ModelMap ignored) {
var mav = USER_LIST_VIEW.view();
addLocalUserList(mav,
userManager.listUsers(true, this::showUserFormUrl));
Expand All @@ -372,7 +382,7 @@ public ModelAndView listUsers() {

@Override
@Action("getting the user-creation UI")
public ModelAndView getUserCreationForm() {
public ModelAndView getUserCreationForm(ModelMap ignored) {
var userForm = new UserRecord();
userForm.setInternal(true);
return addStandardContext(
Expand Down Expand Up @@ -461,7 +471,7 @@ public ModelAndView deleteUser(int id, Principal principal,
() -> new AdminException("could not delete that user"));
log.info("deleted user ID={} username={}", id, deletedUsername);
// Not sure that these are the correct place
var mav = redirectTo(uri(admin().listUsers()), attrs);
var mav = redirectTo(uri(admin().listUsers(NULL_MAP)), attrs);
addNotice(attrs, "deleted " + deletedUsername);
addUser(attrs, new UserRecord());
return mav;
Expand All @@ -477,12 +487,12 @@ public ModelAndView deleteUser(int id, Principal principal,
* @return URL
*/
private URI deleteUserUrl(int id) {
return uri(admin().deleteUser(id, null, null));
return uri(admin().deleteUser(id, NULL_USER, NULL_ATTR));
}

@Override
@Action("listing the groups")
public ModelAndView listGroups() {
public ModelAndView listGroups(ModelMap ignored) {
var mav = GROUP_LIST_VIEW.view();
addLocalGroupList(mav,
userManager.listGroups(INTERNAL, this::showGroupInfoUrl));
Expand All @@ -500,12 +510,15 @@ public ModelAndView showGroupInfo(int id) {
var userLocations = new HashMap<String, URI>();
addGroup(mav, userManager.getGroup(id, m -> {
userLocations.put(m.getUserName(), showUserFormUrl(m));
return uri(admin().removeUserFromGroup(id, m.getUserId(), null));
return uri(
admin().removeUserFromGroup(id, m.getUserId(), NULL_ATTR));
}).orElseThrow(NoGroup::new));
addUserList(mav, userLocations);
addUrl(mav, "deleteUri", uri(admin().deleteGroup(id, null)));
addUrl(mav, "addUserUri", uri(admin().addUserToGroup(id, null, null)));
addUrl(mav, "addQuotaUri", uri(admin().adjustGroupQuota(id, 0, null)));
addUrl(mav, "deleteUri", uri(admin().deleteGroup(id, NULL_ATTR)));
addUrl(mav, "addUserUri",
uri(admin().addUserToGroup(id, null, NULL_ATTR)));
addUrl(mav, "addQuotaUri",
uri(admin().adjustGroupQuota(id, 0, NULL_ATTR)));
return addStandardContext(mav);
}

Expand Down Expand Up @@ -544,7 +557,7 @@ private URI showGroupInfoUrl(GroupRecord group) {

@Override
@Action("getting the group-creation UI")
public ModelAndView getGroupCreationForm() {
public ModelAndView getGroupCreationForm(ModelMap ignored) {
return addStandardContext(
CREATE_GROUP_VIEW.view(GROUP_OBJ, new CreateGroupModel()));
}
Expand Down Expand Up @@ -619,12 +632,12 @@ public ModelAndView deleteGroup(int id, RedirectAttributes attrs) {
userManager.deleteGroup(id).orElseThrow(NoGroup::new);
log.info("deleted group ID={} groupname={}", id, deletedGroupName);
addNotice(attrs, "deleted " + deletedGroupName);
return redirectTo(uri(admin().listGroups()), attrs);
return redirectTo(uri(admin().listGroups(NULL_MAP)), attrs);
}

@Override
@Action("getting the UI for finding boards")
public ModelAndView boards() {
public ModelAndView boards(ModelMap ignored) {
var mav = BOARD_VIEW.view();
addBoard(mav, new BoardRecord());
addMachineList(mav, getMachineNames(true));
Expand Down Expand Up @@ -795,7 +808,7 @@ private void inflateBoardRecord(BoardRecord br, BoardState bs) {
*/
@Override
@Action("getting a machine's configuration")
public ModelAndView machineManagement() {
public ModelAndView machineManagement(ModelMap ignored) {
var mav = MACHINE_VIEW.view();
addMachineList(mav, getMachineNames(true));
var tagging = machineController.getMachineTagging();
Expand All @@ -813,23 +826,23 @@ public ModelAndView retagMachine(String machineName, String newTags) {
stream(newTags.split(",")).map(String::strip).collect(toSet());
machineController.updateTags(machineName, tags);
log.info("retagged {} to have tags {}", machineName, tags);
return machineManagement();
return machineManagement(NULL_MAP);
}

@Override
@Action("disabling a machine")
public ModelAndView disableMachine(String machineName) {
machineController.setMachineState(machineName, false);
log.info("marked {} as out of service", machineName);
return machineManagement();
return machineManagement(NULL_MAP);
}

@Override
@Action("enabling a machine")
public ModelAndView enableMachine(String machineName) {
machineController.setMachineState(machineName, true);
log.info("marked {} as in service", machineName);
return machineManagement();
return machineManagement(NULL_MAP);
}

@Override
Expand All @@ -840,7 +853,7 @@ public ModelAndView defineMachine(MultipartFile file) {
machineDefiner.loadMachineDefinition(m);
log.info("defined machine {}", m.getName());
}
var mav = machineManagement();
var mav = machineManagement(NULL_MAP);
// Tailor with extra objects here
mav.addObject(DEFINED_MACHINES_OBJ, machines);
return mav;
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ limitations under the License.
<log4j.version>2.20.0</log4j.version>

<spring.version>5.3.28</spring.version>
<spring.boot.version>2.7.12</spring.boot.version>
<spring.boot.version>2.7.13</spring.boot.version>
<!--
DKF: if you update spring.boot.version, also update the annotation
processor binding in Eclipse for SpiNNaker-allocserv:
Expand Down Expand Up @@ -600,7 +600,7 @@ limitations under the License.
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.12.1</version>
<version>1.13.3</version>
</plugin>
<plugin>
<groupId>com.github.blutorange</groupId>
Expand Down

0 comments on commit 335c9c2

Please sign in to comment.