Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lti-xblock-consumer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OpenJupyter
lti-xblock-consumer
Commits
5ee85126
Commit
5ee85126
authored
8 years ago
by
Qubad786
Browse files
Options
Downloads
Patches
Plain Diff
Configure LTI editable fields to provide/avoid their editing from studio
parent
0f808cd1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lti_consumer/lti_consumer.py
+31
-5
31 additions, 5 deletions
lti_consumer/lti_consumer.py
lti_consumer/tests/unit/test_lti_consumer.py
+58
-0
58 additions, 0 deletions
lti_consumer/tests/unit/test_lti_consumer.py
with
89 additions
and
5 deletions
lti_consumer/lti_consumer.py
+
31
−
5
View file @
5ee85126
...
@@ -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
):
"""
"""
...
...
This diff is collapsed.
Click to expand it.
lti_consumer/tests/unit/test_lti_consumer.py
+
58
−
0
View file @
5ee85126
...
@@ -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()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment