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
1da320f1
Commit
1da320f1
authored
Jul 25, 2017
by
Simon Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move the user_attribute creation for site from within the user creation transaction to outside
learner-1521
parent
d17bc753
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
7 deletions
+14
-7
common/djangoapps/student/views.py
+14
-7
No files found.
common/djangoapps/student/views.py
View file @
1da320f1
...
@@ -1675,7 +1675,7 @@ def user_signup_handler(sender, **kwargs): # pylint: disable=unused-argument
...
@@ -1675,7 +1675,7 @@ def user_signup_handler(sender, **kwargs): # pylint: disable=unused-argument
log
.
info
(
u'user {} originated from a white labeled "Microsite"'
.
format
(
kwargs
[
'instance'
]
.
id
))
log
.
info
(
u'user {} originated from a white labeled "Microsite"'
.
format
(
kwargs
[
'instance'
]
.
id
))
def
_do_create_account
(
form
,
custom_form
=
None
,
site
=
None
):
def
_do_create_account
(
form
,
custom_form
=
None
):
"""
"""
Given cleaned post variables, create the User and UserProfile objects, as well as the
Given cleaned post variables, create the User and UserProfile objects, as well as the
registration for this user.
registration for this user.
...
@@ -1716,10 +1716,6 @@ def _do_create_account(form, custom_form=None, site=None):
...
@@ -1716,10 +1716,6 @@ def _do_create_account(form, custom_form=None, site=None):
custom_model
=
custom_form
.
save
(
commit
=
False
)
custom_model
=
custom_form
.
save
(
commit
=
False
)
custom_model
.
user
=
user
custom_model
.
user
=
user
custom_model
.
save
()
custom_model
.
save
()
if
site
:
# Set UserAttribute indicating the site the user account was created on.
UserAttribute
.
set_user_attribute
(
user
,
'created_on_site'
,
site
.
domain
)
except
IntegrityError
:
except
IntegrityError
:
# Figure out the cause of the integrity error
# Figure out the cause of the integrity error
if
len
(
User
.
objects
.
filter
(
username
=
user
.
username
))
>
0
:
if
len
(
User
.
objects
.
filter
(
username
=
user
.
username
))
>
0
:
...
@@ -1762,6 +1758,13 @@ def _do_create_account(form, custom_form=None, site=None):
...
@@ -1762,6 +1758,13 @@ def _do_create_account(form, custom_form=None, site=None):
return
(
user
,
profile
,
registration
)
return
(
user
,
profile
,
registration
)
def
_create_or_set_user_attribute_created_on_site
(
user
,
site
):
# Create or Set UserAttribute indicating the microsite site the user account was created on.
# User maybe created on 'courses.edx.org', or a white-label site
if
site
:
UserAttribute
.
set_user_attribute
(
user
,
'created_on_site'
,
site
.
domain
)
def
create_account_with_params
(
request
,
params
):
def
create_account_with_params
(
request
,
params
):
"""
"""
Given a request and a dict of parameters (which may or may not have come
Given a request and a dict of parameters (which may or may not have come
...
@@ -1868,7 +1871,7 @@ def create_account_with_params(request, params):
...
@@ -1868,7 +1871,7 @@ def create_account_with_params(request, params):
# Perform operations within a transaction that are critical to account creation
# Perform operations within a transaction that are critical to account creation
with
transaction
.
atomic
():
with
transaction
.
atomic
():
# first, create the account
# first, create the account
(
user
,
profile
,
registration
)
=
_do_create_account
(
form
,
custom_form
,
site
=
request
.
site
)
(
user
,
profile
,
registration
)
=
_do_create_account
(
form
,
custom_form
)
# If a 3rd party auth provider and credentials were provided in the API, link the account with social auth
# If a 3rd party auth provider and credentials were provided in the API, link the account with social auth
# (If the user is using the normal register page, the social auth pipeline does the linking, not this code)
# (If the user is using the normal register page, the social auth pipeline does the linking, not this code)
...
@@ -1905,6 +1908,8 @@ def create_account_with_params(request, params):
...
@@ -1905,6 +1908,8 @@ def create_account_with_params(request, params):
raise
ValidationError
({
'access_token'
:
[
error_message
]})
raise
ValidationError
({
'access_token'
:
[
error_message
]})
# Perform operations that are non-critical parts of account creation
# Perform operations that are non-critical parts of account creation
_create_or_set_user_attribute_created_on_site
(
user
,
request
.
site
)
preferences_api
.
set_user_preference
(
user
,
LANGUAGE_KEY
,
get_language
())
preferences_api
.
set_user_preference
(
user
,
LANGUAGE_KEY
,
get_language
())
if
settings
.
FEATURES
.
get
(
'ENABLE_DISCUSSION_EMAIL_DIGEST'
):
if
settings
.
FEATURES
.
get
(
'ENABLE_DISCUSSION_EMAIL_DIGEST'
):
...
@@ -2225,7 +2230,7 @@ def auto_auth(request):
...
@@ -2225,7 +2230,7 @@ def auto_auth(request):
# If successful, this will return a tuple containing
# If successful, this will return a tuple containing
# the new user object.
# the new user object.
try
:
try
:
user
,
profile
,
reg
=
_do_create_account
(
form
,
site
=
request
.
site
)
user
,
profile
,
reg
=
_do_create_account
(
form
)
except
(
AccountValidationError
,
ValidationError
):
except
(
AccountValidationError
,
ValidationError
):
# Attempt to retrieve the existing user.
# Attempt to retrieve the existing user.
user
=
User
.
objects
.
get
(
username
=
username
)
user
=
User
.
objects
.
get
(
username
=
username
)
...
@@ -2252,6 +2257,8 @@ def auto_auth(request):
...
@@ -2252,6 +2257,8 @@ def auto_auth(request):
profile
.
year_of_birth
=
(
year
-
age_limit
)
-
1
profile
.
year_of_birth
=
(
year
-
age_limit
)
-
1
profile
.
save
()
profile
.
save
()
_create_or_set_user_attribute_created_on_site
(
user
,
request
.
site
)
# Enroll the user in a course
# Enroll the user in a course
course_key
=
None
course_key
=
None
if
course_id
:
if
course_id
:
...
...
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