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
8533fd97
Unverified
Commit
8533fd97
authored
Jul 29, 2016
by
Jesse Shapiro
Committed by
Brandon DeRosier
Oct 07, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding change to staff role for new users and draft migration
parent
20fc5bae
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
82 additions
and
14 deletions
+82
-14
common/djangoapps/student/roles.py
+2
-2
lms/djangoapps/ccx/api/v0/views.py
+3
-3
lms/djangoapps/ccx/migrations/0004_change_ccx_coach_to_staff.py
+67
-0
lms/djangoapps/ccx/utils.py
+6
-6
lms/djangoapps/ccx/views.py
+4
-3
No files found.
common/djangoapps/student/roles.py
View file @
8533fd97
...
...
@@ -153,7 +153,7 @@ class RoleBase(AccessRole):
# legit get updated.
from
student.models
import
CourseAccessRole
for
user
in
users
:
if
user
.
is_authenticated
and
user
.
is_active
and
not
self
.
has_user
(
user
):
if
user
.
is_authenticated
()
and
user
.
is_active
and
not
self
.
has_user
(
user
):
entry
=
CourseAccessRole
(
user
=
user
,
role
=
self
.
_role_name
,
course_id
=
self
.
course_key
,
org
=
self
.
org
)
entry
.
save
()
if
hasattr
(
user
,
'_roles'
):
...
...
@@ -349,7 +349,7 @@ class UserBasedRole(object):
"""
Grant this object's user the object's role for the supplied courses
"""
if
self
.
user
.
is_authenticated
and
self
.
user
.
is_active
:
if
self
.
user
.
is_authenticated
()
and
self
.
user
.
is_active
:
for
course_key
in
course_keys
:
entry
=
CourseAccessRole
(
user
=
self
.
user
,
role
=
self
.
role
,
course_id
=
course_key
,
org
=
course_key
.
org
)
entry
.
save
()
...
...
lms/djangoapps/ccx/api/v0/views.py
View file @
8533fd97
...
...
@@ -37,7 +37,7 @@ from lms.djangoapps.ccx.overrides import (
)
from
lms.djangoapps.ccx.utils
import
(
add_master_course_staff_to_ccx
,
assign_
coach
_role_to_ccx
,
assign_
staff
_role_to_ccx
,
is_email
,
get_course_chapters
,
)
...
...
@@ -507,8 +507,8 @@ class CCXListView(GenericAPIView):
email_students
=
True
,
email_params
=
email_params
,
)
# assign
coach
role for the coach to the newly created ccx
assign_
coach
_role_to_ccx
(
ccx_course_key
,
coach
,
master_course_object
.
id
)
# assign
staff
role for the coach to the newly created ccx
assign_
staff
_role_to_ccx
(
ccx_course_key
,
coach
,
master_course_object
.
id
)
# assign staff role for all the staff and instructor of the master course to the newly created ccx
add_master_course_staff_to_ccx
(
master_course_object
,
...
...
lms/djangoapps/ccx/migrations/0004_change_ccx_coach_to_staff.py
0 → 100644
View file @
8533fd97
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
# We're doing something awful here, but it's necessary for the greater good:
from
django.contrib.auth.models
import
User
from
instructor.access
import
allow_access
,
revoke_access
from
ccx_keys.locator
import
CCXLocator
from
lms.djangoapps.ccx.utils
import
ccx_course
def
change_existing_ccx_coaches_to_staff
(
apps
,
schema_editor
):
"""
Modify all coaches of CCX courses so that they have the staff role on the
CCX course they coach, but retain the CCX Coach role on the parent course.
Arguments:
apps (Applications): Apps in edX platform.
schema_editor (SchemaEditor): For editing database schema (unused)
"""
CustomCourseForEdX
=
apps
.
get_model
(
'ccx'
,
'CustomCourseForEdX'
)
db_alias
=
schema_editor
.
connection
.
alias
list_ccx
=
CustomCourseForEdX
.
objects
.
using
(
db_alias
)
.
all
()
for
ccx
in
list_ccx
:
ccx_locator
=
CCXLocator
.
from_course_locator
(
ccx
.
course_id
,
unicode
(
ccx
.
id
))
with
ccx_course
(
ccx_locator
)
as
course
:
coach
=
User
.
objects
.
get
(
id
=
ccx
.
coach
.
id
)
allow_access
(
course
,
coach
,
'staff'
,
send_email
=
False
)
revoke_access
(
course
,
coach
,
'ccx_coach'
,
send_email
=
False
)
def
revert_ccx_staff_to_coaches
(
apps
,
schema_editor
):
"""
Modify all staff on CCX courses so that they no longer have the staff role
on the course that they coach.
Arguments:
apps (Applications): Apps in edX platform.
schema_editor (SchemaEditor): For editing database schema (unused)
"""
CustomCourseForEdX
=
apps
.
get_model
(
'ccx'
,
'CustomCourseForEdX'
)
db_alias
=
schema_editor
.
connection
.
alias
list_ccx
=
CustomCourseForEdX
.
objects
.
using
(
db_alias
)
.
all
()
for
ccx
in
list_ccx
:
ccx_locator
=
CCXLocator
.
from_course_locator
(
ccx
.
course_id
,
unicode
(
ccx
.
id
))
with
ccx_course
(
ccx_locator
)
as
course
:
coach
=
User
.
objects
.
get
(
id
=
ccx
.
coach
.
id
)
allow_access
(
course
,
coach
,
'ccx_coach'
,
send_email
=
False
)
revoke_access
(
course
,
coach
,
'staff'
,
send_email
=
False
)
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'ccx'
,
'0001_initial'
),
(
'ccx'
,
'0002_customcourseforedx_structure_json'
),
(
'ccx'
,
'0003_add_master_course_staff_in_ccx'
),
]
operations
=
[
migrations
.
RunPython
(
code
=
change_existing_ccx_coaches_to_staff
,
reverse_code
=
revert_ccx_staff_to_coaches
)
]
lms/djangoapps/ccx/utils.py
View file @
8533fd97
...
...
@@ -292,9 +292,9 @@ def ccx_course(ccx_locator):
yield
course
def
assign_
coach
_role_to_ccx
(
ccx_locator
,
user
,
master_course_id
):
def
assign_
staff
_role_to_ccx
(
ccx_locator
,
user
,
master_course_id
):
"""
Check if user has ccx_coach role on master course then assign him
coach
role on ccx only
Check if user has ccx_coach role on master course then assign him
staff
role on ccx only
if role is not already assigned. Because of this coach can open dashboard from master course
as well as ccx.
:param ccx_locator: CCX key
...
...
@@ -304,12 +304,12 @@ def assign_coach_role_to_ccx(ccx_locator, user, master_course_id):
coach_role_on_master_course
=
CourseCcxCoachRole
(
master_course_id
)
# check if user has coach role on master course
if
coach_role_on_master_course
.
has_user
(
user
):
# Check if user has
coach
role on ccx.
role
=
Course
CcxCoach
Role
(
ccx_locator
)
# Check if user has
staff
role on ccx.
role
=
Course
Staff
Role
(
ccx_locator
)
if
not
role
.
has_user
(
user
):
# assign user
role coach
on ccx
# assign user
the staff role
on ccx
with
ccx_course
(
ccx_locator
)
as
course
:
allow_access
(
course
,
user
,
"
ccx_coach
"
,
send_email
=
False
)
allow_access
(
course
,
user
,
"
staff
"
,
send_email
=
False
)
def
is_email
(
identifier
):
...
...
lms/djangoapps/ccx/views.py
View file @
8533fd97
...
...
@@ -56,7 +56,7 @@ from lms.djangoapps.ccx.overrides import (
)
from
lms.djangoapps.ccx.utils
import
(
add_master_course_staff_to_ccx
,
assign_
coach
_role_to_ccx
,
assign_
staff
_role_to_ccx
,
ccx_course
,
ccx_students_enrolling_center
,
get_ccx_for_coach
,
...
...
@@ -147,7 +147,8 @@ def dashboard(request, course, ccx=None):
if
ccx
:
ccx_locator
=
CCXLocator
.
from_course_locator
(
course
.
id
,
unicode
(
ccx
.
id
))
# At this point we are done with verification that current user is ccx coach.
assign_staff_role_to_ccx
(
ccx_locator
,
request
.
user
,
course
.
id
)
schedule
=
get_ccx_schedule
(
course
,
ccx
)
grading_policy
=
get_override_for_ccx
(
ccx
,
course
,
'grading_policy'
,
course
.
grading_policy
)
...
...
@@ -239,7 +240,7 @@ def create_ccx(request, course, ccx=None):
email_params
=
email_params
,
)
assign_
coach
_role_to_ccx
(
ccx_id
,
request
.
user
,
course
.
id
)
assign_
staff
_role_to_ccx
(
ccx_id
,
request
.
user
,
course
.
id
)
add_master_course_staff_to_ccx
(
course
,
ccx_id
,
ccx
.
display_name
)
# using CCX object as sender here.
...
...
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