Skip to content

Commit

Permalink
SAK-50365 Gradebook Quick Entry getUsers call filters out bad users a…
Browse files Browse the repository at this point in the history
…nd sorts them (sakaiproject#12783)
  • Loading branch information
ottenhoff authored Aug 9, 2024
1 parent 5e9bec9 commit 583446e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public List<String> getGradeableUsers(final String siteId, final GbGroup groupFi
final List<CourseSection> courseSections = this.gradingService.getViewableSections(gradebook.getUid());

//for each section TA has access to, grab student Id's
List<String> viewableStudents = new ArrayList();
List<String> viewableStudents = new ArrayList<>();

Map<String, Set<Member>> groupMembers = getGroupMembers(givenSiteId);

Expand Down Expand Up @@ -314,13 +314,12 @@ public List<String> getGradeableUsers(final String siteId, final GbGroup groupFi
userUuids.retainAll(viewableStudents); // retain only those that are visible to this TA
} else {
userUuids.removeAll(sectionManager.getSectionEnrollmentsForStudents(givenSiteId, userUuids).getStudentUuids()); // TA can view/grade students without section
userUuids.removeAll(nonProvidedMembers); // Filter out non-provided users
nonProvidedMembers.forEach(userUuids::remove); // Filter out non-provided users
}
}
}

return new ArrayList<>(userUuids);

} catch (final IdUnusedException e) {
log.warn("IdUnusedException trying to getGradeableUsers", e);
return null;
Expand All @@ -334,12 +333,12 @@ public List<String> getGradeableUsers(final String siteId, final GbGroup groupFi
* Given a list of uuids, get a list of Users
*
* @param userUuids list of user uuids
* @return
* @return a List of full User objects
*/
public List<User> getUsers(final List<String> userUuids) throws GbException {
try {
final List<User> users = this.userDirectoryService.getUsers(userUuids);
Collections.sort(users, new UserSortNameComparator()); // TODO: remove this sort, it causes double sorting in various scenarios
users.sort(new UserSortNameComparator()); // TODO: remove this sort, it causes double sorting in various scenarios
return users;
} catch (final RuntimeException e) {
// an LDAP exception can sometimes be thrown here, catch and rethrow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import lombok.Getter;
import lombok.Setter;
import org.sakaiproject.user.api.User;

public class QuickEntryPage extends BasePage {
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -207,19 +208,24 @@ public void onSubmit(){
itemdetails = itemdetails + " - " + MessageFormat.format(getString("quickentry.externally"),assignmentNow.getExternalAppName());
}
form.add(new Label("itemdetails", itemdetails));
final List<String> gradableUsers = this.businessService.getGradeableUsers();
List<QuickEntryRowModel> rows = new ArrayList<>();

// The getUsers call will both sort and remove orphaned/invalid users
final List<String> gradableUserIds = this.businessService.getGradeableUsers();
final List<User> gradableUsers = this.businessService.getUsers(gradableUserIds);
Map<String, List<String>> groupContainer = this.businessService.getGroupMemberships();

List<QuickEntryRowModel> rows = new ArrayList<>();

int totalstudents = 0;
int studentsnow = 0;
for(String uid: gradableUsers){
for (User userNow: gradableUsers) {
final String uid = userNow.getId();
QuickEntryRowModel rowNow = new QuickEntryRowModel();
totalstudents++;
if(!params.get("groupNow").isNull() && !groupContainer.get("/site/" + this.businessService.getCurrentSiteId() + "/group/"+params.get("groupNow").toString()).contains(uid)){
continue;
}
studentsnow++;
GbUser userNow = this.businessService.getUser(uid);
rowNow.setName(userNow.getLastName() + ", " + userNow.getFirstName() + " (" + userNow.getDisplayId() + ')');
String commentNow = this.businessService.getAssignmentGradeComment(this.assignmentNow.getId(),uid);
if(commentNow != null){
Expand All @@ -232,24 +238,14 @@ public void onSubmit(){
rowNow.setOriginalComment(null);
}
String gradeNow = this.businessService.getGradeForStudentForItem(uid,this.assignmentNow.getId()).getGrade();
if(StringUtils.isNotBlank(gradeNow)){
rowNow.setGrade(gradeNow);
} else {
rowNow.setGrade(null);
}
rowNow.setExcused(this.businessService.getAssignmentExcuse(this.assignmentNow.getId(),uid) != "0");
rowNow.setGrade(StringUtils.defaultIfBlank(gradeNow, null));
rowNow.setExcused(!Objects.equals(this.businessService.getAssignmentExcuse(this.assignmentNow.getId(), uid), "0"));
rowNow.setLocked(this.assignmentNow.getExternallyMaintained());
rowNow.setMaxGrade(this.assignmentNow.getPoints());
rowNow.setStudentid(uid);
rows.add(rowNow);
((QuickEntryPageModel)form.getModelObject()).getItemgrades().add(rowNow);
}
rows.sort(new Comparator<QuickEntryRowModel>() {
@Override
public int compare(QuickEntryRowModel quickEntryRowModel, QuickEntryRowModel t1) {
return quickEntryRowModel.getName().compareTo(t1.getName());
}
});
form.add(new Label("summarycount",MessageFormat.format(getString("quickentry.count"),studentsnow,totalstudents)));
ListView<QuickEntryRowModel> userFields = new ListView<QuickEntryRowModel>("studentRow",rows){
@Override
Expand Down

0 comments on commit 583446e

Please sign in to comment.