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
174c0175
Commit
174c0175
authored
6 years ago
by
Simon Chen
Browse files
Options
Downloads
Patches
Plain Diff
Implement retire users function in the SurveyAnswer model for GDPR
parent
2be587d3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lms/djangoapps/survey/models.py
+16
-2
16 additions, 2 deletions
lms/djangoapps/survey/models.py
lms/djangoapps/survey/tests/test_models.py
+25
-0
25 additions, 0 deletions
lms/djangoapps/survey/tests/test_models.py
with
41 additions
and
2 deletions
lms/djangoapps/survey/models.py
+
16
−
2
View file @
174c0175
...
...
@@ -239,8 +239,6 @@ class SurveyAnswer(TimeStampedModel):
supplied to this method is presumed to be previously validated
"""
for
name
in
answers
.
keys
():
value
=
answers
[
name
]
# See if there is an answer stored for this user, form, field_name pair or not
# this will allow for update cases. This does include an additional lookup,
# but write operations will be relatively infrequent
...
...
@@ -261,3 +259,19 @@ class SurveyAnswer(TimeStampedModel):
answer
.
field_value
=
value
answer
.
course_key
=
course_key
answer
.
save
()
@classmethod
def
retire_user
(
cls
,
user_id
):
"""
With the parameter user_id, blank out the survey answer values for all survey questions
This is to fulfill our GDPR obligations
Return True if there are data to be blanked
Return False if there are no matching data
"""
answers
=
cls
.
objects
.
filter
(
user
=
user_id
)
if
not
answers
:
return
False
answers
.
update
(
field_value
=
''
)
return
True
This diff is collapsed.
Click to expand it.
lms/djangoapps/survey/tests/test_models.py
+
25
−
0
View file @
174c0175
...
...
@@ -280,3 +280,28 @@ class SurveyModelsTests(TestCase):
names
=
survey
.
get_field_names
()
self
.
assertEqual
(
sorted
(
names
),
[
'
ddl
'
,
'
field1
'
,
'
field2
'
])
def
test_retire_user_successful
(
self
):
survey
=
self
.
_create_test_survey
()
self
.
assertIsNotNone
(
survey
)
survey
.
save_user_answers
(
self
.
student
,
self
.
student_answers
,
self
.
course_id
)
survey
.
save_user_answers
(
self
.
student2
,
self
.
student2_answers
,
self
.
course_id
)
retire_result
=
SurveyAnswer
.
retire_user
(
self
.
student
.
id
)
self
.
assertTrue
(
retire_result
)
answers
=
survey
.
get_answers
(
self
.
student
)
blanked_out_student_answser
=
{
key
:
''
for
key
in
self
.
student_answers
}
self
.
assertEquals
(
answers
[
self
.
student
.
id
],
blanked_out_student_answser
)
self
.
assertEquals
(
survey
.
get_answers
(
self
.
student2
)[
self
.
student2
.
id
],
self
.
student2_answers
)
def
test_retire_user_not_exist
(
self
):
survey
=
self
.
_create_test_survey
()
self
.
assertIsNotNone
(
survey
)
survey
.
save_user_answers
(
self
.
student
,
self
.
student_answers
,
self
.
course_id
)
retire_result
=
SurveyAnswer
.
retire_user
(
self
.
student2
.
id
)
self
.
assertFalse
(
retire_result
)
answers
=
survey
.
get_answers
(
self
.
student
)
self
.
assertEquals
(
answers
[
self
.
student
.
id
],
self
.
student_answers
)
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