Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update initialize endpoint and create assessments/feedback endpoint in ORA Staff Grader #33632

Merged

Conversation

BryanttV
Copy link
Contributor

@BryanttV BryanttV commented Oct 31, 2023

Description

This cover letter was based on this PR

For this PR we have the following goals:

  1. Create two new endpoints:
    • The /api/ora_staff_grader/assessments/feedback/from endpoint to list the assessment received for a specific submission of a learner.
    • The /api/ora_staff_grader/assessments/feedback/to endpoint to list the assessment given by a learner based on their submission ID.
  2. Update the /api/ora_staff_grader/initialize endpoint to add the fullname and email fields.

Note

This PR in the ORA Grading MFE will use these endpoints to display a more detailed table to the instructor.

Dependencies

Important

This upgrade will consist of two PRs: one for ORA and the other for edx-platform. This is because the main serializer of the service resides in the platform. To test it, you must fetch and set up the ORA version with the new handlers.

What changed?

1. New endpoints

/api/ora_staff_grader/assessments/feedback/from

This endpoint fetches assessment details for a given:

  • Submission UUID
  • ORA Location

/api/ora_staff_grader/assessments/feedback/to

This endpoint fetches assessment details for a given:

  • Submission UUID
  • ORA Location

Both endpoints return the scorer information and scoring details to fill the following Staff Grade MFE table:

image

The following is an example of the response from either of the two endpoints:

{
   "assessments": [
      {
         "assessment_id" : "8",
         "scorer_name" : "Nikola Tesla",
         "scorer_username" : "nikola",
         "scorer_email" : "[email protected]",
         "assesment_date" : "2024-02-15 15:29:55.374959+00:00",
         "assesment_scores" : [
            {
               "criterion_name" : "Ideas",
               "score_earned" : 3,
               "score_type" :" Fair"
            },
            {
               "criterion_name" :" Content",
               "score_earned" : 1,
               "score_type" :" Fair"
            }
         ],
         "problem_step" : "Peer",
         "feedback" : "Good Job"
      }
   ]
}

2. Updated endpoint

/api/ora_staff_grader/initialize

This is a pre-existing endpoint to which two extra fields are added (fullname, email) to fill the following table:

image

The following is an example of the response from this endpoint:

...
    "submissions" : {
        "619b8fb2-ebc0-49ed-9b35-4700efb28f66" : {
            "submissionUUID" : "619b8fb2-ebc0-49ed-9b35-4700efb28f66",
            "username" : "admin",
            "email" : "[email protected]",
            "fullname" : "Fernando Gonzalez",
            "teamName" : null,
            "dateSubmitted" : "2023-10-13 15:36:13.781179+00:00",
            "dateGraded" : "2023-10-17 20:26:07.146547+00:00",
            "gradedBy" : "admin",
            "gradeStatus" : "graded",
            "lockStatus" : "unlocked",
            "score" : {
                "pointsEarned" : 10,
                "pointsPossible" : 10
            }
        }
    },

Testing Instructions

To test this, you can use Postman:

  1. Get an auth token from /oauth2/access_token/ with the following x-www-form-urlencoded content type body:

    client_id: login-service-client-id
    client_secret: <your-client-secret>
    grant_type: password
    username: <your-username>
    password: <your-password>
    

    From the response, copy the access_token, which must be sent in the headers of the endpoints.

  2. Test the endpoints:

  • /api/ora_staff_grader/initialize
    • Query Params: oraLocation
  • /api/ora_staff_grader/assessments/feedback/from
    • Query Params: oraLocation, submissionUUID
  • /api/ora_staff_grader/assessments/feedback/to
    • Query Params: oraLocation, submissionUUID

NOTE: From the MFE ora-grading you can get the oraLocation from here:

image

And the submissionUUID from the response of the initialize endpoint here:

image

Make sure that the oraLocation value is encoded.

image

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Oct 31, 2023
@openedx-webhooks
Copy link

openedx-webhooks commented Oct 31, 2023

Thanks for the pull request, @BryanttV! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

