Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
4f50874f
Commit
4f50874f
authored
Dec 14, 2016
by
jagonzalr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update tests
parent
ce17c1cd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
25 deletions
+48
-25
cms/djangoapps/contentstore/views/course.py
+2
-19
cms/djangoapps/contentstore/views/library.py
+16
-1
cms/djangoapps/contentstore/views/tests/test_library.py
+30
-5
No files found.
cms/djangoapps/contentstore/views/course.py
View file @
4f50874f
...
@@ -26,7 +26,7 @@ from .component import (
...
@@ -26,7 +26,7 @@ from .component import (
ADVANCED_COMPONENT_TYPES
,
ADVANCED_COMPONENT_TYPES
,
)
)
from
.item
import
create_xblock_info
from
.item
import
create_xblock_info
from
.library
import
LIBRARIES_ENABLED
from
.library
import
LIBRARIES_ENABLED
,
_get_library_creator_status
from
ccx_keys.locator
import
CCXLocator
from
ccx_keys.locator
import
CCXLocator
from
contentstore.course_group_config
import
(
from
contentstore.course_group_config
import
(
COHORT_SCHEME
,
COHORT_SCHEME
,
...
@@ -1634,7 +1634,7 @@ def _get_course_creator_status(user):
...
@@ -1634,7 +1634,7 @@ def _get_course_creator_status(user):
If the user passed in has not previously visited the index page, it will be
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.
added with status 'unrequested' if the course creator group is in use.
"""
"""
if
user
.
is_staff
:
if
user
.
is_staff
:
course_creator_status
=
'granted'
course_creator_status
=
'granted'
elif
settings
.
FEATURES
.
get
(
'DISABLE_COURSE_CREATION'
,
False
):
elif
settings
.
FEATURES
.
get
(
'DISABLE_COURSE_CREATION'
,
False
):
...
@@ -1650,20 +1650,3 @@ def _get_course_creator_status(user):
...
@@ -1650,20 +1650,3 @@ def _get_course_creator_status(user):
course_creator_status
=
'granted'
course_creator_status
=
'granted'
return
course_creator_status
return
course_creator_status
def
_get_library_creator_status
(
user
):
"""
Helper method for returning the library creation status for a particular user,
taking into account the value LIBRARIES_ENABLED.
"""
if
not
LIBRARIES_ENABLED
:
return
False
elif
user
.
is_staff
:
return
True
elif
settings
.
FEATURES
.
get
(
'ENABLE_CREATOR_GROUP'
,
False
):
return
CourseCreatorRole
()
.
has_user
(
user
)
else
:
return
False
cms/djangoapps/contentstore/views/library.py
View file @
4f50874f
...
@@ -38,6 +38,21 @@ log = logging.getLogger(__name__)
...
@@ -38,6 +38,21 @@ log = logging.getLogger(__name__)
LIBRARIES_ENABLED
=
settings
.
FEATURES
.
get
(
'ENABLE_CONTENT_LIBRARIES'
,
False
)
LIBRARIES_ENABLED
=
settings
.
FEATURES
.
get
(
'ENABLE_CONTENT_LIBRARIES'
,
False
)
def
_get_library_creator_status
(
user
):
"""
Helper method for returning the library creation status for a particular user,
taking into account the value LIBRARIES_ENABLED.
"""
if
not
LIBRARIES_ENABLED
:
return
False
elif
user
.
is_staff
:
return
True
elif
settings
.
FEATURES
.
get
(
'ENABLE_CREATOR_GROUP'
,
False
):
return
CourseCreatorRole
()
.
has_user
(
user
)
else
:
return
True
@login_required
@login_required
@ensure_csrf_cookie
@ensure_csrf_cookie
...
@@ -50,7 +65,7 @@ def library_handler(request, library_key_string=None):
...
@@ -50,7 +65,7 @@ def library_handler(request, library_key_string=None):
log
.
exception
(
"Attempted to use the content library API when the libraries feature is disabled."
)
log
.
exception
(
"Attempted to use the content library API when the libraries feature is disabled."
)
raise
Http404
# Should never happen because we test the feature in urls.py also
raise
Http404
# Should never happen because we test the feature in urls.py also
if
not
CourseCreatorRole
()
.
has_user
(
request
.
user
):
if
not
_get_library_creator_status
(
request
.
user
):
if
not
request
.
user
.
is_staff
:
if
not
request
.
user
.
is_staff
:
return
HttpResponseForbidden
()
return
HttpResponseForbidden
()
...
...
cms/djangoapps/contentstore/views/tests/test_library.py
View file @
4f50874f
...
@@ -46,7 +46,7 @@ class UnitTestLibraries(CourseTestCase):
...
@@ -46,7 +46,7 @@ class UnitTestLibraries(CourseTestCase):
def
test_library_creator_status_libraries_not_enabled
(
self
):
def
test_library_creator_status_libraries_not_enabled
(
self
):
_
,
nostaff_user
=
self
.
create_non_staff_authed_user_client
()
_
,
nostaff_user
=
self
.
create_non_staff_authed_user_client
()
self
.
assertEqual
(
_get_library_creator_status
(
nostaff_user
),
False
)
self
.
assertEqual
(
_get_library_creator_status
(
nostaff_user
),
False
)
@mock.patch
(
"contentstore.views.library.LIBRARIES_ENABLED"
,
True
)
@mock.patch
(
"contentstore.views.library.LIBRARIES_ENABLED"
,
True
)
def
test_library_creator_status_with_is_staff_user
(
self
):
def
test_library_creator_status_with_is_staff_user
(
self
):
...
@@ -61,8 +61,8 @@ class UnitTestLibraries(CourseTestCase):
...
@@ -61,8 +61,8 @@ class UnitTestLibraries(CourseTestCase):
@mock.patch
(
"contentstore.views.library.LIBRARIES_ENABLED"
,
True
)
@mock.patch
(
"contentstore.views.library.LIBRARIES_ENABLED"
,
True
)
def
test_library_creator_status_with_no_course_creator_role
(
self
):
def
test_library_creator_status_with_no_course_creator_role
(
self
):
_
,
nostaff_user
=
self
.
create_non_staff_authed_user_client
()
_
,
nostaff_user
=
self
.
create_non_staff_authed_user_client
()
self
.
assertEqual
(
_get_library_creator_status
(
nostaff_user
),
Fals
e
)
self
.
assertEqual
(
_get_library_creator_status
(
nostaff_user
),
Tru
e
)
@patch
(
"contentstore.views.library.LIBRARIES_ENABLED"
,
False
)
@patch
(
"contentstore.views.library.LIBRARIES_ENABLED"
,
False
)
def
test_with_libraries_disabled
(
self
):
def
test_with_libraries_disabled
(
self
):
...
@@ -113,8 +113,7 @@ class UnitTestLibraries(CourseTestCase):
...
@@ -113,8 +113,7 @@ class UnitTestLibraries(CourseTestCase):
@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 are not given course creator roles should still be able to
Users who are given course creator roles should be able to create libraries.
create libraries.
"""
"""
self
.
client
.
logout
()
self
.
client
.
logout
()
ns_user
,
password
=
self
.
create_non_staff_user
()
ns_user
,
password
=
self
.
create_non_staff_user
()
...
@@ -125,6 +124,32 @@ class UnitTestLibraries(CourseTestCase):
...
@@ -125,6 +124,32 @@ class UnitTestLibraries(CourseTestCase):
})
})
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
@patch.dict
(
'django.conf.settings.FEATURES'
,
{
'ENABLE_CREATOR_GROUP'
:
False
})
def
test_lib_create_permission_no_course_creator_role_and_no_course_creator_group
(
self
):
"""
Users who are not given course creator roles should still be able to create libraries if COURSE_CREATOR_GROUP is not enabled
"""
self
.
client
.
logout
()
ns_user
,
password
=
self
.
create_non_staff_user
()
self
.
client
.
login
(
username
=
ns_user
.
username
,
password
=
password
)
response
=
self
.
client
.
ajax_post
(
LIBRARY_REST_URL
,
{
'org'
:
'org'
,
'library'
:
'lib'
,
'display_name'
:
"New Library"
,
})
self
.
assertEqual
(
response
.
status_code
,
200
)
@patch.dict
(
'django.conf.settings.FEATURES'
,
{
'ENABLE_CREATOR_GROUP'
:
True
})
def
test_lib_create_permission_no_course_creator_role_and_course_creator_group
(
self
):
"""
Users who are not given course creator roles should not be able to create libraries if COURSE_CREATOR_GROUP is enabled.
"""
self
.
client
.
logout
()
ns_user
,
password
=
self
.
create_non_staff_user
()
self
.
client
.
login
(
username
=
ns_user
.
username
,
password
=
password
)
response
=
self
.
client
.
ajax_post
(
LIBRARY_REST_URL
,
{
'org'
:
'org'
,
'library'
:
'lib'
,
'display_name'
:
"New Library"
,
})
self
.
assertEqual
(
response
.
status_code
,
403
)
@ddt.data
(
@ddt.data
(
{},
{},
{
'org'
:
'org'
},
{
'org'
:
'org'
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment