From 00a42fe12138e19ef4feca844f87d547b1cb81ba Mon Sep 17 00:00:00 2001 From: jagonzalr Date: Thu, 3 Nov 2016 14:59:39 +0200 Subject: [PATCH] show button new library in studio depending on flags and user staff status --- cms/djangoapps/contentstore/views/course.py | 24 +++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py index 70686f0353..1ee0ec20c1 100644 --- a/cms/djangoapps/contentstore/views/course.py +++ b/cms/djangoapps/contentstore/views/course.py @@ -467,7 +467,7 @@ def course_listing(request): List all courses available to the logged in user """ courses, in_process_course_actions = get_courses_accessible_to_user(request) - libraries = _accessible_libraries_list(request.user) if LIBRARIES_ENABLED else [] + libraries = _accessible_libraries_list(request.user) if LIBRARIES_ENABLED and request.user.is_staff else [] programs_config = ProgramsApiConfig.current() raw_programs = get_programs(request.user) if programs_config.is_studio_tab_enabled else [] @@ -518,7 +518,7 @@ def course_listing(request): 'in_process_course_actions': in_process_course_actions, 'libraries_enabled': LIBRARIES_ENABLED, 'libraries': [format_library_for_view(lib) for lib in libraries], - 'show_new_library_button': LIBRARIES_ENABLED and request.user.is_active, + 'show_new_library_button': _get_library_creation_status(request.user), 'user': request.user, 'request_course_creator_url': reverse('contentstore.views.request_course_creator'), 'course_creator_status': _get_course_creator_status(request.user), @@ -1631,6 +1631,7 @@ def _get_course_creator_status(user): If the user passed in has not previously visited the index page, it will be added with status 'unrequested' if the course creator group is in use. """ + if user.is_staff: course_creator_status = 'granted' elif settings.FEATURES.get('DISABLE_COURSE_CREATION', False): @@ -1646,3 +1647,22 @@ def _get_course_creator_status(user): course_creator_status = 'granted' return course_creator_status + + +def _get_library_creation_status(user): + """ + Helper method for returning the library creation status for a particular user, + taking into account the values of DISABLE_LIBRARY_CREATION and LIBRARIES_ENABLED. + + """ + + if LIBRARIES_ENABLED: + if user.is_active and user.is_staff: + if not settings.FEATURES.get('DISABLE_LIBRARY_CREATION', False): + return True + else: + return False + else: + return False + else: + return False