@BryanttV BryanttV force-pushed the bav/staff-grader-table-endpoints branch from 6621aa7 to 25d2b74 Compare October 31, 2023 20:43
@BryanttV BryanttV marked this pull request as ready for review November 1, 2023 14:51
@BryanttV BryanttV force-pushed the bav/staff-grader-table-endpoints branch from 25d2b74 to d137652 Compare November 1, 2023 14:53
@mphilbrick211 mphilbrick211 added needs test run Author's first PR to this repository, awaiting test authorization from Axim and removed needs test run Author's first PR to this repository, awaiting test authorization from Axim labels Nov 1, 2023
@BryanttV BryanttV changed the title feat: ORA staff grader mfe endpoints upgraded feat: update initialize endpoint and create assessment/feedback endpoint in ORA Staff Grader Nov 7, 2023
@BryanttV BryanttV changed the title feat: update initialize endpoint and create assessment/feedback endpoint in ORA Staff Grader feat: update initialize endpoint and create assessments/feedback endpoint in ORA Staff Grader Nov 7, 2023
@BryanttV BryanttV force-pushed the bav/staff-grader-table-endpoints branch 2 times, most recently from 96d0f4d to ff88db5 Compare November 7, 2023 22:04
@BryanttV BryanttV force-pushed the bav/staff-grader-table-endpoints branch from 44188a0 to 4a641da Compare November 14, 2023 22:25
@mphilbrick211
Copy link

Hi @BryanttV! Is this ready for review?

@BryanttV
Copy link
Contributor Author

Hi @mphilbrick211!. Yes, it's ready for review

@mphilbrick211 mphilbrick211 added the waiting for eng review PR is ready for review. Review and merge it, or suggest changes. label Nov 20, 2023
@BryanttV BryanttV force-pushed the bav/staff-grader-table-endpoints branch from aae1092 to 09a10d1 Compare December 7, 2023 16:51
@BryanttV BryanttV force-pushed the bav/staff-grader-table-endpoints branch from 09a10d1 to f26c6f8 Compare January 26, 2024 17:11
@pomegranited pomegranited self-requested a review February 8, 2024 05:52
@BryanttV BryanttV force-pushed the bav/staff-grader-table-endpoints branch 2 times, most recently from 7e20bd3 to b5fc878 Compare February 15, 2024 15:08
@BryanttV BryanttV force-pushed the bav/staff-grader-table-endpoints branch 2 times, most recently from 5a3bb34 to 82ae819 Compare February 15, 2024 21:19
@BryanttV
Copy link
Contributor Author

Hi @mariajgrimaldi, I addressed your comments, can you check again? thanks!

@@ -147,6 +150,121 @@ def get(self, request, ora_location, *args, **kwargs):
return UnknownErrorResponse()


class AssessmentFeedbackToView(StaffGraderBaseView):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, it is possible to declare a single DRF view with multiple "GET" endpoints: https://stackoverflow.com/a/70301277

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @pomegranited, I didn't know that was possible, thanks for commenting! I have already made the necessary changes to use a single view. Could you check it again?

nandodev-net and others added 5 commits February 16, 2024 18:44
feat: generate_assessment_data handler created

fix: style and functions rename

fix: test submission metadata serializers upgraded

fix: style and some test and docs improvements

fix: HTTPStatus conditional

chore: update assessment_filter argument and update docstring

chore: fix quality errors

chore: remove inline comments and improve docstring of serializers

refactor: rename assessment_filter to assessment_type
@BryanttV BryanttV force-pushed the bav/staff-grader-table-endpoints branch from 6ef3209 to ecb3fe1 Compare February 16, 2024 23:45
Comment on lines +242 to +244
except Exception as ex:
log.exception(ex)
return UnknownErrorResponse()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BryanttV I'm hitting this general Exception clause when I try accessing these endpoints as a student. Traceback below; is there a better way to catch xblock handler permission errors?

edx.devstack.lms  | 2024-02-18 12:05:23,986 ERROR 983 [lms.djangoapps.ora_staff_grader.views] [user 6] [ip 172.19.0.1] views.py:243 - Expecting value: line 1 column 1 (char 0)
edx.devstack.lms  | Traceback (most recent call last):
edx.devstack.lms  |   File "/edx/app/edxapp/edx-platform/lms/djangoapps/ora_staff_grader/views.py", line 230, in _get_assessments
edx.devstack.lms  |     assessments_data = {"assessments": getter_func(request, ora_location, submission_uuid)}
edx.devstack.lms  |   File "/edx/app/edxapp/edx-platform/lms/djangoapps/ora_staff_grader/ora_api.py", line 63, in get_assessments_to
edx.devstack.lms  |     return json.loads(response.content)
edx.devstack.lms  |   File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
edx.devstack.lms  |     return _default_decoder.decode(s)
edx.devstack.lms  |   File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
edx.devstack.lms  |     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
edx.devstack.lms  |   File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
edx.devstack.lms  |     raise JSONDecodeError("Expecting value", s, err.value) from None
edx.devstack.lms  | json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
edx.devstack.lms  | Internal Server Error: /api/ora_staff_grader/assessments/feedback/to/
edx.devstack.lms  | 2024-02-18 12:05:24,056 ERROR 983 [django.request] [user None] [ip None] log.py:241 - Internal Server Error: /api/ora_staff_grader/assessments/feedback/to/
edx.devstack.lms  | [18/Feb/2024 12:05:24] "GET /api/ora_staff_grader/assessments/feedback/to/?oraLocation=block-v1%3AedX%2BDemoX%2BDemo_Course%2Btype%40openassessment%2Bblock%40bce6c7ff830a473f9971204964424221&submissionUUID=90fe5b5b-03fa-4371-af26-2ee49939483f HTTP/1.1" 500 19098

