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
403b6719
Commit
403b6719
authored
6 years ago
by
Sofiya Semenova
Browse files
Options
Downloads
Patches
Plain Diff
Management command to create GDPR test user
parent
26ab5959
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/user_api/management/commands/create_user_gdpr_testing.py
+197
-0
197 additions, 0 deletions
.../user_api/management/commands/create_user_gdpr_testing.py
with
197 additions
and
0 deletions
openedx/core/djangoapps/user_api/management/commands/create_user_gdpr_testing.py
0 → 100644
+
197
−
0
View file @
403b6719
"""
Create a user with GDPR P1 PII for manual testing.
Enrolls the user in the DemoX course.
Optionally takes in username, email, and course UUID arguments.
"""
from
__future__
import
unicode_literals
from
datetime
import
datetime
from
uuid
import
uuid4
from
pytz
import
UTC
from
django.core.management.base
import
BaseCommand
from
django.contrib.auth.models
import
User
from
consent.models
import
DataSharingConsent
from
enterprise.models
import
(
EnterpriseCourseEnrollment
,
EnterpriseCustomer
,
EnterpriseCustomerUser
,
PendingEnterpriseCustomerUser
,
)
from
entitlements.models
import
CourseEntitlement
,
CourseEntitlementSupportDetail
from
integrated_channels.sap_success_factors.models
import
SapSuccessFactorsLearnerDataTransmissionAudit
from
lms.djangoapps.verify_student.models
import
SoftwareSecurePhotoVerification
from
opaque_keys.edx.keys
import
CourseKey
from
openedx.core.djangoapps.course_groups.models
import
UnregisteredLearnerCohortAssignments
,
CourseUserGroup
from
openedx.core.djangoapps.profile_images.images
import
create_profile_images
from
openedx.core.djangoapps.profile_images.tests.helpers
import
make_image_file
from
student.models
import
(
CourseEnrollment
,
PendingEmailChange
,
UserProfile
,
CourseEnrollmentAllowed
)
from
...models
import
UserOrgTag
class
Command
(
BaseCommand
):
"""
Implementation of the create_user_gdpr_testing command.
"""
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'
-u
'
,
'
--username
'
,
nargs
=
1
,
required
=
False
,
help
=
'
Username
'
)
parser
.
add_argument
(
'
-e
'
,
'
--email
'
,
nargs
=
1
,
required
=
False
,
help
=
'
Email
'
)
parser
.
add_argument
(
'
-c
'
,
'
--course
'
,
nargs
=
1
,
required
=
False
,
help
=
'
Course UUID
'
)
def
handle
(
self
,
*
args
,
**
options
):
"""
Execute the command.
"""
username
=
options
[
'
username
'
]
if
options
[
'
username
'
]
else
'
gdpr_test_user
'
email
=
options
[
'
email
'
]
if
options
[
'
email
'
]
else
'
gdpr_test_user@example.com
'
course_uuid
=
options
[
'
course
'
]
if
options
[
'
course
'
]
else
uuid4
().
hex
user
,
__
=
User
.
objects
.
get_or_create
(
username
=
username
,
)
user_info
=
{
'
email
'
:
email
,
'
first_name
'
:
"
GDPR
"
,
'
last_name
'
:
"
Test
"
,
'
is_active
'
:
True
,
'
password
'
:
'
gdpr test password
'
}
for
field
,
value
in
user_info
.
items
():
setattr
(
user
,
field
,
value
)
user
.
save
()
# UserProfile
profile_image_uploaded_date
=
datetime
(
2018
,
5
,
3
,
tzinfo
=
UTC
)
user_profile
,
__
=
UserProfile
.
objects
.
get_or_create
(
user
=
user
)
user_profile_info
=
{
'
name
'
:
'
gdpr test name
'
,
'
meta
'
:
'
gdpr test meta
'
,
'
location
'
:
'
gdpr test location
'
,
'
year_of_birth
'
:
1950
,
'
gender
'
:
'
gdpr test gender
'
,
'
mailing_address
'
:
'
gdpr test mailing address
'
,
'
city
'
:
'
Boston
'
,
'
country
'
:
'
US
'
,
'
bio
'
:
'
gdpr test bio
'
,
'
profile_image_uploaded_at
'
:
profile_image_uploaded_date
}
for
field
,
value
in
user_profile_info
.
items
():
setattr
(
user_profile
,
field
,
value
)
user_profile
.
save
()
# Profile images
with
make_image_file
()
as
image_file
:
create_profile_images
(
image_file
,
{
10
:
"
ten.jpg
"
}
)
# DataSharingConsent
enterprise_customer
,
__
=
EnterpriseCustomer
.
objects
.
get_or_create
(
# pylint: disable=no-member
name
=
'
test gdpr enterprise customer
'
,
active
=
True
,
branding_configuration
=
None
,
catalog
=
None
,
enable_audit_enrollment
=
False
,
enable_data_sharing_consent
=
False
,
enforce_data_sharing_consent
=
'
at_enrollment
'
,
replace_sensitive_sso_username
=
True
,
site_id
=
1
)
DataSharingConsent
.
objects
.
get_or_create
(
username
=
username
,
enterprise_customer_id
=
enterprise_customer
.
uuid
)
# Sapsf data transmission
enterprise_customer_user
,
__
=
EnterpriseCustomerUser
.
objects
.
get_or_create
(
user_id
=
user
.
id
,
enterprise_customer_id
=
enterprise_customer
.
uuid
)
audit
,
__
=
EnterpriseCourseEnrollment
.
objects
.
get_or_create
(
enterprise_customer_user
=
enterprise_customer_user
)
SapSuccessFactorsLearnerDataTransmissionAudit
.
objects
.
get_or_create
(
enterprise_course_enrollment_id
=
audit
.
id
,
completed_timestamp
=
10
)
# PendingEnterpriseCustomerUser
PendingEnterpriseCustomerUser
.
objects
.
get_or_create
(
user_email
=
user
.
email
,
enterprise_customer_id
=
enterprise_customer
.
uuid
)
# EntitlementSupportDetail
course_entitlement
,
__
=
CourseEntitlement
.
objects
.
get_or_create
(
user_id
=
user
.
id
,
course_uuid
=
course_uuid
)
CourseEntitlementSupportDetail
.
objects
.
get_or_create
(
support_user
=
user
,
comments
=
'
test comments
'
,
entitlement_id
=
course_entitlement
.
id
)
# Misc. models that may contain PII of this user
SoftwareSecurePhotoVerification
.
objects
.
get_or_create
(
user
=
user
,
name
=
'
gdpr test
'
,
face_image_url
=
'
https://fake_image_url.com
'
,
photo_id_image_url
=
'
gdpr_test
'
,
photo_id_key
=
'
gdpr_test
'
)
PendingEmailChange
.
objects
.
get_or_create
(
user
=
user
,
activation_key
=
uuid4
().
hex
)
UserOrgTag
.
objects
.
get_or_create
(
user
=
user
)
course_id
=
CourseKey
.
from_string
(
"
course-v1:edX+DemoX+Demo_Course
"
)
# Objects linked to the user via their original email
CourseEnrollmentAllowed
.
objects
.
get_or_create
(
email
=
user
.
email
)
course_user_group
,
__
=
CourseUserGroup
.
objects
.
get_or_create
(
name
=
'
test course user group
'
,
course_id
=
course_id
)
UnregisteredLearnerCohortAssignments
.
objects
.
get_or_create
(
email
=
user
.
email
,
course_user_group_id
=
course_user_group
.
id
)
# Enroll the user in a course
CourseEnrollment
.
objects
.
get_or_create
(
course_id
=
course_id
,
user_id
=
user
.
id
,
)
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