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
4e455fd8
Commit
4e455fd8
authored
Oct 21, 2013
by
Don Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Limit read access to people with write access.
Add unit tests for auth
parent
e9c70633
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
8 deletions
+33
-8
cms/djangoapps/contentstore/tests/test_orphan.py
+16
-0
cms/djangoapps/contentstore/tests/utils.py
+1
-1
cms/djangoapps/contentstore/views/item.py
+16
-7
No files found.
cms/djangoapps/contentstore/tests/test_orphan.py
View file @
4e455fd8
...
@@ -5,6 +5,7 @@ import json
...
@@ -5,6 +5,7 @@ import json
from
contentstore.tests.utils
import
CourseTestCase
from
contentstore.tests.utils
import
CourseTestCase
from
xmodule.modulestore.django
import
editable_modulestore
from
xmodule.modulestore.django
import
editable_modulestore
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
student.models
import
CourseEnrollment
class
TestOrphan
(
CourseTestCase
):
class
TestOrphan
(
CourseTestCase
):
"""
"""
...
@@ -70,3 +71,18 @@ class TestOrphan(CourseTestCase):
...
@@ -70,3 +71,18 @@ class TestOrphan(CourseTestCase):
self
.
client
.
get
(
url
,
HTTP_ACCEPT
=
'application/json'
)
.
content
self
.
client
.
get
(
url
,
HTTP_ACCEPT
=
'application/json'
)
.
content
)
)
self
.
assertEqual
(
len
(
orphans
),
0
,
"Orphans not deleted {}"
.
format
(
orphans
))
self
.
assertEqual
(
len
(
orphans
),
0
,
"Orphans not deleted {}"
.
format
(
orphans
))
def
test_not_permitted
(
self
):
"""
Test that auth restricts get and delete appropriately
"""
test_user_client
,
test_user
=
self
.
createNonStaffAuthedUserClient
()
CourseEnrollment
.
enroll
(
test_user
,
self
.
course
.
location
.
course_id
)
url
=
reverse
(
'orphan'
,
kwargs
=
{
'course_id'
:
'{}.{}'
.
format
(
self
.
course
.
location
.
org
,
self
.
course
.
location
.
course
)}
)
response
=
test_user_client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
403
)
response
=
test_user_client
.
delete
(
url
)
self
.
assertEqual
(
response
.
status_code
,
403
)
cms/djangoapps/contentstore/tests/utils.py
View file @
4e455fd8
...
@@ -65,7 +65,7 @@ class CourseTestCase(ModuleStoreTestCase):
...
@@ -65,7 +65,7 @@ class CourseTestCase(ModuleStoreTestCase):
def
createNonStaffAuthedUserClient
(
self
):
def
createNonStaffAuthedUserClient
(
self
):
"""
"""
Create a non-staff user, log them in, and return the client to use for testing.
Create a non-staff user, log them in, and return the client
, user
to use for testing.
"""
"""
uname
=
'teststudent'
uname
=
'teststudent'
password
=
'foo'
password
=
'foo'
...
...
cms/djangoapps/contentstore/views/item.py
View file @
4e455fd8
...
@@ -7,7 +7,7 @@ from django.core.exceptions import PermissionDenied
...
@@ -7,7 +7,7 @@ from django.core.exceptions import PermissionDenied
from
django.contrib.auth.decorators
import
login_required
from
django.contrib.auth.decorators
import
login_required
from
xmodule.modulestore
import
Location
from
xmodule.modulestore
import
Location
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
,
loc_mapper
from
xmodule.modulestore.inheritance
import
own_metadata
from
xmodule.modulestore.inheritance
import
own_metadata
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
,
InvalidLocationError
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
,
InvalidLocationError
...
@@ -21,6 +21,8 @@ from .access import has_access
...
@@ -21,6 +21,8 @@ from .access import has_access
from
.helpers
import
_xmodule_recurse
from
.helpers
import
_xmodule_recurse
from
xmodule.x_module
import
XModuleDescriptor
from
xmodule.x_module
import
XModuleDescriptor
from
django.views.decorators.http
import
require_http_methods
from
django.views.decorators.http
import
require_http_methods
from
xmodule.modulestore.locator
import
CourseLocator
from
student.models
import
CourseEnrollment
__all__
=
[
'save_item'
,
'create_item'
,
'delete_item'
,
'orphan'
]
__all__
=
[
'save_item'
,
'create_item'
,
'delete_item'
,
'orphan'
]
...
@@ -216,10 +218,17 @@ def orphan(request, course_id):
...
@@ -216,10 +218,17 @@ def orphan(request, course_id):
:param request:
:param request:
:param course_id: Locator syntax course_id
:param course_id: Locator syntax course_id
"""
"""
course_loc
=
CourseLocator
(
course_id
=
course_id
)
if
request
.
method
==
'GET'
:
if
request
.
method
==
'GET'
:
return
JsonResponse
(
modulestore
()
.
get_orphans
(
course_id
,
DETACHED_CATEGORIES
,
'draft'
))
if
has_access
(
request
.
user
,
course_loc
):
if
request
.
method
==
'DELETE'
and
request
.
user
.
is_staff
:
return
JsonResponse
(
modulestore
()
.
get_orphans
(
course_id
,
DETACHED_CATEGORIES
,
'draft'
))
items
=
modulestore
()
.
get_orphans
(
course_id
,
DETACHED_CATEGORIES
,
'draft'
)
else
:
for
item
in
items
:
raise
PermissionDenied
()
modulestore
(
'draft'
)
.
delete_item
(
item
,
True
)
if
request
.
method
==
'DELETE'
:
return
JsonResponse
({
'deleted'
:
items
})
if
request
.
user
.
is_staff
:
items
=
modulestore
()
.
get_orphans
(
course_id
,
DETACHED_CATEGORIES
,
'draft'
)
for
item
in
items
:
modulestore
(
'draft'
)
.
delete_item
(
item
,
True
)
return
JsonResponse
({
'deleted'
:
items
})
else
:
raise
PermissionDenied
()
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