SciPost Code Repository
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SciPost
Manage
Activity
Members
Labels
Plan
Issues
118
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
SciPost
SciPost
Commits
2debd764
Commit
2debd764
authored
6 months ago
by
George Katsikas
Browse files
Options
Downloads
Patches
Plain Diff
propagate user mail change to profile if verified
fixes
#306
parent
07510e78
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
scipost_django/profiles/forms.py
+1
-7
1 addition, 7 deletions
scipost_django/profiles/forms.py
scipost_django/profiles/models.py
+11
-0
11 additions, 0 deletions
scipost_django/profiles/models.py
scipost_django/scipost/forms.py
+37
-14
37 additions, 14 deletions
scipost_django/scipost/forms.py
with
49 additions
and
21 deletions
scipost_django/profiles/forms.py
+
1
−
7
View file @
2debd764
...
@@ -297,15 +297,9 @@ class AddProfileEmailForm(forms.ModelForm):
...
@@ -297,15 +297,9 @@ class AddProfileEmailForm(forms.ModelForm):
"""
Mark the email as still_valid but not primary.
"""
"""
Mark the email as still_valid but not primary.
"""
self
.
instance
.
profile
=
self
.
profile
self
.
instance
.
profile
=
self
.
profile
if
self
.
request
:
is_editing_self
=
self
.
request
.
user
.
contributor
.
profile
==
self
.
profile
is_ed_admin
=
self
.
request
.
user
.
contributor
.
is_ed_admin
self
.
instance
.
verified
=
is_editing_self
or
is_ed_admin
self
.
instance
.
still_valid
=
True
self
.
instance
.
still_valid
=
True
self
.
instance
.
primary
=
False
self
.
instance
.
primary
=
False
self
.
instance
.
added_by
=
self
.
request
.
user
.
contributor
self
.
instance
.
added_by
=
self
.
request
.
user
.
contributor
if
self
.
request
else
None
return
super
().
save
()
return
super
().
save
()
...
...
This diff is collapsed.
Click to expand it.
scipost_django/profiles/models.py
+
11
−
0
View file @
2debd764
...
@@ -231,6 +231,9 @@ class ProfileEmail(models.Model):
...
@@ -231,6 +231,9 @@ class ProfileEmail(models.Model):
)
)
primary
=
models
.
BooleanField
(
default
=
False
)
primary
=
models
.
BooleanField
(
default
=
False
)
if
TYPE_CHECKING
:
objects
:
models
.
Manager
[
"
ProfileEmail
"
]
class
Meta
:
class
Meta
:
unique_together
=
[
"
profile
"
,
"
email
"
]
unique_together
=
[
"
profile
"
,
"
email
"
]
ordering
=
[
"
-primary
"
,
"
-still_valid
"
,
"
email
"
]
ordering
=
[
"
-primary
"
,
"
-still_valid
"
,
"
email
"
]
...
@@ -261,6 +264,14 @@ class ProfileEmail(models.Model):
...
@@ -261,6 +264,14 @@ class ProfileEmail(models.Model):
kwargs
=
{
"
email_id
"
:
self
.
id
,
"
token
"
:
self
.
verification_token
},
kwargs
=
{
"
email_id
"
:
self
.
id
,
"
token
"
:
self
.
verification_token
},
)
)
def
set_primary
(
self
):
"""
Sets this email as the primary email for the Profile, unsetting others.
"""
self
.
profile
.
emails
.
update
(
primary
=
False
)
self
.
primary
=
True
self
.
save
()
def
get_profiles
(
slug
):
def
get_profiles
(
slug
):
"""
"""
...
...
This diff is collapsed.
Click to expand it.
scipost_django/scipost/forms.py
+
37
−
14
View file @
2debd764
...
@@ -360,21 +360,44 @@ class UpdateUserDataForm(forms.ModelForm):
...
@@ -360,21 +360,44 @@ class UpdateUserDataForm(forms.ModelForm):
self
.
fields
[
"
last_name
"
].
widget
.
attrs
[
"
readonly
"
]
=
True
self
.
fields
[
"
last_name
"
].
widget
.
attrs
[
"
readonly
"
]
=
True
def
clean_email
(
self
):
def
clean_email
(
self
):
if
email
:
=
self
.
cleaned_data
.
get
(
"
email
"
):
# Guard against empty email address
other_users
=
User
.
objects
.
filter
(
email
=
email
).
exclude
(
pk
=
self
.
instance
.
pk
)
if
not
(
email
:
=
self
.
cleaned_data
.
get
(
"
email
"
)):
if
other_users
.
exists
():
raise
ValidationError
(
"
The email address cannot be empty.
"
)
self
.
add_error
(
"
email
"
,
other_users
=
User
.
objects
.
filter
(
email
=
email
).
exclude
(
pk
=
self
.
instance
.
pk
)
"
This email is already in use by another user.
"
if
other_users
.
exists
():
"
If it belongs to you and you have forgotten your credentials,
"
raise
ValidationError
(
"
use the email in place of your username and/or reset your password.
"
,
"
This email is already in use by another user.
"
)
"
If it belongs to you and you have forgotten your credentials,
"
# other_profiles = Profile.objects.filter(emails__email=email).exclude(
"
use the email in place of your username and/or reset your password.
"
,
# user=self.instance
)
# )
# if other_profiles.exists():
profile_email
,
created
=
ProfileEmail
.
objects
.
get_or_create
(
email
=
email
,
profile
=
self
.
instance
.
contributor
.
profile
)
# If just created, it needs to be verified
if
created
:
profile_email
.
send_verification_email
()
raise
ValidationError
(
"
This email is not yet verified. Please check your inbox for a verification email.
"
)
# Existing, but of another User
elif
profile_email
.
profile
.
contributor
!=
self
.
instance
.
contributor
:
raise
ValidationError
(
"
This email is already declared as belonging to another person.
"
"
Please contact tech support.
"
,
)
# Existing, of this User, but not verified
elif
not
profile_email
.
verified
:
profile_email
.
send_verification_email
()
raise
ValidationError
(
"
This email is not yet verified. Please check your inbox for a verification email.
"
)
return
email
or
self
.
instance
.
email
# Existing, of this User, and verified
profile_email
.
set_primary
()
return
email
def
clean_last_name
(
self
):
def
clean_last_name
(
self
):
"""
Make sure the `last_name` cannot be saved via this form.
"""
"""
Make sure the `last_name` cannot be saved via this form.
"""
...
...
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