Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
e62705a3
Commit
e62705a3
authored
3 years ago
by
stvn
Browse files
Options
Downloads
Patches
Plain Diff
feat: Add support to Discussions API for legacy cohort settings
parent
1b76999c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
openedx/core/djangoapps/discussions/views.py
+34
-4
34 additions, 4 deletions
openedx/core/djangoapps/discussions/views.py
with
34 additions
and
4 deletions
openedx/core/djangoapps/discussions/views.py
+
34
−
4
View file @
e62705a3
...
...
@@ -12,6 +12,8 @@ from rest_framework.response import Response
from
rest_framework.views
import
APIView
from
common.djangoapps.student.roles
import
CourseStaffRole
from
lms.djangoapps.discussion.rest_api.serializers
import
DiscussionSettingsSerializer
from
openedx.core.djangoapps.django_comment_common.models
import
CourseDiscussionSettings
from
openedx.core.lib.api.authentication
import
BearerAuthenticationAllowInactiveUser
from
openedx.core.lib.courses
import
get_course_by_id
from
xmodule.modulestore.django
import
modulestore
...
...
@@ -111,7 +113,6 @@ class LegacySettingsSerializer(serializers.BaseSerializer):
payload
=
{
key
:
value
for
key
,
value
in
data
.
items
()
if
key
in
self
.
Meta
.
fields
}
return
payload
...
...
@@ -124,6 +125,20 @@ class LegacySettingsSerializer(serializers.BaseSerializer):
for
field
in
instance
.
fields
.
values
()
if
field
.
name
in
self
.
Meta
.
fields
}
discussion_settings
=
CourseDiscussionSettings
.
get
(
instance
.
id
)
serializer
=
DiscussionSettingsSerializer
(
discussion_settings
,
context
=
{
'
course
'
:
instance
,
'
settings
'
:
discussion_settings
,
},
partial
=
True
,
)
settings
.
update
({
key
:
value
for
key
,
value
in
serializer
.
data
.
items
()
if
key
!=
'
id
'
})
return
settings
def
update
(
self
,
instance
,
validated_data
:
dict
):
...
...
@@ -131,11 +146,26 @@ class LegacySettingsSerializer(serializers.BaseSerializer):
Update and save an existing instance
"""
save
=
False
for
field
in
self
.
Meta
.
fields
:
if
field
in
validated_data
:
value
=
validated_da
ta
[
field
]
cohort_settings
=
{}
for
field
,
value
in
validated_data
.
items
()
:
if
field
in
self
.
Me
ta
.
field
s
:
setattr
(
instance
,
field
,
value
)
save
=
True
else
:
cohort_settings
[
field
]
=
value
if
cohort_settings
:
discussion_settings
=
CourseDiscussionSettings
.
get
(
instance
.
id
)
serializer
=
DiscussionSettingsSerializer
(
discussion_settings
,
context
=
{
'
course
'
:
instance
,
'
settings
'
:
discussion_settings
,
},
data
=
cohort_settings
,
partial
=
True
,
)
if
serializer
.
is_valid
(
raise_exception
=
True
):
serializer
.
save
()
if
save
:
modulestore
().
update_item
(
instance
,
self
.
context
[
'
user_id
'
])
return
instance
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment