Skip to content

Commit

Permalink
SAK-42282 Items with brackets in the title cannot be sent to Gradebook (
Browse files Browse the repository at this point in the history
  • Loading branch information
josecebe authored Mar 19, 2020
1 parent e8e78c1 commit da77cb1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
3 changes: 2 additions & 1 deletion assignment/api/src/resources/assignment.properties
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,9 @@ gen.remove.q = Remove?

addtogradebook = Add to Gradebook
addtogradebook.wrongGradeScale = Gradebook integration is only available when Grade Scale is set to Points.
addtogradebook.nonUniqueTitle = The assignment {0} has been created but has not been associated with a new Gradebook item due to an existing item of the same name or the name starting with reserved characters (* and #). Please edit the assignment title.
addtogradebook.nonUniqueTitle = The assignment {0} has been created but has not been associated with a new Gradebook item due to an existing item of the same name. Please edit the assignment title.
addtogradebook.illegalPoints = The assignment could not be added to Gradebook. To add to Gradebook, edit the assignment and enter a value greater than zero for points.
addtogradebook.titleInvalidCharacters = The assignment {0} has been created but has not been associated with a new Gradebook item due to assignment name contain invalid characters for a Gradebook item: '*', '[', ']' or start with a '#'. Please edit the assignment title.
addtogradebook.alertMessage = Exception while getting site gradebook, exception below:
addtogradebook.previouslyAssoc = You are trying to associate this assignment with an already associated Gradebook item and scores might be overwritten. Do you want to continue?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5641,7 +5641,7 @@ public void doSave_toggle_remove_review(RunData data) {
if (assignmentRef != null) {
String associateGradebookAssignment = a.getProperties().get(PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT);
// update grade in gradebook
assignmentToolUtils.integrateGradebook(stateToMap(state), assignmentRef, associateGradebookAssignment, null, null, null, -1, null, submissionId, "update", -1);
addAlerts(state, assignmentToolUtils.integrateGradebook(stateToMap(state), assignmentRef, associateGradebookAssignment, null, null, null, -1, null, submissionId, "update", -1));
}
}
}
Expand Down Expand Up @@ -8024,15 +8024,15 @@ private void initIntegrateWithGradebook(SessionState state, String siteId, Strin

if (!"remove".equals(addUpdateRemoveAssignment) && gradeType == SCORE_GRADE_TYPE) {
try {
assignmentToolUtils.integrateGradebook(stateToMap(state), assignmentReference, associateGradebookAssignment, addUpdateRemoveAssignment, aOldTitle, title, Integer.parseInt(gradePoints), dueTime, null, null, category);
addAlerts(state, assignmentToolUtils.integrateGradebook(stateToMap(state), assignmentReference, associateGradebookAssignment, addUpdateRemoveAssignment, aOldTitle, title, Integer.parseInt(gradePoints), dueTime, null, null, category));

// add all existing grades, if any, into Gradebook
assignmentToolUtils.integrateGradebook(stateToMap(state), assignmentReference, associateGradebookAssignment, null, null, null, -1, null, null, "update", category);
addAlerts(state, assignmentToolUtils.integrateGradebook(stateToMap(state), assignmentReference, associateGradebookAssignment, null, null, null, -1, null, null, "update", category));

// if the assignment has been assoicated with a different entry in gradebook before, remove those grades from the entry in Gradebook
if (StringUtils.trimToNull(oAssociateGradebookAssignment) != null && !oAssociateGradebookAssignment.equals(associateGradebookAssignment)) {
// remove all previously associated grades, if any, into Gradebook
assignmentToolUtils.integrateGradebook(stateToMap(state), assignmentReference, oAssociateGradebookAssignment, null, null, null, -1, null, null, "remove", category);
addAlerts(state, assignmentToolUtils.integrateGradebook(stateToMap(state), assignmentReference, oAssociateGradebookAssignment, null, null, null, -1, null, null, "remove", category));

// if the old assoicated assignment entry in GB is an external one, but doesn't have anything assoicated with it in Assignment tool, remove it
removeNonAssociatedExternalGradebookEntry(context, assignmentReference, oAssociateGradebookAssignment, gradebookUid);
Expand All @@ -8042,11 +8042,11 @@ private void initIntegrateWithGradebook(SessionState state, String siteId, Strin
log.warn(this + ":initIntegrateWithGradebook " + nE.getMessage());
}
} else {
assignmentToolUtils.integrateGradebook(stateToMap(state), assignmentReference, associateGradebookAssignment, "remove", null, null, -1, null, null, null, category);
addAlerts(state, assignmentToolUtils.integrateGradebook(stateToMap(state), assignmentReference, associateGradebookAssignment, "remove", null, null, -1, null, null, null, category));
}
} else {
// remove all previously associated grades, if any, into Gradebook
assignmentToolUtils.integrateGradebook(stateToMap(state), assignmentReference, oAssociateGradebookAssignment, null, null, null, -1, null, null, "remove", category);
addAlerts(state, assignmentToolUtils.integrateGradebook(stateToMap(state), assignmentReference, oAssociateGradebookAssignment, null, null, null, -1, null, null, "remove", category));

// need to remove the associated gradebook entry if 1) it is external and 2) no other assignment are associated with it
removeNonAssociatedExternalGradebookEntry(context, assignmentReference, oAssociateGradebookAssignment, gradebookUid);
Expand Down Expand Up @@ -9403,7 +9403,7 @@ public void doDelete_assignment(RunData data) {
rubricsService.softDeleteRubricAssociation(RubricsConstants.RBCS_TOOL_ASSIGNMENT, id);

// remove from Gradebook
assignmentToolUtils.integrateGradebook(stateToMap(state), ref, associateGradebookAssignment, "remove", null, null, -1, null, null, null, -1);
addAlerts(state, assignmentToolUtils.integrateGradebook(stateToMap(state), ref, associateGradebookAssignment, "remove", null, null, -1, null, null, null, -1));

// we use to check "assignment.delete.cascade.submission" setting. But the implementation now is always remove submission objects when the assignment is removed.
// delete assignment and its submissions altogether
Expand Down Expand Up @@ -9729,7 +9729,7 @@ public void doRelease_grades(RunData data) {
// integrate with Gradebook
String associateGradebookAssignment = a.getProperties().get(PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT);

assignmentToolUtils.integrateGradebook(stateToMap(state), aReference, associateGradebookAssignment, null, null, null, -1, null, null, "update", -1);
addAlerts(state, assignmentToolUtils.integrateGradebook(stateToMap(state), aReference, associateGradebookAssignment, null, null, null, -1, null, null, "update", -1));
}
}
}
Expand Down Expand Up @@ -10483,7 +10483,7 @@ public boolean saveReviewGradeForm(RunData data, SessionState state, String grad
String aReference = AssignmentReferenceReckoner.reckoner().assignment(a).reckon().getReference();
String associateGradebookAssignment = a.getProperties().get(PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT);
// update grade in gradebook
assignmentToolUtils.integrateGradebook(stateToMap(state), aReference, associateGradebookAssignment, null, null, null, -1, null, submissionId, "update", -1);
addAlerts(state, assignmentToolUtils.integrateGradebook(stateToMap(state), aReference, associateGradebookAssignment, null, null, null, -1, null, submissionId, "update", -1));
}
}
}
Expand Down Expand Up @@ -13117,7 +13117,7 @@ private void uploadAll_updateSubmissions(SessionState state,
if (releaseGrades && graded) {
// update grade in gradebook
if (associateGradebookAssignment != null) {
assignmentToolUtils.integrateGradebook(stateToMap(state), aReference, associateGradebookAssignment, null, null, null, -1, null, sReference, "update", -1);
addAlerts(state, assignmentToolUtils.integrateGradebook(stateToMap(state), aReference, associateGradebookAssignment, null, null, null, -1, null, sReference, "update", -1));
}
}
} catch (PermissionException e) {
Expand All @@ -13127,6 +13127,12 @@ private void uploadAll_updateSubmissions(SessionState state,
}
}
}

