diff --git a/platform_plugin_turnitin/extensions/filters.py b/platform_plugin_turnitin/extensions/filters.py index 2ac09a3..5614647 100644 --- a/platform_plugin_turnitin/extensions/filters.py +++ b/platform_plugin_turnitin/extensions/filters.py @@ -1,10 +1,9 @@ """Filters for the Turnitin plugin.""" from django.conf import settings -from opaque_keys.edx.keys import UsageKey from openedx_filters import PipelineStep -from platform_plugin_turnitin.edxapp_wrapper.modulestore import modulestore +from platform_plugin_turnitin.utils import enabled_in_course class ORASubmissionViewTurnitinWarning(PipelineStep): @@ -15,6 +14,9 @@ def run_filter(self, context: dict, template_name: str) -> dict: # pylint: disa Execute filter that loads the submission template with a warning message that notifies the user that the submission will be sent to Turnitin. + If the Turnitin feature is not enabled globally or in the course, the original + template is returned. + Args: context (dict): The context dictionary. template_name (str): ORA template name. @@ -22,17 +24,7 @@ def run_filter(self, context: dict, template_name: str) -> dict: # pylint: disa Returns: dict: The context dictionary and the template name. """ - if settings.ENABLE_TURNITIN_SUBMISSION: - return { - "context": context, - "template_name": "turnitin/oa_response.html", - } - - course_key = UsageKey.from_string(context["xblock_id"]).course_key - course_block = modulestore().get_course(course_key) - enable_in_course = course_block.other_course_settings.get("ENABLE_TURNITIN_SUBMISSION", False) - - if enable_in_course: + if settings.ENABLE_TURNITIN_SUBMISSION or enabled_in_course(context["xblock_id"]): return { "context": context, "template_name": "turnitin/oa_response.html", diff --git a/platform_plugin_turnitin/handlers.py b/platform_plugin_turnitin/handlers.py index 1aa23a9..edc01f1 100644 --- a/platform_plugin_turnitin/handlers.py +++ b/platform_plugin_turnitin/handlers.py @@ -1,42 +1,26 @@ """Event handlers for the Turnitin plugin.""" from django.conf import settings -from opaque_keys.edx.keys import UsageKey -from platform_plugin_turnitin.edxapp_wrapper.modulestore import modulestore from platform_plugin_turnitin.tasks import ora_submission_created_task +from platform_plugin_turnitin.utils import enabled_in_course def ora_submission_created(submission, **kwargs): """ Handle the ORA_SUBMISSION_CREATED event. - Args: - submission (ORASubmissionData): The ORA submission data. - """ - if settings.ENABLE_TURNITIN_SUBMISSION: - call_ora_submission_created_task(submission) - return - - course_key = UsageKey.from_string(submission.location).course_key - course_block = modulestore().get_course(course_key) - enable_in_course = course_block.other_course_settings.get("ENABLE_TURNITIN_SUBMISSION", False) - - if enable_in_course: - call_ora_submission_created_task(submission) - - -def call_ora_submission_created_task(submission) -> None: - """ - Call the ORA submission created task. + If the Turnitin feature is enabled globally or in the course, create a new task to + send the ORA submission data to Turnitin. Args: submission (ORASubmissionData): The ORA submission data. """ - ora_submission_created_task.delay( - submission.uuid, - submission.anonymous_user_id, - submission.answer.parts, - submission.answer.file_names, - submission.answer.file_urls, - ) + if settings.ENABLE_TURNITIN_SUBMISSION or enabled_in_course(submission.location): + ora_submission_created_task.delay( + submission.uuid, + submission.anonymous_user_id, + submission.answer.parts, + submission.answer.file_names, + submission.answer.file_urls, + ) diff --git a/platform_plugin_turnitin/utils.py b/platform_plugin_turnitin/utils.py index c502942..7235a4a 100644 --- a/platform_plugin_turnitin/utils.py +++ b/platform_plugin_turnitin/utils.py @@ -2,6 +2,10 @@ from datetime import datetime +from opaque_keys.edx.keys import UsageKey + +from platform_plugin_turnitin.edxapp_wrapper.modulestore import modulestore + def get_current_datetime() -> str: """ @@ -15,3 +19,18 @@ def get_current_datetime() -> str: str: The current datetime in ISO 8601 format. """ return datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ") + + +def enabled_in_course(block_id: str) -> bool: + """ + Check if Turnitin feature is enabled in the course. + + Args: + block_id (str): The block ID. + + Returns: + bool: True if Turnitin feature is enabled in the course, False otherwise. + """ + course_key = UsageKey.from_string(block_id).course_key + course_block = modulestore().get_course(course_key) + return course_block.other_course_settings.get("ENABLE_TURNITIN_SUBMISSION", False)