Commit 24af22ca by Braden MacDonald

Remove restrictions on library creation in Studio

parent 4d6cefcc
...@@ -523,13 +523,13 @@ class TestLibraryAccess(SignalDisconnectTestMixin, LibraryTestCase): ...@@ -523,13 +523,13 @@ class TestLibraryAccess(SignalDisconnectTestMixin, LibraryTestCase):
self.client.logout() self.client.logout()
self._assert_cannot_create_library(expected_code=302) # 302 redirect to login expected self._assert_cannot_create_library(expected_code=302) # 302 redirect to login expected
# Now create a non-staff user with no permissions: # Now check that logged-in users without CourseCreator role can still create libraries
self._login_as_non_staff_user(logout_first=False) self._login_as_non_staff_user(logout_first=False)
self.assertFalse(CourseCreatorRole().has_user(self.non_staff_user)) self.assertFalse(CourseCreatorRole().has_user(self.non_staff_user))
# Now check that logged-in users without any permissions cannot create libraries
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREATOR_GROUP': True}): with patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREATOR_GROUP': True}):
self._assert_cannot_create_library() lib_key2 = self._create_library(library="lib2", display_name="Test Library 2")
library2 = modulestore().get_library(lib_key2)
self.assertIsNotNone(library2)
@ddt.data( @ddt.data(
CourseInstructorRole, CourseInstructorRole,
......
...@@ -458,6 +458,7 @@ def course_listing(request): ...@@ -458,6 +458,7 @@ def course_listing(request):
'in_process_course_actions': in_process_course_actions, 'in_process_course_actions': in_process_course_actions,
'libraries_enabled': LIBRARIES_ENABLED, 'libraries_enabled': LIBRARIES_ENABLED,
'libraries': [format_library_for_view(lib) for lib in libraries], 'libraries': [format_library_for_view(lib) for lib in libraries],
'show_new_library_button': LIBRARIES_ENABLED and request.user.is_active,
'user': request.user, 'user': request.user,
'request_course_creator_url': reverse('contentstore.views.request_course_creator'), 'request_course_creator_url': reverse('contentstore.views.request_course_creator'),
'course_creator_status': _get_course_creator_status(request.user), 'course_creator_status': _get_course_creator_status(request.user),
......
...@@ -30,7 +30,7 @@ from .component import get_component_templates, CONTAINER_TEMPLATES ...@@ -30,7 +30,7 @@ from .component import get_component_templates, CONTAINER_TEMPLATES
from student.auth import ( from student.auth import (
STUDIO_VIEW_USERS, STUDIO_EDIT_ROLES, get_user_permissions, has_studio_read_access, has_studio_write_access STUDIO_VIEW_USERS, STUDIO_EDIT_ROLES, get_user_permissions, has_studio_read_access, has_studio_write_access
) )
from student.roles import CourseCreatorRole, CourseInstructorRole, CourseStaffRole, LibraryUserRole from student.roles import CourseInstructorRole, CourseStaffRole, LibraryUserRole
from student import auth from student import auth
from util.json_request import expect_json, JsonResponse, JsonResponseBadRequest from util.json_request import expect_json, JsonResponse, JsonResponseBadRequest
...@@ -115,9 +115,6 @@ def _create_library(request): ...@@ -115,9 +115,6 @@ def _create_library(request):
""" """
Helper method for creating a new library. Helper method for creating a new library.
""" """
if not auth.has_access(request.user, CourseCreatorRole()):
log.exception(u"User %s tried to create a library without permission", request.user.username)
raise PermissionDenied()
display_name = None display_name = None
try: try:
display_name = request.json['display_name'] display_name = request.json['display_name']
......
...@@ -87,8 +87,8 @@ class UnitTestLibraries(ModuleStoreTestCase): ...@@ -87,8 +87,8 @@ class UnitTestLibraries(ModuleStoreTestCase):
@patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREATOR_GROUP': True}) @patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREATOR_GROUP': True})
def test_lib_create_permission(self): def test_lib_create_permission(self):
""" """
Users who aren't given course creator roles shouldn't be able to create Users who are not given course creator roles should still be able to
libraries either. create libraries.
""" """
self.client.logout() self.client.logout()
ns_user, password = self.create_non_staff_user() ns_user, password = self.create_non_staff_user()
...@@ -97,7 +97,7 @@ class UnitTestLibraries(ModuleStoreTestCase): ...@@ -97,7 +97,7 @@ class UnitTestLibraries(ModuleStoreTestCase):
response = self.client.ajax_post(LIBRARY_REST_URL, { response = self.client.ajax_post(LIBRARY_REST_URL, {
'org': 'org', 'library': 'lib', 'display_name': "New Library", 'org': 'org', 'library': 'lib', 'display_name': "New Library",
}) })
self.assertEqual(response.status_code, 403) self.assertEqual(response.status_code, 200)
@ddt.data( @ddt.data(
{}, {},
......
...@@ -24,13 +24,13 @@ ...@@ -24,13 +24,13 @@
% if course_creator_status=='granted': % if course_creator_status=='granted':
<a href="#" class="button new-button new-course-button"><i class="icon fa fa-plus icon-inline"></i> <a href="#" class="button new-button new-course-button"><i class="icon fa fa-plus icon-inline"></i>
${_("New Course")}</a> ${_("New Course")}</a>
% if libraries_enabled:
<a href="#" class="button new-button new-library-button"><i class="icon fa fa-plus icon-inline"></i>
${_("New Library")}</a>
% endif
% elif course_creator_status=='disallowed_for_this_site' and settings.FEATURES.get('STUDIO_REQUEST_EMAIL',''): % elif course_creator_status=='disallowed_for_this_site' and settings.FEATURES.get('STUDIO_REQUEST_EMAIL',''):
<a href="mailto:${settings.FEATURES.get('STUDIO_REQUEST_EMAIL','')}">${_("Email staff to create course")}</a> <a href="mailto:${settings.FEATURES.get('STUDIO_REQUEST_EMAIL','')}">${_("Email staff to create course")}</a>
% endif % endif
% if show_new_library_button:
<a href="#" class="button new-button new-library-button"><i class="icon fa fa-plus icon-inline"></i>
${_("New Library")}</a>
% endif
</li> </li>
</ul> </ul>
</nav> </nav>
...@@ -449,7 +449,7 @@ ...@@ -449,7 +449,7 @@
</div> </div>
</div> </div>
</div> </div>
%if course_creator_status == "granted": % if show_new_library_button:
<div class="notice-item has-actions"> <div class="notice-item has-actions">
<div class="msg"> <div class="msg">
<h3 class="title">${_('Create Your First Library')}</h3> <h3 class="title">${_('Create Your First Library')}</h3>
...@@ -464,7 +464,7 @@ ...@@ -464,7 +464,7 @@
</li> </li>
</ul> </ul>
</div> </div>
%endif % endif
</div> </div>
%endif %endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment