Added anonymous user id and extra params in program lti (#29429)
* fix: added anonymous user id and extra params in program lti * refactor: updated flag name * fix: fixed linter issues
This commit is contained in:
@@ -4,11 +4,12 @@ Fragments for rendering programs.
|
||||
|
||||
import json
|
||||
|
||||
from urllib.parse import quote
|
||||
from django.contrib.sites.shortcuts import get_current_site
|
||||
from django.http import Http404
|
||||
from django.template.loader import render_to_string
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _ # lint-amnesty, pylint: disable=unused-import
|
||||
from django.utils.translation import get_language, to_locale, gettext_lazy as _ # lint-amnesty, pylint: disable=unused-import
|
||||
from lti_consumer.lti_1p1.contrib.django import lti_embed
|
||||
from web_fragments.fragment import Fragment
|
||||
|
||||
@@ -17,7 +18,7 @@ from lms.djangoapps.commerce.utils import EcommerceService
|
||||
from lms.djangoapps.learner_dashboard.utils import FAKE_COURSE_KEY, program_tab_view_is_enabled, strip_course_id
|
||||
|
||||
from openedx.core.djangoapps.catalog.constants import PathwayType
|
||||
from openedx.core.djangoapps.catalog.utils import get_pathways
|
||||
from openedx.core.djangoapps.catalog.utils import get_pathways, get_programs
|
||||
from openedx.core.djangoapps.credentials.utils import get_credentials_records_url
|
||||
from openedx.core.djangoapps.discussions.models import ProgramDiscussionsConfiguration
|
||||
from openedx.core.djangoapps.plugin_api.views import EdxFragmentView
|
||||
@@ -30,6 +31,7 @@ from openedx.core.djangoapps.programs.utils import (
|
||||
)
|
||||
from openedx.core.djangoapps.user_api.preferences.api import get_user_preferences
|
||||
from openedx.core.djangolib.markup import HTML
|
||||
from common.djangoapps.student.models import anonymous_id_for_user
|
||||
|
||||
|
||||
class ProgramsFragmentView(EdxFragmentView):
|
||||
@@ -147,9 +149,9 @@ class ProgramDetailsFragmentView(EdxFragmentView):
|
||||
'certificate_data': certificate_data,
|
||||
'industry_pathways': industry_pathways,
|
||||
'credit_pathways': credit_pathways,
|
||||
'program_discussions_enabled': program_tab_view_is_enabled(),
|
||||
'program_tab_view_enabled': program_tab_view_is_enabled(),
|
||||
'discussion_fragment': {
|
||||
'enabled': bool(program_discussion_lti.configuration),
|
||||
'configured': bool(program_discussion_lti.configuration),
|
||||
'iframe': program_discussion_lti.render_iframe()
|
||||
}
|
||||
}
|
||||
@@ -175,6 +177,7 @@ class ProgramDiscussionLTI:
|
||||
|
||||
def __init__(self, program_uuid, request):
|
||||
self.program_uuid = program_uuid
|
||||
self.program = get_programs(uuid=self.program_uuid)
|
||||
self.request = request
|
||||
self.configuration = self.get_configuration()
|
||||
|
||||
@@ -205,6 +208,16 @@ class ProgramDiscussionLTI:
|
||||
all_roles = [basic_role]
|
||||
return ','.join(all_roles)
|
||||
|
||||
def _get_additional_lti_parameters(self):
|
||||
lti_config = self.configuration.lti_configuration
|
||||
return lti_config.lti_config.get('additional_parameters', {})
|
||||
|
||||
def _get_context_title(self) -> str:
|
||||
return "{} - {}".format(
|
||||
self.program.get('title', ''),
|
||||
self.program.get('subtitle', ''),
|
||||
)
|
||||
|
||||
def _get_lti_embed_code(self) -> str:
|
||||
"""
|
||||
Returns the LTI embed code for embedding in the program discussions tab
|
||||
@@ -217,13 +230,16 @@ class ProgramDiscussionLTI:
|
||||
return lti_embed(
|
||||
html_element_id='lti-tab-launcher',
|
||||
lti_consumer=self.configuration.lti_configuration.get_lti_consumer(),
|
||||
resource_link_id=resource_link_id,
|
||||
user_id=str(self.request.user.id),
|
||||
resource_link_id=quote(resource_link_id),
|
||||
user_id=quote(anonymous_id_for_user(self.request.user, None)),
|
||||
roles=self.get_user_roles(),
|
||||
context_id=self.program_uuid,
|
||||
context_title=self.program_uuid,
|
||||
context_id=quote(self.program_uuid),
|
||||
context_title=self._get_context_title(),
|
||||
context_label=self.program_uuid,
|
||||
result_sourcedid=result_sourcedid
|
||||
result_sourcedid=quote(result_sourcedid),
|
||||
locale=to_locale(get_language()),
|
||||
additional_params=self._get_additional_lti_parameters()
|
||||
|
||||
)
|
||||
|
||||
def render_iframe(self) -> str:
|
||||
|
||||
@@ -328,8 +328,8 @@ class TestProgramDetailsFragmentView(SharedModuleStoreTestCase, ProgramCacheMixi
|
||||
|
||||
def test_discussion_flags_exist(self):
|
||||
"""
|
||||
Test if programDiscussionEnabled and discussionFragment exist in html.
|
||||
Test if programTabViewEnabled and discussionFragment exist in html.
|
||||
"""
|
||||
response = self.client.get(self.url)
|
||||
self.assertContains(response, 'programDiscussionEnabled: true',)
|
||||
self.assertContains(response, 'discussionFragment: {"enabled": false, "iframe": ""')
|
||||
self.assertContains(response, 'programTabViewEnabled: true',)
|
||||
self.assertContains(response, 'discussionFragment: {"configured": false, "iframe": ""')
|
||||
|
||||
@@ -57,7 +57,7 @@ describe('Program Progress View', () => {
|
||||
programRecordUrl: '/foo/bar',
|
||||
industryPathways: data.industryPathways,
|
||||
creditPathways: data.creditPathways,
|
||||
programDiscussionEnabled: false
|
||||
programTabViewEnabled: false
|
||||
|
||||
});
|
||||
|
||||
@@ -155,7 +155,7 @@ describe('Program Progress View', () => {
|
||||
programRecordUrl: '/foo/bar',
|
||||
industryPathways: [],
|
||||
creditPathways: [],
|
||||
programDiscussionEnabled: false
|
||||
programTabViewEnabled: false
|
||||
});
|
||||
|
||||
expect(emptyView.$('.program-credit-pathways .divider-heading')).toHaveLength(0);
|
||||
|
||||
@@ -493,7 +493,7 @@ describe('Program Details Header View', () => {
|
||||
destination_url: 'industry.com',
|
||||
},
|
||||
],
|
||||
programDiscussionEnabled: false
|
||||
programTabViewEnabled: false
|
||||
};
|
||||
const data = options.programData;
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class ProgramDetailsSidebarView extends Backbone.View {
|
||||
this.industryPathways = options.industryPathways;
|
||||
this.creditPathways = options.creditPathways;
|
||||
this.programModel = options.model;
|
||||
this.programDiscussionEnabled = options.programDiscussionEnabled;
|
||||
this.programTabViewEnabled = options.programTabViewEnabled;
|
||||
this.render();
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class ProgramDetailsSidebarView extends Backbone.View {
|
||||
programRecordUrl: this.programRecordUrl,
|
||||
industryPathways: this.industryPathways,
|
||||
creditPathways: this.creditPathways,
|
||||
programDiscussionEnabled: this.programDiscussionEnabled
|
||||
programTabViewEnabled: this.programTabViewEnabled
|
||||
});
|
||||
|
||||
HtmlUtils.setHtml(this.$el, this.tpl(data));
|
||||
|
||||
@@ -27,7 +27,7 @@ class ProgramDetailsView extends Backbone.View {
|
||||
|
||||
initialize(options) {
|
||||
this.options = options;
|
||||
if (this.options.programDiscussionEnabled) {
|
||||
if (this.options.programTabViewEnabled) {
|
||||
this.tpl = HtmlUtils.template(tabPageTpl);
|
||||
} else {
|
||||
this.tpl = HtmlUtils.template(pageTpl);
|
||||
@@ -79,7 +79,7 @@ class ProgramDetailsView extends Backbone.View {
|
||||
remainingCount,
|
||||
completedCount,
|
||||
completeProgramURL: buyButtonUrl,
|
||||
programDiscussionEnabled: this.options.programDiscussionEnabled,
|
||||
programTabViewEnabled: this.options.programTabViewEnabled,
|
||||
industryPathways: this.options.industryPathways,
|
||||
creditPathways: this.options.creditPathways,
|
||||
discussionFragment: this.options.discussionFragment,
|
||||
@@ -132,7 +132,7 @@ class ProgramDetailsView extends Backbone.View {
|
||||
programRecordUrl: this.options.urls.program_record_url,
|
||||
industryPathways: this.options.industryPathways,
|
||||
creditPathways: this.options.creditPathways,
|
||||
programDiscussionEnabled: this.options.programDiscussionEnabled,
|
||||
programTabViewEnabled: this.options.programTabViewEnabled,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ ProgramDetailsFactory({
|
||||
userPreferences: ${user_preferences | n, dump_js_escaped_json},
|
||||
industryPathways: ${industry_pathways | n, dump_js_escaped_json},
|
||||
creditPathways: ${credit_pathways | n, dump_js_escaped_json},
|
||||
programDiscussionEnabled: ${program_discussions_enabled | n, dump_js_escaped_json},
|
||||
programTabViewEnabled: ${program_tab_view_enabled | n, dump_js_escaped_json},
|
||||
discussionFragment: ${discussion_fragment, | n, dump_js_escaped_json}
|
||||
});
|
||||
</%static:webpack>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
</div>
|
||||
<% } %>
|
||||
</aside>
|
||||
<% if (!programDiscussionEnabled) { %>
|
||||
<% if (!programTabViewEnabled) { %>
|
||||
<% if (creditPathways.length > 0) { %>
|
||||
<aside class="aside js-program-pathways program-credit-pathways">
|
||||
<h2 class = "divider-heading"><%- gettext('Additional Credit Opportunities') %></h2>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<header class="js-program-header program-header full-width-banner"></header>
|
||||
<!-- TODO: consider if article is the most appropriate element here -->
|
||||
|
||||
<% if (programDiscussionEnabled) { %>
|
||||
<% if (programTabViewEnabled) { %>
|
||||
<div class="program-detail-nav">
|
||||
<ul class="nav nav-tabs program-detail-nav-list" id="programTabs" role="tablist">
|
||||
<li class="nav-item" role="presentation">
|
||||
<button class="nav-link btn-link active" id="home-tab" data-toggle="tab" data-target="#journey" type="button" role="tab" aria-controls="journey" aria-selected="true">Journey</button>
|
||||
</li>
|
||||
<% if (discussionFragment.enabled) { %>
|
||||
<% if (discussionFragment.configured) { %>
|
||||
<li class="nav-item" role="presentation">
|
||||
<button class="nav-link btn-link" id="profile-tab" data-toggle="tab" data-target="#community" type="button" role="tab" aria-controls="community" aria-selected="false">Community</button>
|
||||
</li>
|
||||
@@ -102,7 +102,7 @@
|
||||
<aside class="js-program-sidebar program-sidebar"></aside>
|
||||
|
||||
</div>
|
||||
<% if (discussionFragment.enabled) { %>
|
||||
<% if (discussionFragment.configured) { %>
|
||||
<div class="tab-pane fade" id="community" role="tabpanel" aria-labelledby="community-tab"><%= HtmlUtils.HTML(discussionFragment.iframe) %></div>
|
||||
<% } %>
|
||||
<div class="tab-pane fade" id="live" role="tabpanel" aria-labelledby="live-tab">Live tab content</div>
|
||||
|
||||
Reference in New Issue
Block a user