Skip to content

Commit

Permalink
feat: added ORA graded by staff notification
Browse files Browse the repository at this point in the history
  • Loading branch information
eemaanamir committed Aug 28, 2024
1 parent ea596d6 commit 51ddba0
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 3 deletions.
64 changes: 64 additions & 0 deletions lms/djangoapps/ora_staff_grader/notifications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""
This module contains utility functions for sending notifications.
"""
import logging

from opaque_keys.edx.keys import UsageKey
from opaque_keys import InvalidKeyError


from openedx_events.learning.data import UserNotificationData
from openedx_events.learning.signals import USER_NOTIFICATION_REQUESTED
from openedx.core.djangoapps.content.course_overviews.api import (
get_course_overview_or_none,
)
from lms.djangoapps.ora_staff_grader.errors import (
XBlockInternalError,
)
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.exceptions import ItemNotFoundError
from django.contrib.auth import get_user_model
from django.conf import settings

log = logging.getLogger(__name__)
User = get_user_model()


def send_staff_grade_assigned_notification(request, usage_id, submission_uuid, submissions):
"""
Send a user notification for a course for a new grade being assigned
"""
try:
ora_user = User.objects.get(email=submissions[submission_uuid]['email'])
# Do not send the notification if the request user is the same as the ora submitter
if request.user != ora_user:
# Get ORA block
ora_usage_key = UsageKey.from_string(usage_id)
ora_metadata = modulestore().get_item(ora_usage_key)
# Get course metadata
course_id = str(ora_usage_key.course_key)
course_metadata = get_course_overview_or_none(course_id)
notification_data = UserNotificationData(
user_ids=[ora_user.id],
context={
'ora_name': ora_metadata.display_name,
'course_name': course_metadata.display_name,
},
notification_type="ora_staff_grade_assigned",
content_url=f"{settings.LMS_ROOT_URL}/courses/{str(course_id)}/jump_to/{str(ora_usage_key)}",
app_name="grading",
course_key=course_id,
)
USER_NOTIFICATION_REQUESTED.send_event(notification_data=notification_data)

# Catch bad ORA location
except (InvalidKeyError, ItemNotFoundError):
log.error(f"Bad ORA location provided: {usage_id}")

# Issues with the XBlock handlers
except XBlockInternalError as ex:
log.error(ex)

# Blanket exception handling in case something blows up
except Exception as ex:
log.exception(ex)
7 changes: 6 additions & 1 deletion lms/djangoapps/ora_staff_grader/ora_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
)

from lms.djangoapps.ora_staff_grader.utils import call_xblock_json_handler, is_json
from .notifications import send_staff_grade_assigned_notification


def get_submissions(request, usage_id):
Expand Down Expand Up @@ -116,7 +117,7 @@ def get_assessment_info(request, usage_id, submission_uuid):
return json.loads(response.content)


def submit_grade(request, usage_id, grade_data):
def submit_grade(request, usage_id, grade_data, submission_uuid):
"""
Submit a grade for an assessment.
Expand All @@ -137,6 +138,10 @@ def submit_grade(request, usage_id, grade_data):
context={"handler": handler_name, "msg": response_data.get("msg", "")}
)

if response_data.get("success", False):
submissions = get_submissions(request, usage_id)
send_staff_grade_assigned_notification(request, usage_id, submission_uuid, submissions)

return response_data


Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/ora_staff_grader/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def post(self, request, ora_location, submission_uuid, *args, **kwargs):
# Transform grade data and submit assessment, raises on failure
context = {"submission_uuid": submission_uuid}
grade_data = StaffAssessSerializer(request.data, context=context).data
submit_grade(request, ora_location, grade_data)
submit_grade(request, ora_location, grade_data, submission_uuid)

# Clear the lock on the graded submission
delete_submission_lock(request, ora_location, submission_uuid)
Expand Down
18 changes: 18 additions & 0 deletions openedx/core/djangoapps/notifications/base_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,24 @@
'filters': [FILTER_AUDIT_EXPIRED_USERS_WITH_NO_ROLE],
'visible_to': [CourseStaffRole.ROLE, CourseInstructorRole.ROLE]
},
'ora_staff_grade_assigned': {
'notification_app': 'grading',
'name': 'ora_staff_grade_assigned',
'is_core': False,
'info': '',
'web': False,
'email': False,
'push': False,
'email_cadence': EmailCadence.DAILY,
'non_editable': [],
'content_template': _('<{p}>You have received a grade for open response assessment '
'<{strong}>{ora_name}</{strong}></{p}>'),
'content_context': {
'ora_name': 'Name of ORA in course',
},
'email_template': '',
'filters': [FILTER_AUDIT_EXPIRED_USERS_WITH_NO_ROLE],
},
}

COURSE_NOTIFICATION_APPS = {
Expand Down
2 changes: 1 addition & 1 deletion openedx/core/djangoapps/notifications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
ADDITIONAL_NOTIFICATION_CHANNEL_SETTINGS = ['email_cadence']

# Update this version when there is a change to any course specific notification type or app.
COURSE_NOTIFICATION_CONFIG_VERSION = 11
COURSE_NOTIFICATION_CONFIG_VERSION = 12


def get_course_notification_preference_config():
Expand Down

0 comments on commit 51ddba0

Please sign in to comment.