Skip to content

Commit

Permalink
LSNBLDR-725; allow setting grade to zero for missing student pages an…
Browse files Browse the repository at this point in the history
…d comments (sakaiproject#3878)
  • Loading branch information
clhedrick authored Feb 8, 2017
1 parent fec7d2e commit 25cfae2
Show file tree
Hide file tree
Showing 11 changed files with 348 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public String[] getResults() {
private boolean gradeComment() {
boolean r = false;


SimplePageComment comment = simplePageToolDao.findCommentByUUID(id);
SimplePageItem commentItem = simplePageToolDao.findItem(comment.getItemId());
SimpleStudentPage studentPage = null; // comments on student page only
Expand All @@ -96,6 +95,13 @@ private boolean gradeComment() {
if(commentItem.getPageId() <= 0) {
studentPage = simplePageToolDao.findStudentPage(Long.valueOf(commentItem.getSakaiId()));
topItem = simplePageToolDao.findItem(studentPage.getItemId());
if (! simplePageBean.itemOk(topItem.getId())) {
return false;
}
} else {
if (! simplePageBean.itemOk(commentItem.getId())) {
return false;
}
}

String gradebookId = null;
Expand Down Expand Up @@ -154,13 +160,18 @@ private boolean gradeStudentPage() {
SimpleStudentPage page = simplePageToolDao.findStudentPage(Long.valueOf(id));
SimplePageItem pageItem = simplePageToolDao.findItem(page.getItemId());
Double newpoints = Double.valueOf(points);

// the idea was to not update if there's no change in points
// but there can be reasons to want to force grades back to the gradebook,
// particually for group pages where the group may have changed
//if(Double.valueOf(points).equals(page.getPoints())) {
// return new String[] {"success", jsId, String.valueOf(page.getPoints())};
//}

if (page.getPageId() != simplePageBean.getCurrentPageId()) {
return false;
}

if (newpoints < 0.0 || newpoints > pageItem.getGradebookPoints()) {
return false;
}
Expand Down Expand Up @@ -199,6 +210,9 @@ private boolean gradeQuestion() {
SimplePageItem questionItem = simplePageBean.findItem(response.getQuestionId());
Double newpoints = Double.valueOf(points);

if (! simplePageBean.itemOk(questionItem.getId()))
return false;

r = "true".equals(questionItem.getAttribute("questionGraded")) || questionItem.getGradebookId() != null;
if (questionItem.getGradebookId() != null)
if (newpoints < 0.0 || newpoints > questionItem.getGradebookPoints()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ boolean update(Object i, boolean requiresEditPermission) {
// hacking on an item in a completely different site. This method checks
// that an item is OK to hack on, given the current page.

private boolean itemOk(Long itemId) {
public boolean itemOk(Long itemId) {
// not specified, we'll add a new one
if (itemId == null || itemId == -1)
return true;
Expand Down Expand Up @@ -2276,7 +2276,7 @@ public SimplePageToolDao.PageData toolWasReset() {
// Info. Site info knows nothing about us, so it will make an entry for the page without
// creating it. When the user then tries to go to the page, this code will be the firsst
// to notice it. Hence we have to create pages that don't exist
private long getCurrentPageId() {
public long getCurrentPageId() {
// return ((ToolConfiguration)toolManager.getCurrentPlacement()).getPageId();

if (currentPageId != null)
Expand Down Expand Up @@ -7531,7 +7531,145 @@ public String updateStudent() {
return "failure";
}
}


public String missingStudentSetZero() {
if (!checkCsrf())
return "permission-failed";
if(!canEditPage())
return "permission-failed";
if (!itemOk(itemId))
return "permission-failed";

SimplePageItem item = findItem(itemId);
String gradebookId = item.getGradebookId();
if(gradebookId == null) {
setErrMessage(messageLocator.getMessage("simplepage.not-graded"));
return "failure";
}

// initialize notsubmitted to all userids or groupids
Set<String> notSubmitted = new HashSet<String>();
if (item.isGroupOwned()) {
String ownerGroups = item.getOwnerGroups();
if (ownerGroups != null)
notSubmitted = new HashSet(Arrays.asList(ownerGroups.split(",")));
} else {
Set<Member> members = new HashSet<Member>();
try {
members = authzGroupService.getAuthzGroup(siteService.siteReference(getCurrentSiteId())).getMembers();
} catch (Exception e) {
// since site obviously exists, this should be impossible
}
for (Member m: members)
notSubmitted.add(m.getUserId());
}

// now go through all student pages and remove them from the list
List<SimpleStudentPage> studentPages = simplePageToolDao.findStudentPages(item.getId());
for(SimpleStudentPage page : studentPages) {
if(page.isDeleted()) continue;

// remove this from notSubmitted
if (item.isGroupOwned()) {
String pageGroup = page.getGroup();
if (pageGroup != null)
notSubmitted.remove(pageGroup);
} else {
notSubmitted.remove(page.getOwner());
}
}

// now zero the grades
for (String owner: notSubmitted) {
List<String> owners = null;
if (item.isGroupOwned()) {
owners = studentPageGroupMembers(item, owner);
} else {
owners = new ArrayList<String>();
owners.add(owner);
}
for (String userid: owners) {
gradebookIfc.updateExternalAssessmentScore(getCurrentSiteId(), gradebookId, userid, "0.0");
}
}

return "success";

}

public String missingCommentsSetZero() {
System.out.println("point 1");
if (!checkCsrf())
return "permission-failed";
if(!canEditPage())
return "permission-failed";
if (!itemOk(itemId))
return "permission-failed";
System.out.println("point 2 " + itemId);

SimplePageItem commentItem = findItem(itemId);
boolean studentComments = (commentItem.getType() == SimplePageItem.STUDENT_CONTENT);

String gradebookId;

if (studentComments) {
gradebookId = commentItem.getAltGradebook();
} else {
gradebookId = commentItem.getGradebookId();
}

if (gradebookId == null) {
setErrMessage(messageLocator.getMessage("simplepage.not-graded"));
return "failure";
}

// initialize notsubmitted to all userids or groupids
Set<String> notSubmitted = new HashSet<String>();
Set<Member> members = new HashSet<Member>();
try {
members = authzGroupService.getAuthzGroup(siteService.siteReference(getCurrentSiteId())).getMembers();
} catch (Exception e) {
// since site obviously exists, this should be impossible
}
for (Member m: members)
notSubmitted.add(m.getUserId());

// now go through all comments and remove them from the list
List<SimplePageComment> comments;

if(!studentComments) {
comments = simplePageToolDao.findComments(itemId);
}else {
List<SimpleStudentPage> studentPages = simplePageToolDao.findStudentPages(itemId);

List<Long> commentsItemIds = new ArrayList<Long>();
for(SimpleStudentPage p : studentPages) {
// If the page is deleted, don't show the comments
if(!p.isDeleted()) {
commentsItemIds.add(p.getCommentsSection());
}
}

comments = simplePageToolDao.findCommentsOnItems(commentsItemIds);
}

// have comments. look at owners
for(SimplePageComment comment : comments) {
if(comment.getComment() == null || comment.getComment().equals("")) {
continue;
}
notSubmitted.remove(comment.getAuthor());
}

// now zero grade
for (String owner: notSubmitted) {
gradebookIfc.updateExternalAssessmentScore(getCurrentSiteId(), gradebookId, owner, "0.0");
}

return "success";

}

private void regradeStudentPageComments(SimplePageItem pageItem) {
List<SimpleStudentPage> pages = simplePageToolDao.findStudentPages(pageItem.getId());
for(SimpleStudentPage c : pages) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.HashSet;

import org.sakaiproject.lessonbuildertool.SimplePage;
import org.sakaiproject.lessonbuildertool.SimplePageItem;
Expand All @@ -17,13 +19,17 @@
import org.sakaiproject.user.cover.UserDirectoryService;
import org.sakaiproject.tool.cover.ToolManager;
import org.sakaiproject.tool.cover.SessionManager;
import org.sakaiproject.authz.api.Member;
import org.sakaiproject.authz.api.AuthzGroupService;
import org.sakaiproject.site.api.SiteService;

import uk.org.ponder.messageutil.MessageLocator;
import uk.org.ponder.localeutil.LocaleGetter;
import uk.org.ponder.rsf.builtin.UVBProducer;
import uk.org.ponder.rsf.components.UIBranchContainer;
import uk.org.ponder.rsf.components.UIContainer;
import uk.org.ponder.rsf.components.UIForm;
import uk.org.ponder.rsf.components.UICommand;
import uk.org.ponder.rsf.components.UIInitBlock;
import uk.org.ponder.rsf.components.UIInput;
import uk.org.ponder.rsf.components.UIInternalLink;
Expand All @@ -42,7 +48,10 @@ public class CommentGradingPaneProducer implements ViewComponentProducer, ViewPa
private SimplePageBean simplePageBean;
private SimplePageToolDao simplePageToolDao;
private MessageLocator messageLocator;
public LocaleGetter localeGetter;
private AuthzGroupService authzGroupService;
private SiteService siteService;
public LocaleGetter localeGetter;


public String getViewID() {
return VIEW_ID;
Expand All @@ -56,6 +65,14 @@ public void setSimplePageToolDao(SimplePageToolDao simplePageToolDao) {
this.simplePageToolDao = simplePageToolDao;
}

public void setAuthzGroupService(AuthzGroupService a) {
this.authzGroupService = a;
}

public void setSiteService(SiteService s) {
this.siteService = s;
}

public void setMessageLocator(MessageLocator messageLocator) {
this.messageLocator = messageLocator;
}
Expand Down Expand Up @@ -90,7 +107,7 @@ public void fillComponents(UIContainer tofill, ViewParameters viewparams, Compon

UIInternalLink.make(tofill, "back-link", messageLocator.getMessage("simplepage.go-back"), backParams);

if(simplePageBean.getEditPrivs() != 0) {
if(simplePageBean.getEditPrivs() != 0 || !simplePageBean.itemOk(params.commentsItemId)) {
UIOutput.make(tofill, "permissionsError");
return;
}
Expand Down Expand Up @@ -130,13 +147,24 @@ public void fillComponents(UIContainer tofill, ViewParameters viewparams, Compon
ArrayList<String> userIds = new ArrayList<String>();
HashMap<String, SimpleUser> users = new HashMap<String, SimpleUser>();

// initialize notsubmitted to all userids or groupids
Set<String> notSubmitted = new HashSet<String>();
Set<Member> members = new HashSet<Member>();
try {
members = authzGroupService.getAuthzGroup(siteService.siteReference(simplePageBean.getCurrentSiteId())).getMembers();
} catch (Exception e) {
// since site obviously exists, this should be impossible
}
for (Member m: members)
notSubmitted.add(m.getUserId());

for(SimplePageComment comment : comments) {
if(comment.getComment() == null || comment.getComment().equals("")) {
continue;
}

if(!userIds.contains(comment.getAuthor())) {
userIds.add(comment.getAuthor());
notSubmitted.remove(comment.getAuthor());
try {
SimpleUser user = new SimpleUser();
user.displayName = UserDirectoryService.getUser(comment.getAuthor()).getDisplayName();
Expand All @@ -163,6 +191,24 @@ public void fillComponents(UIContainer tofill, ViewParameters viewparams, Compon
}
}

if (notSubmitted.size() > 0) {
List<String> missing = new ArrayList<String>();
for (String userId: notSubmitted) {
try {
missing.add(UserDirectoryService.getUser(userId).getDisplayName());
} catch (Exception e) {
missing.add(userId);
}
}
Collections.sort(missing);
UIOutput.make(tofill, "missing-head");
UIOutput.make(tofill, "missing-div");
for (String name: missing) {
UIBranchContainer branch = UIBranchContainer.make(tofill, "missing:");
UIOutput.make(branch, "missing-entry", name);
}
}

ArrayList<SimpleUser> simpleUsers = new ArrayList<SimpleUser>(users.values());
Collections.sort(simpleUsers);

Expand All @@ -183,6 +229,19 @@ public void fillComponents(UIContainer tofill, ViewParameters viewparams, Compon
decorate(new UIFreeAttributeDecorator("title",
messageLocator.getMessage("simplepage.update-points")));

if (notSubmitted.size() > 0)
UIOutput.make(tofill, "zeroMissing", messageLocator.getMessage("simplepage.zero-missing")).
decorate(new UIFreeAttributeDecorator("title",
messageLocator.getMessage("simplepage.zero-missing")));

Object sessionToken = SessionManager.getCurrentSession().getAttribute("sakai.csrf.token");

UIForm zeroForm = UIForm.make(tofill, "zero-form");
if (sessionToken != null)
UIInput.make(zeroForm, "zero-csrf", "simplePageBean.csrfToken", sessionToken.toString());
UIInput.make(zeroForm, "zero-item", "#{simplePageBean.itemId}", Long.toString(params.commentsItemId));
UICommand.make(zeroForm, "zero", messageLocator.getMessage("simplepage.zero-missing"), "#{simplePageBean.missingCommentsSetZero}");

for(SimpleUser user : simpleUsers) {
UIBranchContainer branch = UIBranchContainer.make(tofill, "student-row:");

Expand Down Expand Up @@ -241,7 +300,6 @@ public void fillComponents(UIContainer tofill, ViewParameters viewparams, Compon
UIInput jsIdInput = UIInput.make(gradingForm, "gradingForm-jsId", "gradingBean.jsId");
UIInput pointsInput = UIInput.make(gradingForm, "gradingForm-points", "gradingBean.points");
UIInput typeInput = UIInput.make(gradingForm, "gradingForm-type", "gradingBean.type");
Object sessionToken = SessionManager.getCurrentSession().getAttribute("sakai.csrf.token");
UIInput csrfInput = UIInput.make(gradingForm, "csrf", "gradingBean.csrfToken", (sessionToken == null ? "" : sessionToken.toString()));

UIInitBlock.make(tofill, "gradingForm-init", "initGradingForm", new Object[] {idInput, pointsInput, jsIdInput, typeInput, csrfInput, "gradingBean.results"});
Expand Down
Loading

0 comments on commit 25cfae2

Please sign in to comment.