Skip to content

Commit

Permalink
fix(Student Data): Student data does not save if in multiple workgrou…
Browse files Browse the repository at this point in the history
…ps in a run (#241)
  • Loading branch information
geoffreykwan authored Oct 4, 2023
1 parent 54b7f7d commit 98fb87d
Showing 1 changed file with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ public void handleGetConfigWISE5Preview(HttpServletRequest request, HttpServletR

@GetMapping("/config/studentRun/{runId}")
public void getConfigWISE5StudentRun(HttpServletRequest request, HttpServletResponse response,
@PathVariable("runId") RunImpl run) throws ObjectNotFoundException, IOException,
JSONException {
@PathVariable("runId") RunImpl run)
throws ObjectNotFoundException, IOException, JSONException {
JSONObject config = new JSONObject();
config.put("mode", "studentRun");
getRunConfigParameters(request, config, run);
Expand Down Expand Up @@ -411,8 +411,8 @@ private JSONArray getClassmateUserInfosJSONArray(Run run, Workgroup workgroup, U
JSONArray studentsNotInWorkgroup = new JSONArray();
for (User user : period.getMembers()) {
if (!workgroupService.isUserInAnyWorkgroupForRun(user, run)) {
JSONObject userJSONInfo =
createUserJSONInfo(user, isAllowedToViewStudentNames(run, loggedInUser));
JSONObject userJSONInfo = createUserJSONInfo(user,
isAllowedToViewStudentNames(run, loggedInUser));
studentsNotInWorkgroup.put(userJSONInfo);
}
}
Expand Down Expand Up @@ -781,28 +781,19 @@ private void addDummyUserInfoToConfig(JSONObject config) {
}

/**
* Gets the workgroup for the currently-logged in user so that she may view the VLE.
*
* Gets the workgroup for the logged in user
* @param run
* @return Workgroup for the currently-logged in user
* @throws ObjectNotFoundException
* @return Workgroup for the logged in user
*/
private Workgroup getWorkgroup(Run run) {
Workgroup workgroup = null;
SecurityContext context = SecurityContextHolder.getContext();
if (context.getAuthentication().getPrincipal() instanceof UserDetails) {
UserDetails userDetails = (UserDetails) context.getAuthentication().getPrincipal();
User user = userService.retrieveUser(userDetails);

List<Workgroup> workgroupListByRunAndUser = workgroupService.getWorkgroupListByRunAndUser(run,
user);

if (workgroupListByRunAndUser.size() == 1) {
workgroup = workgroupListByRunAndUser.get(0);
} else if (workgroupListByRunAndUser.size() > 1) {
// this user is in more than one workgroup so we will just get the last one
workgroup = workgroupListByRunAndUser.get(workgroupListByRunAndUser.size() - 1);
}
workgroup = workgroupListByRunAndUser.get(0);
}
return workgroup;
}
Expand Down

0 comments on commit 98fb87d

Please sign in to comment.