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
ec55d8c1
Commit
ec55d8c1
authored
Dec 10, 2013
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create explicit Locations.
STUD-1030
parent
724cc025
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
24 additions
and
37 deletions
+24
-37
cms/djangoapps/auth/tests/__init__.py
+0
-0
cms/djangoapps/auth/tests/test_authz.py
+4
-3
cms/djangoapps/contentstore/management/commands/check_course.py
+11
-2
cms/djangoapps/contentstore/tests/test_contentstore.py
+0
-0
cms/djangoapps/contentstore/tests/test_utils.py
+4
-11
cms/djangoapps/contentstore/utils.py
+2
-2
cms/djangoapps/contentstore/views/access.py
+2
-18
cms/djangoapps/contentstore/views/course.py
+1
-1
No files found.
cms/djangoapps/auth/tests/__init__.py
0 → 100644
View file @
ec55d8c1
cms/djangoapps/auth/tests/test_authz.py
View file @
ec55d8c1
...
...
@@ -5,6 +5,7 @@ import mock
from
django.test
import
TestCase
from
django.contrib.auth.models
import
User
from
xmodule.modulestore
import
Location
from
django.core.exceptions
import
PermissionDenied
from
auth.authz
import
add_user_to_creator_group
,
remove_user_from_creator_group
,
is_user_in_creator_group
,
\
...
...
@@ -129,7 +130,7 @@ class CourseGroupTest(TestCase):
""" Test case setup """
self
.
creator
=
User
.
objects
.
create_user
(
'testcreator'
,
'testcreator+courses@edx.org'
,
'foo'
)
self
.
staff
=
User
.
objects
.
create_user
(
'teststaff'
,
'teststaff+courses@edx.org'
,
'foo'
)
self
.
location
=
'i4x'
,
'mitX'
,
'101'
,
'course'
,
'test'
self
.
location
=
Location
(
'i4x'
,
'mitX'
,
'101'
,
'course'
,
'test'
)
def
test_add_user_to_course_group
(
self
):
"""
...
...
@@ -181,7 +182,7 @@ class CourseGroupTest(TestCase):
create_all_course_groups
(
self
.
creator
,
self
.
location
)
add_user_to_course_group
(
self
.
creator
,
self
.
staff
,
self
.
location
,
STAFF_ROLE_NAME
)
location2
=
'i4x'
,
'mitX'
,
'103'
,
'course'
,
'test2'
location2
=
Location
(
'i4x'
,
'mitX'
,
'103'
,
'course'
,
'test2'
)
staff2
=
User
.
objects
.
create_user
(
'teststaff2'
,
'teststaff2+courses@edx.org'
,
'foo'
)
create_all_course_groups
(
self
.
creator
,
location2
)
add_user_to_course_group
(
self
.
creator
,
staff2
,
location2
,
STAFF_ROLE_NAME
)
...
...
@@ -193,7 +194,7 @@ class CourseGroupTest(TestCase):
create_all_course_groups
(
self
.
creator
,
self
.
location
)
add_user_to_course_group
(
self
.
creator
,
self
.
staff
,
self
.
location
,
STAFF_ROLE_NAME
)
location2
=
'i4x'
,
'mitX'
,
'103'
,
'course'
,
'test2'
location2
=
Location
(
'i4x'
,
'mitX'
,
'103'
,
'course'
,
'test2'
)
creator2
=
User
.
objects
.
create_user
(
'testcreator2'
,
'testcreator2+courses@edx.org'
,
'foo'
)
staff2
=
User
.
objects
.
create_user
(
'teststaff2'
,
'teststaff2+courses@edx.org'
,
'foo'
)
create_all_course_groups
(
creator2
,
location2
)
...
...
cms/djangoapps/contentstore/management/commands/check_course.py
View file @
ec55d8c1
...
...
@@ -2,6 +2,7 @@ from django.core.management.base import BaseCommand, CommandError
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.xml_importer
import
check_module_metadata_editability
from
xmodule.course_module
import
CourseDescriptor
from
xmodule.modulestore
import
Location
class
Command
(
BaseCommand
):
...
...
@@ -54,8 +55,16 @@ class Command(BaseCommand):
discussion_items
=
_get_discussion_items
(
course
)
# now query all discussion items via get_items() and compare with the tree-traversal
queried_discussion_items
=
store
.
get_items
([
'i4x'
,
course
.
location
.
org
,
course
.
location
.
course
,
'discussion'
,
None
,
None
])
queried_discussion_items
=
store
.
get_items
(
Location
(
'i4x'
,
course
.
location
.
org
,
course
.
location
.
course
,
'discussion'
,
None
,
None
)
)
for
item
in
queried_discussion_items
:
if
item
.
location
.
url
()
not
in
discussion_items
:
...
...
cms/djangoapps/contentstore/tests/test_contentstore.py
View file @
ec55d8c1
This diff is collapsed.
Click to expand it.
cms/djangoapps/contentstore/tests/test_utils.py
View file @
ec55d8c1
""" Tests for utils. """
from
contentstore
import
utils
import
mock
import
unittest
import
collections
import
copy
import
json
from
uuid
import
uuid4
from
django.test
import
TestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
django.test.utils
import
override_settings
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
xmodule.contentstore.content
import
StaticContent
from
xmodule.contentstore.django
import
contentstore
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
xmodule.exceptions
import
NotFoundError
from
xmodule.modulestore
import
Location
class
LMSLinksTestCase
(
TestCase
):
...
...
@@ -64,12 +57,12 @@ class LMSLinksTestCase(TestCase):
def
get_about_page_link
(
self
):
""" create mock course and return the about page link """
location
=
'i4x'
,
'mitX'
,
'101'
,
'course'
,
'test'
location
=
Location
(
'i4x'
,
'mitX'
,
'101'
,
'course'
,
'test'
)
return
utils
.
get_lms_link_for_about_page
(
location
)
def
lms_link_test
(
self
):
""" Tests get_lms_link_for_item. """
location
=
'i4x'
,
'mitX'
,
'101'
,
'vertical'
,
'contacting_us'
location
=
Location
(
'i4x'
,
'mitX'
,
'101'
,
'vertical'
,
'contacting_us'
)
link
=
utils
.
get_lms_link_for_item
(
location
,
False
,
"mitX/101/test"
)
self
.
assertEquals
(
link
,
"//localhost:8000/courses/mitX/101/test/jump_to/i4x://mitX/101/vertical/contacting_us"
)
link
=
utils
.
get_lms_link_for_item
(
location
,
True
,
"mitX/101/test"
)
...
...
@@ -80,7 +73,7 @@ class LMSLinksTestCase(TestCase):
# If no course_id is passed in, it is obtained from the location. This is the case for
# Studio dashboard.
location
=
'i4x'
,
'mitX'
,
'101'
,
'course'
,
'test'
location
=
Location
(
'i4x'
,
'mitX'
,
'101'
,
'course'
,
'test'
)
link
=
utils
.
get_lms_link_for_item
(
location
)
self
.
assertEquals
(
link
,
...
...
cms/djangoapps/contentstore/utils.py
View file @
ec55d8c1
...
...
@@ -79,7 +79,7 @@ def get_course_location_for_item(location):
# @hack! We need to find the course location however, we don't
# know the 'name' parameter in this context, so we have
# to assume there's only one item in this query even though we are not specifying a name
course_search_location
=
[
'i4x'
,
item_loc
.
org
,
item_loc
.
course
,
'course'
,
None
]
course_search_location
=
Location
(
'i4x'
,
item_loc
.
org
,
item_loc
.
course
,
'course'
,
None
)
courses
=
modulestore
()
.
get_items
(
course_search_location
)
# make sure we found exactly one match on this above course search
...
...
@@ -107,7 +107,7 @@ def get_course_for_item(location):
# @hack! We need to find the course location however, we don't
# know the 'name' parameter in this context, so we have
# to assume there's only one item in this query even though we are not specifying a name
course_search_location
=
[
'i4x'
,
item_loc
.
org
,
item_loc
.
course
,
'course'
,
None
]
course_search_location
=
Location
(
'i4x'
,
item_loc
.
org
,
item_loc
.
course
,
'course'
,
None
)
courses
=
modulestore
()
.
get_items
(
course_search_location
)
# make sure we found exactly one match on this above course search
...
...
cms/djangoapps/contentstore/views/access.py
View file @
ec55d8c1
from
auth.authz
import
STAFF_ROLE_NAME
,
INSTRUCTOR_ROLE_NAME
from
auth.authz
import
is_user_in_course_group_role
from
django.core.exceptions
import
PermissionDenied
from
..utils
import
get_course_location_for_item
from
xmodule.modulestore
import
Location
from
xmodule.modulestore.locator
import
CourseLocator
def
get_location_and_verify_access
(
request
,
org
,
course
,
name
):
"""
Create the location, verify that the user has permissions
to view the location. Returns the location as a Location
"""
location
=
[
'i4x'
,
org
,
course
,
'course'
,
name
]
# check that logged in user has permissions to this item
if
not
has_access
(
request
.
user
,
location
):
raise
PermissionDenied
()
return
Location
(
location
)
def
has_access
(
user
,
location
,
role
=
STAFF_ROLE_NAME
):
'''
"""
Return True if user allowed to access this piece of data
Note that the CMS permissions model is with respect to courses
There is a super-admin permissions if user.is_staff is set
...
...
@@ -29,7 +13,7 @@ def has_access(user, location, role=STAFF_ROLE_NAME):
I'm presuming that the course instructor (formally known as admin)
will not be in both INSTRUCTOR and STAFF groups, so we have to cascade our
queries here as INSTRUCTOR has all the rights that STAFF do
'''
"""
if
not
isinstance
(
location
,
CourseLocator
):
location
=
get_course_location_for_item
(
location
)
_has_access
=
is_user_in_course_group_role
(
user
,
location
,
role
)
...
...
cms/djangoapps/contentstore/views/course.py
View file @
ec55d8c1
...
...
@@ -128,7 +128,7 @@ def course_listing(request):
"""
List all courses available to the logged in user
"""
courses
=
modulestore
(
'direct'
)
.
get_items
(
[
'i4x'
,
None
,
None
,
'course'
,
None
]
)
courses
=
modulestore
(
'direct'
)
.
get_items
(
Location
(
'i4x'
,
None
,
None
,
'course'
,
None
)
)
# filter out courses that we don't have access too
def
course_filter
(
course
):
...
...
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