Skip to content

Commit

Permalink
feat: add organization logo to public video page (#31922)
Browse files Browse the repository at this point in the history
* feat: add org logo to public video page

Refactors CTA banner slightly to allow for left org logo float.

* fix: hide org logo if not provided

* test: add tests for org logo
  • Loading branch information
nsprenkle committed Mar 16, 2023
1 parent b6ba328 commit 4d999ed
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
35 changes: 35 additions & 0 deletions lms/djangoapps/courseware/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3096,6 +3096,41 @@ def test_access(self, is_waffle_enabled, is_public_video, expected_status_code):
self.assertEqual(expected_status_code, response.status_code)
self.assertEqual(expected_status_code, embed_response.status_code)

def test_get_org_logo_none(self):
# Given a course with no organizational logo
self.setup_course()
target_video = self.video_block_public

# When I render the page
response = self.get_response(usage_key=target_video.location, is_embed=False)
content = response.content.decode('utf-8')

# Then the page does not render an org logo
org_logo = re.search('<img .*class=[\'"]org-logo[\'"].*>', content)
self.assertIsNone(org_logo)

@patch('lms.djangoapps.courseware.views.views.get_course_organization')
def test_get_org_logo(self, mock_get_org):
# Given a course with an organizational logo
self.setup_course()
target_video = self.video_block_public

mock_org_logo_url = "/assets/foo"
mock_org_logo = MagicMock()
mock_org_logo.url = mock_org_logo_url

mock_get_org.return_value = {
"logo": mock_org_logo
}

# When I render the page
response = self.get_response(usage_key=target_video.location, is_embed=False)
content = response.content.decode('utf-8')

# Then the page does render an org logo
org_logo = re.search(f'<img .*class=[\'"]org-logo[\'"].*src=[\'"]{mock_org_logo_url}[\'"].*>', content)
self.assertIsNotNone(org_logo)


class TestRenderXBlockSelfPaced(TestRenderXBlock): # lint-amnesty, pylint: disable=test-inherits-tests
"""
Expand Down
13 changes: 13 additions & 0 deletions lms/djangoapps/courseware/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey, UsageKey
from openedx_filters.learning.filters import CourseAboutRenderStarted
from organizations.api import get_course_organization
from pytz import UTC
from requests.exceptions import ConnectionError, Timeout # pylint: disable=redefined-builtin
from rest_framework import status
Expand Down Expand Up @@ -1785,9 +1786,11 @@ def get_template_and_context(self, course, video_block):
})
course_about_page_url, enroll_url = self.get_public_video_cta_button_urls(course)
social_sharing_metadata = self.get_social_sharing_metadata(course, video_block)
org_logo = self.get_organization_logo_from_course(course)
context = {
'fragment': fragment,
'course': course,
'org_logo': org_logo,
'social_sharing_metadata': social_sharing_metadata,
'learn_more_url': course_about_page_url,
'enroll_url': enroll_url,
Expand All @@ -1799,6 +1802,16 @@ def get_template_and_context(self, course, video_block):
}
return 'public_video.html', context

def get_organization_logo_from_course(self, course):
"""
Get organization logo for this course
"""
course_org = get_course_organization(course.id)

if course_org and course_org['logo']:
return course_org['logo'].url
return None

def get_social_sharing_metadata(self, course, video_block):
"""
Gather the information for the meta OpenGraph and Twitter-specific tags
Expand Down
9 changes: 8 additions & 1 deletion lms/static/sass/_experiments.scss
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,16 @@
// AU 972 Social Video Sharing Page
.public-video-share-cta {
position: relative;
float: right;
z-index: 1;

.org-logo{
height: 40px;
}

.nav-links{
float: right;
}

.btn-learn-more{
@extend %btn-shims;
color: #00262B;
Expand Down
7 changes: 5 additions & 2 deletions lms/templates/public_video.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
</%block>

<%block name="body_extra">
<nav class="public-video-share-cta nav-links" aria-label="Learn More">
<div>
<nav class="public-video-share-cta" aria-label="Learn More">
% if org_logo:
<img class="org-logo" src="${org_logo}" alt="Organization Logo"/>
% endif
<div class="nav-links">
<a class="btn-learn-more btn" href="${learn_more_url}">
${_("Learn more about this course")}
</a>
Expand Down

0 comments on commit 4d999ed

Please sign in to comment.