private void addAlerts(SessionState state, List<String> alerts) {
for (String alert : alerts) {
addAlert(state, alert);
}
}

/**
* This is to get the submission or feedback attachment from the upload zip file into the submission object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.sakaiproject.service.gradebook.shared.GradebookExternalAssessmentService;
import org.sakaiproject.service.gradebook.shared.GradebookFrameworkService;
import org.sakaiproject.service.gradebook.shared.GradebookService;
import org.sakaiproject.service.gradebook.shared.InvalidGradeItemNameException;
import org.sakaiproject.tool.api.ToolManager;
import org.sakaiproject.user.api.UserDirectoryService;
import org.sakaiproject.util.ResourceLoader;
Expand Down Expand Up @@ -534,6 +535,10 @@ public List<String> integrateGradebook(Map<String, Object> options, String assig
// add alert prompting for change assignment title
alerts.add(rb.getFormattedMessage("addtogradebook.nonUniqueTitle", "\"" + newAssignment_title + "\""));
log.warn(this + ":integrateGradebook " + e.getMessage());
} catch (InvalidGradeItemNameException e) {
// add alert prompting for invalid assignment title name
alerts.add(rb.getFormattedMessage("addtogradebook.titleInvalidCharacters", "\"" + newAssignment_title + "\""));
log.warn(this + ":integrateGradebook " + e.getMessage());
} catch (Exception e) {
log.warn(this + ":integrateGradebook " + e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ append_copy_title=- Copy #

# gradebook can not accept an assessment if its totalpoint = 0,
gradebook_exception_min_points=Warning: A Gradebook item could not be created for this assessment because Gradebook requires that the total points for this assessment must be > 0. Please change the Gradebook Options in the Settings to 'None" and republish again. Please contact your local help desk for more assistance.
gradebook_exception_title_invalid=Warning: A Gradebook item could not be created for this assessment because assessment name contain invalid characters for a Gradebook item: '*', '[', ']' or start with a '#'. Please change the assessment name and republish again.

# Title of links: starts with t_
t_addPart=Add Part
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.sakaiproject.samigo.util.SamigoConstants;
import org.sakaiproject.service.gradebook.shared.AssignmentHasIllegalPointsException;
import org.sakaiproject.service.gradebook.shared.GradebookExternalAssessmentService;
import org.sakaiproject.service.gradebook.shared.InvalidGradeItemNameException;
import org.sakaiproject.tool.assessment.data.dao.assessment.PublishedItemData;
import org.sakaiproject.tool.assessment.data.dao.assessment.PublishedSectionData;
import org.sakaiproject.tool.assessment.facade.ExtendedTimeFacade;
Expand Down Expand Up @@ -285,6 +286,12 @@ private void publish(AssessmentFacade assessment,
"gradebook_exception_min_points");
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(err));
throw new AbortProcessingException(gbe);
} catch (InvalidGradeItemNameException gbe) {
log.warn(gbe.getMessage(), gbe);
String err=(String)ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.AuthorMessages",
"gradebook_exception_title_invalid");
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(err));
throw new AbortProcessingException(gbe);
} catch (Exception e) {
log.warn(e.getMessage(), e);
// Add a global message (not bound to any component) to the faces context indicating the failure
Expand Down

0 comments on commit da77cb1

Please sign in to comment.