Copy link
Contributor Author

@BryanttV BryanttV Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @pomegranited, I was doing some research and found the following:

  • Currently, this is how the other ORA Staff Grader endpoints behave.

  • The error is generated from the following line. When there is a permissions error from ORA the following is returned in the response.content:

    b'<div>You do not have permission to access ORA staff grading.</div>\n

    When trying to parse this string to a dict using json.loads() it breaks 💥

I think that this permission error should be raised by the XBlockInternalError, but since the status_code of the response always returns a 200, the error would never be raised, even though it exists. In my opinion, if there is any type of error from the handler, the most appropriate thing to do is to return the corresponding 4xx code.

Copy link
Member

@mariajgrimaldi mariajgrimaldi Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that also happens with the existing initialize endpoint. The views don't check for permissions, but it waits for the ORA handlers to return:

> response.content
b'<div>You do not have permission to access ORA staff grading.</div>\n'.  

So maybe it'd be enough to return this error, but avoiding the unknown error by wrapping json.loads(response.content) in a try-except block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By doing this change:

try:
    return json.loads(response.content)
except json.JSONDecodeError as exc:
    raise XBlockInternalError(
        context={"handler": handler_name, "details": response.content}
    ) from exc

The response looks like this:

{
	"error": "ERR_INTERNAL",
	"handler": "list_assessments_to",
	"details": "<div>You do not have permission to access ORA staff grading.</div>\n"
}

And the log looks like this:

tutor_dev-lms-1  | 2024-02-20 17:49:21,564 ERROR 31 [lms.djangoapps.ora_staff_grader.views] [user 6] [ip 172.18.0.1] views.py:243 - {'handler': 'list_assessments_to', 'details': b'<div>You do not have permission to access ORA staff grading.</div>\n'}
tutor_dev-lms-1  | Internal Server Error: /api/ora_staff_grader/assessments/feedback/to/
tutor_dev-lms-1  | 2024-02-20 17:49:21,668 ERROR 31 [django.request] [user None] [ip None] log.py:241 - Internal Server Error: /api/ora_staff_grader/assessments/feedback/to/
tutor_dev-lms-1  | [20/Feb/2024 17:49:21] "GET /api/ora_staff_grader/assessments/feedback/to/?oraLocation=block-v1%3Aedunext%2BDemo%2BORA%2Btype%40openassessment%2Bblock%4075685668559f451dabd6ebe6375ad080&submissionUUID=29872ddb-4dfd-4f17-b4bb-459ce1167fcc HTTP/1.1" 500 137

A Django response object containing serialized assessment data or an error response.
"""
try:
assessments_data = {"assessments": getter_func(request, ora_location, submission_uuid)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only difference between get_assessments_from and get_assessments_to now is the handler_name.. you could consolidate them and pass the handler instead of a Callable to this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right! I'll make the changes

@BryanttV
Copy link
Contributor Author

Hi @mariajgrimaldi, @pomegranited. All the requested changes are in place. Could you please check again? Thank you very much!

Copy link
Member

@mariajgrimaldi mariajgrimaldi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is working as expected. Thank you!

If @pomegranited agrees, we can merge this one. Thank you folks!

Copy link
Contributor

@pomegranited pomegranited left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you @BryanttV @mariajgrimaldi !

@mariajgrimaldi mariajgrimaldi merged commit 20570ff into openedx:master Feb 22, 2024
46 checks passed
@openedx-webhooks
Copy link

@BryanttV 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U waiting for eng review PR is ready for review. Review and merge it, or suggest changes.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

7 participants