Commit d7ccb0ef by Christina Roberts

Merge pull request #844 from edx/christina/bad_user

Be robust to username not being available.
parents 2b254f7b e03e0150
...@@ -25,9 +25,15 @@ ...@@ -25,9 +25,15 @@
<div class="message__content"> <div class="message__content">
<p> <p>
{% blocktrans with removed_datetime=workflow_cancellation.cancelled_at|utc|date:"N j, Y H:i e" removed_by_username=workflow_cancellation.cancelled_by %} {% if workflow_cancellation.cancelled_by %}
Your submission has been cancelled by {{ removed_by_username }} on {{ removed_datetime }} {% blocktrans with removed_datetime=workflow_cancellation.cancelled_at|utc|date:"N j, Y H:i e" removed_by_username=workflow_cancellation.cancelled_by %}
{% endblocktrans %} Your submission has been cancelled by {{ removed_by_username }} on {{ removed_datetime }}
{% endblocktrans %}
{% else %}
{% blocktrans with removed_datetime=workflow_cancellation.cancelled_at|utc|date:"N j, Y H:i e" %}
Your submission was cancelled on {{ removed_datetime }}
{% endblocktrans %}
{% endif %}
</p> </p>
<p> <p>
<!-- Comments: Reason for Cancellation--> <!-- Comments: Reason for Cancellation-->
......
...@@ -12,9 +12,13 @@ ...@@ -12,9 +12,13 @@
<div class="staff-assessment__display"> <div class="staff-assessment__display">
<header class="staff-assessment__display__header"> <header class="staff-assessment__display__header">
<h4 class="staff-assessment__display__title"> <h4 class="staff-assessment__display__title">
{% blocktrans %} {% if student_username %}
Response for: {{ student_username }} {% blocktrans %}
{% endblocktrans %} Response for: {{ student_username }}
{% endblocktrans %}
{% else %}
{% trans "Learner Response" %}
{% endif %}
</h4> </h4>
</header> </header>
......
...@@ -11,9 +11,13 @@ ...@@ -11,9 +11,13 @@
<div class="staff-assessment__display"> <div class="staff-assessment__display">
<header class="staff-assessment__display__header"> <header class="staff-assessment__display__header">
<h3 class="staff-assessment__display__title"> <h3 class="staff-assessment__display__title">
{% blocktrans %} {% if student_username %}
Response for: {{ student_username }} {% blocktrans %}
{% endblocktrans %} Response for: {{ student_username }}
{% endblocktrans %}
{% else %}
{% trans "Learner Response" %}
{% endif %}
</h3> </h3>
</header> </header>
......
...@@ -21,9 +21,15 @@ ...@@ -21,9 +21,15 @@
<div class="ui-toggle-visibility__content"> <div class="ui-toggle-visibility__content">
{% if workflow_cancellation %} {% if workflow_cancellation %}
<p> <p>
{% blocktrans with removed_by_username=workflow_cancellation.cancelled_by removed_datetime=workflow_cancellation.cancelled_at|utc|date:"F j, Y H:i e" %} {% if workflow_cancellation.cancelled_by %}
Learner submission removed by {{ removed_by_username }} on {{ removed_datetime }} {% blocktrans with removed_by_username=workflow_cancellation.cancelled_by removed_datetime=workflow_cancellation.cancelled_at|utc|date:"F j, Y H:i e" %}
{% endblocktrans %} Learner submission removed by {{ removed_by_username }} on {{ removed_datetime }}
{% endblocktrans %}
{% else %}
{% blocktrans with removed_datetime=workflow_cancellation.cancelled_at|utc|date:"F j, Y H:i e" %}
Learner submission removed on {{ removed_datetime }}
{% endblocktrans %}
{% endif %}
</p> </p>
<!-- Comments: Reason for Cancellation--> <!-- Comments: Reason for Cancellation-->
<p> <p>
......
...@@ -953,8 +953,24 @@ class OpenAssessmentBlock( ...@@ -953,8 +953,24 @@ class OpenAssessmentBlock(
return unicode(key) return unicode(key)
def get_username(self, anonymous_user_id): def get_username(self, anonymous_user_id):
"""
Return the username of the user associated with anonymous_user_id
Args:
anonymous_user_id (str): the anonymous user id of the user
Returns: the username if it can be identified. If the xblock service to converts to a real user
fails, returns None and logs the error.
"""
if hasattr(self, "xmodule_runtime"): if hasattr(self, "xmodule_runtime"):
return self.xmodule_runtime.get_real_user(anonymous_user_id).username user = self.xmodule_runtime.get_real_user(anonymous_user_id)
if user:
return user.username
else:
logger.exception(
"XBlock service could not find user for anonymous_user_id '{}'".format(anonymous_user_id)
)
return None
def _adjust_start_date_for_beta_testers(self, start): def _adjust_start_date_for_beta_testers(self, start):
if hasattr(self, "xmodule_runtime"): if hasattr(self, "xmodule_runtime"):
......
...@@ -8,7 +8,6 @@ from mock import Mock, patch, MagicMock, PropertyMock ...@@ -8,7 +8,6 @@ from mock import Mock, patch, MagicMock, PropertyMock
from openassessment.xblock import openassessmentblock from openassessment.xblock import openassessmentblock
from openassessment.xblock.resolve_dates import DISTANT_PAST, DISTANT_FUTURE from openassessment.xblock.resolve_dates import DISTANT_PAST, DISTANT_FUTURE
from openassessment.workflow import api as workflow_api
from openassessment.workflow.errors import AssessmentWorkflowError from openassessment.workflow.errors import AssessmentWorkflowError
from .base import XBlockHandlerTestCase, scenario from .base import XBlockHandlerTestCase, scenario
...@@ -659,3 +658,20 @@ class TestDates(XBlockHandlerTestCase): ...@@ -659,3 +658,20 @@ class TestDates(XBlockHandlerTestCase):
if released is not None: if released is not None:
self.assertEqual(xblock.is_released(step=step), released) self.assertEqual(xblock.is_released(step=step), released)
@scenario('data/basic_scenario.xml')
def test_get_username(self, xblock):
user = MagicMock()
user.username = "Bob"
xblock.xmodule_runtime = MagicMock()
xblock.xmodule_runtime.get_real_user.return_value = user
self.assertEqual('Bob', xblock.get_username('anon_id'))
@scenario('data/basic_scenario.xml')
def test_get_username_unknown_id(self, xblock):
xblock.xmodule_runtime = MagicMock()
xblock.xmodule_runtime.get_real_user.return_value = None
self.assertIsNone(xblock.get_username('unknown_id'))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment