OpenTree-Education / rhizone-lms

A learning management system focused on self-reflection.
https://rhi.zone
BSD 3-Clause Clear License
14 stars 7 forks source link

Implement functionality for the PUT /assessments/submissions/:submissionId route and accompanying service file functions #564

Closed ZeyuanLi16 closed 1 year ago

ZeyuanLi16 commented 1 year ago

Describe the Feature / Enhancement

The PUT /submissions/:submissionId route needs to be implemented and fully tested. The PUT /submissions/:submissionId updates details for a specific assessment submission (for facilitator, scores and grading comments; for participant, responses and metadata if not expired).

There needs to be a test coverage for the PUT /submissions/:submissionId route and the service file functions it needs. We need to test this route to ensure the code written for the test will behave as expected by the protocol we previously defined.

This issue continues the work from issue #515.

Additional Details and Resources

This route requires the principal ID (the user ID) from the session information, this route expects an assessment submission ID in the URL as a URL parameter, and expects an AssessmentSubmission in the request body, including all AssessmentResponses, which may or may not be individually updated. The response should contain the following:

Facilitator

The facilitator is always allowed to update an AssessmentSubmission and its responses to insert scores and grading comments.

res.json(itemEnvelope(the updated AssessmentSubmission));

Participant

If the AssessmentSubmission is in the "Opened" or "In Progress" states and the due date for this program assessment has not passed, return the following after having set the state to "In Progress" and updating the submission and responses (disallowing them to update their scores or graderResponse in the update to the submission or its responses):

res.json(itemEnvelope(the updated AssessmentSubmission));

If the AssessmentSubmission is in the "Opened" or "In Progress" states and the due date for this program assessment has passed, set the state to "Expired" and send them a ForbiddenError.

If the AssessmentSubmission is in a state besides "Opened" or "In Progress", send them a ForbiddenError.

export class ForbiddenError extends HttpError {}
ForbiddenError.prototype.message = 'Access to this resource is not allowed.';
ForbiddenError.prototype.status = 403;
else if (new Date() > due_date) {
  throw new ForbiddenError(`You may not create a new assessment submission because the due date has passed.`);
} else if (numSubmissions > max_num_submissions) {
  throw new ForbiddenError(`You have reached the maximum number of submissions for this assessment.`);
} else {
  throw new ForbiddenError();
}

Correct Project Selected

Labels

ZeyuanLi16 commented 1 year ago

Update: I pushed some initial logic for route and service functions. The route has not been finished but I want some input from @seidior .

seidior commented 1 year ago

There are state and due date check in BOTH route and service function, for example if it is in progress and past due date, set state to expired. I think this is valid since we need to have a safe guard in service function too in case other route call it.

Agreed!

I am thinking we need to calculate score some where between route or service function.

Assume we're given the correct score. As long as it's a facilitator submitting any grading-related information, assume they know what's best and don't worry about the checks.