Skip to content
Snippets Groups Projects
Commit 5ee85126 authored by Qubad786's avatar Qubad786
Browse files

Configure LTI editable fields to provide/avoid their editing from studio

parent 0f808cd1
No related branches found
No related tags found
No related merge requests found
...@@ -164,6 +164,7 @@ class LaunchTarget(object): ...@@ -164,6 +164,7 @@ class LaunchTarget(object):
@XBlock.needs('i18n') @XBlock.needs('i18n')
@XBlock.wants('lti-configuration')
class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock): class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
""" """
This XBlock provides an LTI consumer interface for integrating This XBlock provides an LTI consumer interface for integrating
...@@ -421,11 +422,12 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock): ...@@ -421,11 +422,12 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
scope=Scope.settings scope=Scope.settings
) )
# StudioEditableXBlockMixin configuration of fields editable in Studio # Possible editable fields
editable_fields = ( editable_field_names = (
'display_name', 'description', 'lti_id', 'launch_url', 'custom_parameters', 'launch_target', 'button_text', 'display_name', 'description', 'lti_id', 'launch_url', 'custom_parameters',
'inline_height', 'modal_height', 'modal_width', 'has_score', 'weight', 'hide_launch', 'accept_grades_past_due', 'launch_target', 'button_text', 'inline_height', 'modal_height', 'modal_width',
'ask_to_send_username', 'ask_to_send_email' 'has_score', 'weight', 'hide_launch', 'accept_grades_past_due', 'ask_to_send_username',
'ask_to_send_email'
) )
def validate_field_data(self, validation, data): def validate_field_data(self, validation, data):
...@@ -433,6 +435,30 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock): ...@@ -433,6 +435,30 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
_ = self.runtime.service(self, "i18n").ugettext _ = self.runtime.service(self, "i18n").ugettext
validation.add(ValidationMessage(ValidationMessage.ERROR, unicode(_("Custom Parameters must be a list")))) validation.add(ValidationMessage(ValidationMessage.ERROR, unicode(_("Custom Parameters must be a list"))))
@property
def editable_fields(self):
"""
Returns editable fields which may/may not contain 'ask_to_send_username' and
'ask_to_send_email' fields depending on the configuration service.
"""
editable_fields = self.editable_field_names
# update the editable fields if this XBlock is configured to not to allow the
# editing of 'ask_to_send_username' and 'ask_to_send_email'.
config_service = self.runtime.service(self, 'lti-configuration')
if config_service:
is_already_sharing_learner_info = self.ask_to_send_email or self.ask_to_send_username
if not config_service.configuration.lti_access_to_learners_editable(
self.course_id,
is_already_sharing_learner_info,
):
editable_fields = tuple(
field
for field in self.editable_field_names
if field not in ('ask_to_send_username', 'ask_to_send_email')
)
return editable_fields
@property @property
def descriptor(self): def descriptor(self):
""" """
......
...@@ -263,6 +263,64 @@ class TestProperties(TestLtiConsumerXBlock): ...@@ -263,6 +263,64 @@ class TestProperties(TestLtiConsumerXBlock):
self.assertTrue(mock_timezone_now.called) self.assertTrue(mock_timezone_now.called)
class TestEditableFields(TestLtiConsumerXBlock):
"""
Unit tests for LtiConsumerXBlock.editable_fields
"""
def get_mock_lti_configuration(self, editable):
"""
Returns a mock object of lti-configuration service
Arguments:
editable (bool): This indicates whether the LTI fields (i.e. 'ask_to_send_username' and
'ask_to_send_email') are editable.
"""
lti_configuration = Mock()
lti_configuration.configuration = Mock()
lti_configuration.configuration.lti_access_to_learners_editable = Mock(
return_value=editable
)
return lti_configuration
def are_fields_editable(self, fields):
"""
Returns whether the fields passed in as an argument, are editable.
Arguments:
fields (list): list containing LTI Consumer XBlock's field names.
"""
return all(field in self.xblock.editable_fields for field in fields)
def test_editable_fields_with_no_config(self):
"""
Test that LTI XBlock's fields (i.e. 'ask_to_send_username' and 'ask_to_send_email')
are editable when lti-configuration service is not provided.
"""
self.xblock.runtime.service.return_value = None
# Assert that 'ask_to_send_username' and 'ask_to_send_email' are editable.
self.assertTrue(self.are_fields_editable(fields=['ask_to_send_username', 'ask_to_send_email']))
def test_editable_fields_when_editing_allowed(self):
"""
Test that LTI XBlock's fields (i.e. 'ask_to_send_username' and 'ask_to_send_email')
are editable when this XBlock is configured to allow it.
"""
# this XBlock is configured to allow editing of LTI fields
self.xblock.runtime.service.return_value = self.get_mock_lti_configuration(editable=True)
# Assert that 'ask_to_send_username' and 'ask_to_send_email' are editable.
self.assertTrue(self.are_fields_editable(fields=['ask_to_send_username', 'ask_to_send_email']))
def test_editable_fields_when_editing_not_allowed(self):
"""
Test that LTI XBlock's fields (i.e. 'ask_to_send_username' and 'ask_to_send_email')
are not editable when this XBlock is configured to not to allow it.
"""
# this XBlock is configured to not to allow editing of LTI fields
self.xblock.runtime.service.return_value = self.get_mock_lti_configuration(editable=False)
# Assert that 'ask_to_send_username' and 'ask_to_send_email' are not editable.
self.assertFalse(self.are_fields_editable(fields=['ask_to_send_username', 'ask_to_send_email']))
class TestStudentView(TestLtiConsumerXBlock): class TestStudentView(TestLtiConsumerXBlock):
""" """
Unit tests for LtiConsumerXBlock.student_view() Unit tests for LtiConsumerXBlock.student_view()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment