From a34081c24bb2f2299afb8ec30d4ad5296acccf6d Mon Sep 17 00:00:00 2001 From: Harry Rein Date: Fri, 23 Jun 2017 11:07:41 -0400 Subject: [PATCH] Assuring that courses without updates cannot see the updates link from the home page and that the update message does not throw an error upon loading from a direct URL without any updates. Added test to assure this behavior and fixed up welcome message tests. --- openedx/features/course_bookmarks/plugins.py | 2 +- .../course_experience/course_tools.py | 2 +- openedx/features/course_experience/plugins.py | 16 +++++---- .../course-home-fragment.html | 2 +- .../course-updates-fragment.html | 26 ++++++++------ .../tests/views/test_course_home.py | 34 +++++++++++++----- .../tests/views/test_course_updates.py | 5 +-- .../tests/views/test_welcome_message.py | 2 +- .../course_experience/views/course_home.py | 8 ++--- .../course_experience/views/course_updates.py | 35 +++++++++++++------ .../views/welcome_message.py | 7 ++-- 11 files changed, 87 insertions(+), 52 deletions(-) diff --git a/openedx/features/course_bookmarks/plugins.py b/openedx/features/course_bookmarks/plugins.py index 3f24942ae8..17880af8b9 100644 --- a/openedx/features/course_bookmarks/plugins.py +++ b/openedx/features/course_bookmarks/plugins.py @@ -12,7 +12,7 @@ class CourseBookmarksTool(CourseTool): The course bookmarks tool. """ @classmethod - def is_enabled(cls, course_key): + def is_enabled(cls, request, course_key): """ Always show the bookmarks tool. """ diff --git a/openedx/features/course_experience/course_tools.py b/openedx/features/course_experience/course_tools.py index 1057f355bc..76ecb4e857 100644 --- a/openedx/features/course_experience/course_tools.py +++ b/openedx/features/course_experience/course_tools.py @@ -18,7 +18,7 @@ class CourseTool(object): """ @classmethod - def is_enabled(cls, course_key): + def is_enabled(cls, request, course_key): """ Returns true if this tool is enabled for the specified course key. """ diff --git a/openedx/features/course_experience/plugins.py b/openedx/features/course_experience/plugins.py index 611c348382..4cb091544f 100644 --- a/openedx/features/course_experience/plugins.py +++ b/openedx/features/course_experience/plugins.py @@ -3,13 +3,15 @@ Platform plugins to support the course experience. This includes any locally defined CourseTools. """ - from django.core.urlresolvers import reverse from django.utils.translation import ugettext as _ -from . import UNIFIED_COURSE_TAB_FLAG, SHOW_REVIEWS_TOOL_FLAG -from views.course_reviews import CourseReviewsModuleFragmentView from course_tools import CourseTool +from courseware.courses import get_course_by_id +from views.course_reviews import CourseReviewsModuleFragmentView +from views.course_updates import CourseUpdatesFragmentView + +from . import SHOW_REVIEWS_TOOL_FLAG, UNIFIED_COURSE_TAB_FLAG class CourseUpdatesTool(CourseTool): @@ -31,11 +33,13 @@ class CourseUpdatesTool(CourseTool): return 'fa fa-newspaper-o' @classmethod - def is_enabled(cls, course_key): + def is_enabled(cls, request, course_key): """ Returns True if this tool is enabled for the specified course key. """ - return UNIFIED_COURSE_TAB_FLAG.is_enabled(course_key) + course = get_course_by_id(course_key) + has_updates = CourseUpdatesFragmentView.has_updates(request, course) + return UNIFIED_COURSE_TAB_FLAG.is_enabled(course_key) and has_updates @classmethod def url(cls, course_key): @@ -64,7 +68,7 @@ class CourseReviewsTool(CourseTool): return 'fa fa-star' @classmethod - def is_enabled(cls, course_key): + def is_enabled(cls, request, course_key): """ Returns True if this tool is enabled for the specified course key. """ diff --git a/openedx/features/course_experience/templates/course_experience/course-home-fragment.html b/openedx/features/course_experience/templates/course_experience/course-home-fragment.html index 21abafd7fe..8f858d31db 100644 --- a/openedx/features/course_experience/templates/course_experience/course-home-fragment.html +++ b/openedx/features/course_experience/templates/course_experience/course-home-fragment.html @@ -75,7 +75,7 @@ from openedx.features.course_experience.course_tools import CourseToolsPluginMan

${_("Course Tools")}