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
985417fc
Commit
985417fc
authored
Dec 11, 2013
by
Don Mitchell
Committed by
Adam Palay
Dec 12, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Auth converting to new course_id syntax
parent
0d593010
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
11 deletions
+34
-11
lms/djangoapps/courseware/roles.py
+34
-11
No files found.
lms/djangoapps/courseware/roles.py
View file @
985417fc
...
...
@@ -8,6 +8,9 @@ from abc import ABCMeta, abstractmethod
from
django.contrib.auth.models
import
User
,
Group
from
xmodule.modulestore
import
Location
from
xmodule.modulestore.exceptions
import
InvalidLocationError
,
ItemNotFoundError
from
xmodule.modulestore.django
import
loc_mapper
from
xmodule.modulestore.locator
import
CourseLocator
class
CourseContextRequired
(
Exception
):
...
...
@@ -134,20 +137,40 @@ class CourseRole(GroupBasedRole):
A named role in a particular course
"""
def
__init__
(
self
,
role
,
location
,
course_context
=
None
):
# pylint: disable=no-member
loc
=
Location
(
location
)
legacy_group_name
=
'{0}_{1}'
.
format
(
role
,
loc
.
course
)
if
loc
.
category
.
lower
()
==
'course'
:
course_id
=
loc
.
course_id
else
:
# TODO: figure out how to make the group name generation lazy so it doesn't force the
# loc mapping?
if
not
hasattr
(
location
,
'course_id'
):
location
=
Location
(
location
)
# direct copy from auth.authz.get_all_course_role_groupnames will refactor to one impl asap
groupnames
=
[]
try
:
groupnames
.
append
(
'{0}_{1}'
.
format
(
role
,
location
.
course_id
))
except
InvalidLocationError
:
# will occur on old locations where location is not of category course
if
course_context
is
None
:
raise
CourseContextRequired
()
course_id
=
course_context
else
:
groupnames
.
append
(
'{0}_{1}'
.
format
(
role
,
course_context
))
group_name
=
'{0}_{1}'
.
format
(
role
,
course_id
)
super
(
CourseRole
,
self
)
.
__init__
([
group_name
,
legacy_group_name
])
# pylint: disable=no-member
if
isinstance
(
location
,
Location
):
# least preferred legacy role_course format
groupnames
.
append
(
'{0}_{1}'
.
format
(
role
,
location
.
course
))
try
:
locator
=
loc_mapper
()
.
translate_location
(
location
.
course_id
,
location
,
False
,
False
)
groupnames
.
append
(
'{0}_{1}'
.
format
(
role
,
locator
.
course_id
))
except
(
InvalidLocationError
,
ItemNotFoundError
):
# if it's never been mapped, the auth won't be via the Locator syntax
pass
elif
isinstance
(
location
,
CourseLocator
):
# handle old Location syntax
old_location
=
loc_mapper
()
.
translate_locator_to_location
(
location
,
get_course
=
True
)
if
old_location
:
# the slashified version of the course_id (myu/mycourse/myrun)
groupnames
.
append
(
'{0}_{1}'
.
format
(
role
,
old_location
.
course_id
))
# add the least desirable but sometimes occurring format.
groupnames
.
append
(
'{0}_{1}'
.
format
(
role
,
old_location
.
course
))
super
(
CourseRole
,
self
)
.
__init__
(
groupnames
)
class
OrgRole
(
GroupBasedRole
):
...
...
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