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
e6384b92
Commit
e6384b92
authored
Sep 23, 2014
by
Martyn James
Committed by
Jonathan Piacenti
Aug 20, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added new assistant role
parent
79405d9a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
10 deletions
+43
-10
common/djangoapps/student/roles.py
+8
-0
common/djangoapps/student/tests/test_authz.py
+17
-1
lms/djangoapps/api_manager/courses/views.py
+9
-4
lms/djangoapps/api_manager/users/views.py
+7
-5
lms/djangoapps/instructor/access.py
+2
-0
No files found.
common/djangoapps/student/roles.py
View file @
e6384b92
...
@@ -273,6 +273,14 @@ class CourseBetaTesterRole(CourseRole):
...
@@ -273,6 +273,14 @@ class CourseBetaTesterRole(CourseRole):
super
(
CourseBetaTesterRole
,
self
)
.
__init__
(
self
.
ROLE
,
*
args
,
**
kwargs
)
super
(
CourseBetaTesterRole
,
self
)
.
__init__
(
self
.
ROLE
,
*
args
,
**
kwargs
)
class
CourseAssistantRole
(
CourseRole
):
"""A course assistant"""
ROLE
=
'assistant'
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
CourseAssistantRole
,
self
)
.
__init__
(
self
.
ROLE
,
*
args
,
**
kwargs
)
@register_access_role
@register_access_role
class
LibraryUserRole
(
CourseRole
):
class
LibraryUserRole
(
CourseRole
):
"""
"""
...
...
common/djangoapps/student/tests/test_authz.py
View file @
e6384b92
...
@@ -7,7 +7,7 @@ from django.test import TestCase
...
@@ -7,7 +7,7 @@ from django.test import TestCase
from
django.contrib.auth.models
import
User
,
AnonymousUser
from
django.contrib.auth.models
import
User
,
AnonymousUser
from
django.core.exceptions
import
PermissionDenied
from
django.core.exceptions
import
PermissionDenied
from
student.roles
import
CourseInstructorRole
,
CourseStaffRole
,
CourseCreatorRole
from
student.roles
import
CourseInstructorRole
,
CourseStaffRole
,
CourseCreatorRole
,
CourseAssistantRole
from
student.tests.factories
import
AdminFactory
from
student.tests.factories
import
AdminFactory
from
student.auth
import
has_access
,
add_users
,
remove_users
from
student.auth
import
has_access
,
add_users
,
remove_users
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
...
@@ -143,6 +143,7 @@ class CourseGroupTest(TestCase):
...
@@ -143,6 +143,7 @@ class CourseGroupTest(TestCase):
self
.
global_admin
=
AdminFactory
()
self
.
global_admin
=
AdminFactory
()
self
.
creator
=
User
.
objects
.
create_user
(
'testcreator'
,
'testcreator+courses@edx.org'
,
'foo'
)
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
.
staff
=
User
.
objects
.
create_user
(
'teststaff'
,
'teststaff+courses@edx.org'
,
'foo'
)
self
.
assistant
=
User
.
objects
.
create_user
(
'testassistant'
,
'testta+courses@edx.org'
,
'foo'
)
self
.
course_key
=
SlashSeparatedCourseKey
(
'mitX'
,
'101'
,
'test'
)
self
.
course_key
=
SlashSeparatedCourseKey
(
'mitX'
,
'101'
,
'test'
)
def
test_add_user_to_course_group
(
self
):
def
test_add_user_to_course_group
(
self
):
...
@@ -160,6 +161,11 @@ class CourseGroupTest(TestCase):
...
@@ -160,6 +161,11 @@ class CourseGroupTest(TestCase):
add_users
(
self
.
creator
,
CourseStaffRole
(
self
.
course_key
),
self
.
staff
)
add_users
(
self
.
creator
,
CourseStaffRole
(
self
.
course_key
),
self
.
staff
)
self
.
assertTrue
(
has_access
(
self
.
staff
,
CourseStaffRole
(
self
.
course_key
)))
self
.
assertTrue
(
has_access
(
self
.
staff
,
CourseStaffRole
(
self
.
course_key
)))
# Add another user to the TA role
self
.
assertFalse
(
has_access
(
self
.
assistant
,
CourseAssistantRole
(
self
.
course_key
)))
add_users
(
self
.
creator
,
CourseAssistantRole
(
self
.
course_key
),
self
.
assistant
)
self
.
assertTrue
(
has_access
(
self
.
assistant
,
CourseAssistantRole
(
self
.
course_key
)))
def
test_add_user_to_course_group_permission_denied
(
self
):
def
test_add_user_to_course_group_permission_denied
(
self
):
"""
"""
Verifies PermissionDenied if caller of add_user_to_course_group is not instructor role.
Verifies PermissionDenied if caller of add_user_to_course_group is not instructor role.
...
@@ -168,6 +174,8 @@ class CourseGroupTest(TestCase):
...
@@ -168,6 +174,8 @@ class CourseGroupTest(TestCase):
add_users
(
self
.
global_admin
,
CourseStaffRole
(
self
.
course_key
),
self
.
creator
)
add_users
(
self
.
global_admin
,
CourseStaffRole
(
self
.
course_key
),
self
.
creator
)
with
self
.
assertRaises
(
PermissionDenied
):
with
self
.
assertRaises
(
PermissionDenied
):
add_users
(
self
.
staff
,
CourseStaffRole
(
self
.
course_key
),
self
.
staff
)
add_users
(
self
.
staff
,
CourseStaffRole
(
self
.
course_key
),
self
.
staff
)
with
self
.
assertRaises
(
PermissionDenied
):
add_users
(
self
.
assistant
,
CourseAssistantRole
(
self
.
course_key
),
self
.
assistant
)
def
test_remove_user_from_course_group
(
self
):
def
test_remove_user_from_course_group
(
self
):
"""
"""
...
@@ -182,6 +190,12 @@ class CourseGroupTest(TestCase):
...
@@ -182,6 +190,12 @@ class CourseGroupTest(TestCase):
remove_users
(
self
.
creator
,
CourseStaffRole
(
self
.
course_key
),
self
.
staff
)
remove_users
(
self
.
creator
,
CourseStaffRole
(
self
.
course_key
),
self
.
staff
)
self
.
assertFalse
(
has_access
(
self
.
staff
,
CourseStaffRole
(
self
.
course_key
)))
self
.
assertFalse
(
has_access
(
self
.
staff
,
CourseStaffRole
(
self
.
course_key
)))
add_users
(
self
.
creator
,
CourseAssistantRole
(
self
.
course_key
),
self
.
assistant
)
self
.
assertTrue
(
has_access
(
self
.
assistant
,
CourseAssistantRole
(
self
.
course_key
)))
remove_users
(
self
.
creator
,
CourseAssistantRole
(
self
.
course_key
),
self
.
assistant
)
self
.
assertFalse
(
has_access
(
self
.
assistant
,
CourseAssistantRole
(
self
.
course_key
)))
remove_users
(
self
.
creator
,
CourseInstructorRole
(
self
.
course_key
),
self
.
creator
)
remove_users
(
self
.
creator
,
CourseInstructorRole
(
self
.
course_key
),
self
.
creator
)
self
.
assertFalse
(
has_access
(
self
.
creator
,
CourseInstructorRole
(
self
.
course_key
)))
self
.
assertFalse
(
has_access
(
self
.
creator
,
CourseInstructorRole
(
self
.
course_key
)))
...
@@ -194,3 +208,5 @@ class CourseGroupTest(TestCase):
...
@@ -194,3 +208,5 @@ class CourseGroupTest(TestCase):
add_users
(
self
.
global_admin
,
CourseStaffRole
(
self
.
course_key
),
self
.
creator
,
self
.
staff
,
another_staff
)
add_users
(
self
.
global_admin
,
CourseStaffRole
(
self
.
course_key
),
self
.
creator
,
self
.
staff
,
another_staff
)
with
self
.
assertRaises
(
PermissionDenied
):
with
self
.
assertRaises
(
PermissionDenied
):
remove_users
(
self
.
staff
,
CourseStaffRole
(
self
.
course_key
),
another_staff
)
remove_users
(
self
.
staff
,
CourseStaffRole
(
self
.
course_key
),
another_staff
)
with
self
.
assertRaises
(
PermissionDenied
):
remove_users
(
self
.
assistant
,
CourseAssistantRole
(
self
.
course_key
),
another_staff
)
lms/djangoapps/api_manager/courses/views.py
View file @
e6384b92
...
@@ -25,7 +25,7 @@ from django_comment_common.models import FORUM_ROLE_MODERATOR
...
@@ -25,7 +25,7 @@ from django_comment_common.models import FORUM_ROLE_MODERATOR
from
gradebook.models
import
StudentGradebook
from
gradebook.models
import
StudentGradebook
from
instructor.access
import
revoke_access
,
update_forum_role
from
instructor.access
import
revoke_access
,
update_forum_role
from
student.models
import
CourseEnrollment
,
CourseEnrollmentAllowed
from
student.models
import
CourseEnrollment
,
CourseEnrollmentAllowed
from
student.roles
import
CourseRole
,
CourseAccessRole
,
CourseInstructorRole
,
CourseStaffRole
,
CourseObserverRole
,
UserBasedRole
from
student.roles
import
CourseRole
,
CourseAccessRole
,
CourseInstructorRole
,
CourseStaffRole
,
CourseObserverRole
,
CourseAssistantRole
,
UserBasedRole
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
...
@@ -289,8 +289,8 @@ def _manage_role(course_descriptor, user, role, action):
...
@@ -289,8 +289,8 @@ def _manage_role(course_descriptor, user, role, action):
"""
"""
Helper method for managing course/forum roles
Helper method for managing course/forum roles
"""
"""
supported_roles
=
(
'instructor'
,
'staff'
,
'observer'
)
supported_roles
=
(
'instructor'
,
'staff'
,
'observer'
,
'assistant'
)
forum_moderator_roles
=
(
'instructor'
,
'staff'
)
forum_moderator_roles
=
(
'instructor'
,
'staff'
,
'assistant'
)
if
role
not
in
supported_roles
:
if
role
not
in
supported_roles
:
raise
ValueError
raise
ValueError
if
action
is
'allow'
:
if
action
is
'allow'
:
...
@@ -309,7 +309,8 @@ def _manage_role(course_descriptor, user, role, action):
...
@@ -309,7 +309,8 @@ def _manage_role(course_descriptor, user, role, action):
# Before we can safely remove the corresponding forum moderator role
# Before we can safely remove the corresponding forum moderator role
user_instructor_courses
=
UserBasedRole
(
user
,
CourseInstructorRole
.
ROLE
)
.
courses_with_role
()
user_instructor_courses
=
UserBasedRole
(
user
,
CourseInstructorRole
.
ROLE
)
.
courses_with_role
()
user_staff_courses
=
UserBasedRole
(
user
,
CourseStaffRole
.
ROLE
)
.
courses_with_role
()
user_staff_courses
=
UserBasedRole
(
user
,
CourseStaffRole
.
ROLE
)
.
courses_with_role
()
queryset
=
user_instructor_courses
|
user_staff_courses
user_assistant_courses
=
UserBasedRole
(
user
,
CourseAssistantRole
.
ROLE
)
.
courses_with_role
()
queryset
=
user_instructor_courses
|
user_staff_courses
|
user_assistant_courses
queryset
=
queryset
.
filter
(
course_id
=
course_descriptor
.
id
)
queryset
=
queryset
.
filter
(
course_id
=
course_descriptor
.
id
)
if
len
(
queryset
)
==
0
:
if
len
(
queryset
)
==
0
:
update_forum_role
(
course_descriptor
.
id
,
user
,
FORUM_ROLE_MODERATOR
,
'revoke'
)
update_forum_role
(
course_descriptor
.
id
,
user
,
FORUM_ROLE_MODERATOR
,
'revoke'
)
...
@@ -1768,6 +1769,10 @@ class CoursesRolesList(SecureAPIView):
...
@@ -1768,6 +1769,10 @@ class CoursesRolesList(SecureAPIView):
for
observer
in
observers
:
for
observer
in
observers
:
response_data
.
append
({
'id'
:
observer
.
id
,
'role'
:
'observer'
})
response_data
.
append
({
'id'
:
observer
.
id
,
'role'
:
'observer'
})
assistants
=
CourseAssistantRole
(
course_key
)
.
users_with_role
()
for
assistant
in
assistants
:
response_data
.
append
({
'id'
:
assistant
.
id
,
'role'
:
'assistant'
})
user_id
=
self
.
request
.
QUERY_PARAMS
.
get
(
'user_id'
,
None
)
user_id
=
self
.
request
.
QUERY_PARAMS
.
get
(
'user_id'
,
None
)
if
user_id
:
if
user_id
:
response_data
=
list
([
item
for
item
in
response_data
if
int
(
item
[
'id'
])
==
int
(
user_id
)])
response_data
=
list
([
item
for
item
in
response_data
if
int
(
item
[
'id'
])
==
int
(
user_id
)])
...
...
lms/djangoapps/api_manager/users/views.py
View file @
e6384b92
...
@@ -26,7 +26,7 @@ from lms.lib.comment_client.utils import CommentClientRequestError
...
@@ -26,7 +26,7 @@ from lms.lib.comment_client.utils import CommentClientRequestError
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
from
student.models
import
CourseEnrollment
,
PasswordHistory
,
UserProfile
from
student.models
import
CourseEnrollment
,
PasswordHistory
,
UserProfile
from
openedx.core.djangoapps.user_api.models
import
UserPreference
from
openedx.core.djangoapps.user_api.models
import
UserPreference
from
student.roles
import
CourseAccessRole
,
CourseInstructorRole
,
CourseObserverRole
,
CourseStaffRole
,
UserBasedRole
from
student.roles
import
CourseAccessRole
,
CourseInstructorRole
,
CourseObserverRole
,
CourseStaffRole
,
CourseAssistantRole
,
UserBasedRole
from
util.bad_request_rate_limiter
import
BadRequestRateLimiter
from
util.bad_request_rate_limiter
import
BadRequestRateLimiter
from
util.password_policy_validators
import
(
from
util.password_policy_validators
import
(
validate_password_length
,
validate_password_complexity
,
validate_password_length
,
validate_password_complexity
,
...
@@ -132,8 +132,8 @@ def _manage_role(course_descriptor, user, role, action):
...
@@ -132,8 +132,8 @@ def _manage_role(course_descriptor, user, role, action):
"""
"""
Helper method for managing course/forum roles
Helper method for managing course/forum roles
"""
"""
supported_roles
=
(
'instructor'
,
'staff'
,
'observer'
)
supported_roles
=
(
'instructor'
,
'staff'
,
'observer'
,
'assistant'
)
forum_moderator_roles
=
(
'instructor'
,
'staff'
)
forum_moderator_roles
=
(
'instructor'
,
'staff'
,
'assistant'
)
if
role
not
in
supported_roles
:
if
role
not
in
supported_roles
:
raise
ValueError
raise
ValueError
if
action
is
'allow'
:
if
action
is
'allow'
:
...
@@ -161,7 +161,8 @@ def _manage_role(course_descriptor, user, role, action):
...
@@ -161,7 +161,8 @@ def _manage_role(course_descriptor, user, role, action):
# Before we can safely remove the corresponding forum moderator role
# Before we can safely remove the corresponding forum moderator role
user_instructor_courses
=
UserBasedRole
(
user
,
CourseInstructorRole
.
ROLE
)
.
courses_with_role
()
user_instructor_courses
=
UserBasedRole
(
user
,
CourseInstructorRole
.
ROLE
)
.
courses_with_role
()
user_staff_courses
=
UserBasedRole
(
user
,
CourseStaffRole
.
ROLE
)
.
courses_with_role
()
user_staff_courses
=
UserBasedRole
(
user
,
CourseStaffRole
.
ROLE
)
.
courses_with_role
()
queryset
=
user_instructor_courses
|
user_staff_courses
user_assistant_courses
=
UserBasedRole
(
user
,
CourseAssistantRole
.
ROLE
)
.
courses_with_role
()
queryset
=
user_instructor_courses
|
user_staff_courses
|
user_assistant_courses
queryset
=
queryset
.
filter
(
course_id
=
course_descriptor
.
id
)
queryset
=
queryset
.
filter
(
course_id
=
course_descriptor
.
id
)
if
len
(
queryset
)
==
0
:
if
len
(
queryset
)
==
0
:
try
:
try
:
...
@@ -1221,7 +1222,8 @@ class UsersRolesList(SecureListAPIView):
...
@@ -1221,7 +1222,8 @@ class UsersRolesList(SecureListAPIView):
instructor_courses
=
UserBasedRole
(
user
,
CourseInstructorRole
.
ROLE
)
.
courses_with_role
()
instructor_courses
=
UserBasedRole
(
user
,
CourseInstructorRole
.
ROLE
)
.
courses_with_role
()
staff_courses
=
UserBasedRole
(
user
,
CourseStaffRole
.
ROLE
)
.
courses_with_role
()
staff_courses
=
UserBasedRole
(
user
,
CourseStaffRole
.
ROLE
)
.
courses_with_role
()
observer_courses
=
UserBasedRole
(
user
,
CourseObserverRole
.
ROLE
)
.
courses_with_role
()
observer_courses
=
UserBasedRole
(
user
,
CourseObserverRole
.
ROLE
)
.
courses_with_role
()
queryset
=
instructor_courses
|
staff_courses
|
observer_courses
assistant_courses
=
UserBasedRole
(
user
,
CourseAssistantRole
.
ROLE
)
.
courses_with_role
()
queryset
=
instructor_courses
|
staff_courses
|
observer_courses
|
assistant_courses
course_id
=
self
.
request
.
QUERY_PARAMS
.
get
(
'course_id'
,
None
)
course_id
=
self
.
request
.
QUERY_PARAMS
.
get
(
'course_id'
,
None
)
if
course_id
:
if
course_id
:
...
...
lms/djangoapps/instructor/access.py
View file @
e6384b92
...
@@ -18,6 +18,7 @@ from student.roles import (
...
@@ -18,6 +18,7 @@ from student.roles import (
CourseCcxCoachRole
,
CourseCcxCoachRole
,
CourseStaffRole
,
CourseStaffRole
,
CourseObserverRole
,
CourseObserverRole
,
CourseAssistantRole
,
)
)
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
...
@@ -28,6 +29,7 @@ ROLES = {
...
@@ -28,6 +29,7 @@ ROLES = {
'observer'
:
CourseObserverRole
,
'observer'
:
CourseObserverRole
,
'staff'
:
CourseStaffRole
,
'staff'
:
CourseStaffRole
,
'ccx_coach'
:
CourseCcxCoachRole
,
'ccx_coach'
:
CourseCcxCoachRole
,
'assistant'
:
CourseAssistantRole
,
}
}
...
...
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