Skip to content

Commit

Permalink
Merge pull request #18344 from open-craft/symbolist/navigation-for-an…
Browse files Browse the repository at this point in the history
…onymous-users

Fixes for courseware anonymous access.
  • Loading branch information
mduboseedx authored Aug 16, 2018
2 parents 5a4c457 + 36b3316 commit 6bc8b4d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
16 changes: 11 additions & 5 deletions common/lib/xmodule/xmodule/js/src/sequence/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
this.ajaxUrl = this.el.data('ajax-url');
this.nextUrl = this.el.data('next-url');
this.prevUrl = this.el.data('prev-url');
this.savePosition = this.el.data('save-position');
this.showCompletion = this.el.data('show-completion');
this.keydownHandler($(element).find('#sequence-list .tab'));
this.base_page_title = ($('title').data('base-title') || '').trim();
this.bind();
Expand Down Expand Up @@ -230,11 +232,15 @@
if (this.position !== newPosition) {
if (this.position) {
this.mark_visited(this.position);
this.update_completion(this.position);
modxFullUrl = '' + this.ajaxUrl + '/goto_position';
$.postWithPrefix(modxFullUrl, {
position: newPosition
});
if (this.showCompletion) {
this.update_completion(this.position);
}
if (this.savePosition) {
modxFullUrl = '' + this.ajaxUrl + '/goto_position';
$.postWithPrefix(modxFullUrl, {
position: newPosition
});
}
}

// On Sequence change, fire custom event 'sequence:change' on element.
Expand Down
3 changes: 2 additions & 1 deletion common/lib/xmodule/xmodule/seq_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ def _student_view(self, context, banner_text=None):
'next_url': context.get('next_url'),
'prev_url': context.get('prev_url'),
'banner_text': banner_text,
'disable_navigation': not self.is_user_authenticated(context),
'save_position': self.is_user_authenticated(context),
'show_completion': self.is_user_authenticated(context),
'gated_content': self._get_gated_content_info(prereq_met, prereq_meta_info)
}
fragment.add_content(self.system.render_template("seq_module.html", params))
Expand Down
11 changes: 11 additions & 0 deletions lms/djangoapps/courseware/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2338,6 +2338,7 @@ def test_anonymous_access(self):
with self.store.bulk_operations(course.id):
chapter = ItemFactory(parent=course, category='chapter')
section = ItemFactory(parent=chapter, category='sequential')
ItemFactory.create(parent=section, category='vertical', display_name="Vertical")

url = reverse(
'courseware_section',
Expand All @@ -2354,6 +2355,16 @@ def test_anonymous_access(self):
with override_waffle_flag(waffle_flag, active=True):
response = self.client.get(url, follow=False)
assert response.status_code == 200
self.assertIn('data-save-position="false"', response.content)
self.assertIn('data-show-completion="false"', response.content)

user = UserFactory()
CourseEnrollmentFactory(user=user, course_id=course.id)
self.assertTrue(self.client.login(username=user.username, password='test'))
response = self.client.get(url, follow=False)
assert response.status_code == 200
self.assertIn('data-save-position="true"', response.content)
self.assertIn('data-show-completion="true"', response.content)


@attr(shard=5)
Expand Down
10 changes: 7 additions & 3 deletions lms/templates/seq_module.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<%page expression_filter="h"/>
<%! from django.utils.translation import ugettext as _ %>

<div id="sequence_${element_id}" class="sequence" data-id="${item_id}" data-position="${position}" data-ajax-url="${ajax_url}" data-next-url="${next_url}" data-prev-url="${prev_url}">
<div id="sequence_${element_id}" class="sequence" data-id="${item_id}"
data-position="${position}" data-ajax-url="${ajax_url}"
data-next-url="${next_url}" data-prev-url="${prev_url}"
data-save-position="${'true' if save_position else 'false'}"
data-show-completion="${'true' if show_completion else 'false'}"
>
% if banner_text:
<div class="pattern-library-shim alert alert-information subsection-header" tabindex="-1">
<span class="pattern-library-shim icon alert-icon fa fa-info-circle" aria-hidden="true"></span>
Expand Down Expand Up @@ -46,8 +51,7 @@
data-page-title="${item['page_title']}"
data-path="${item['path']}"
data-graded="${item['graded']}"
id="tab_${idx}"
${"disabled=disabled" if disable_navigation else ""}>
id="tab_${idx}">
<span class="icon fa seq_${item['type']}" aria-hidden="true"></span>
% if 'complete' in item:
<span
Expand Down

0 comments on commit 6bc8b4d

Please sign in to comment.