Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beat.web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
beat
beat.web
Commits
b968b343
Commit
b968b343
authored
6 years ago
by
Samuel GAIST
Committed by
André Anjos
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[accounts][commands] Refactor email sending using helper
parent
be263d4d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!261
Fix email sending
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
beat/web/accounts/management/commands/year_revalidation_users.py
+36
-69
36 additions, 69 deletions
...b/accounts/management/commands/year_revalidation_users.py
with
36 additions
and
69 deletions
beat/web/accounts/management/commands/year_revalidation_users.py
+
36
−
69
View file @
b968b343
...
...
@@ -36,13 +36,12 @@ from django.db import models
from
django.db.models
import
Q
from
django.contrib.auth.models
import
User
from
django.conf
import
settings
from
django.core.mail
import
send_mail
from
django.template
import
loader
from
django.template
import
Context
from
...models
import
SupervisionTrack
from
...models
import
Profile
from
....ui.registration.models
import
RegistrationProfile
from
....utils
import
mail
import
sys
import
random
...
...
@@ -97,29 +96,21 @@ class Command(BaseCommand):
if
now
>
supervisiontrack
.
expiration_date
:
#if supervisor account reject all supervisees and inform them
if
user
.
profile
.
is_supervisor
:
c
=
Context
({
'
supervisor
'
:
user
,
'
supervisee
'
:
user
,
'
prefix
'
:
server_address
,
})
context
=
{
'
supervisor
'
:
user
,
'
supervisee
'
:
user
,
'
prefix
'
:
server_address
,
}
# Transform supervisor account to normal account and inform by email
user
.
profile
.
is_supervisor
=
False
user
.
profile
.
save
()
user
.
save
()
try
:
t
=
loader
.
get_template
(
'
registration/mail.beatadmin_supervisor_rejected.subject.txt
'
)
subject
=
t
.
render
(
c
)
# Note: e-mail subject *must not* contain newlines
subject
=
settings
.
EMAIL_SUBJECT_PREFIX
+
''
.
join
(
subject
.
splitlines
())
t
=
loader
.
get_template
(
'
registration/mail.beatadmin_supervisor_rejected_blocked.message.txt
'
)
message
=
t
.
render
(
c
)
send_mail
(
subject
,
message
,
settings
.
DEFAULT_FROM_EMAIL
,
[
user
.
email
])
except
:
pass
mail
.
send_email
(
'
registration/mail.beatadmin_supervisor_rejected.subject.txt
'
,
'
registration/mail.beatadmin_supervisor_rejected_blocked.message.txt
'
,
context
,
[
user
.
email
])
# Reject all his supervisees and inform by email
# Make sure all supervision tracks are invalid for rejected supervisor
...
...
@@ -146,24 +137,16 @@ class Command(BaseCommand):
track_supervisee
.
profile
.
save
()
track_supervisee
.
save
()
c
=
Context
({
'
supervisor
'
:
track_supervisor
,
'
supervisee
'
:
track_supervisee
,
'
prefix
'
:
server_address
,
})
try
:
t
=
loader
.
get_template
(
'
registration/mail.supervisor_failed_rejected.subject.txt
'
)
subject
=
t
.
render
(
c
)
# Note: e-mail subject *must not* contain newlines
subject
=
settings
.
EMAIL_SUBJECT_PREFIX
+
''
.
join
(
subject
.
splitlines
())
t
=
loader
.
get_template
(
'
registration/mail.supervisor_failed_rejected.message.txt
'
)
message
=
t
.
render
(
c
)
context
=
{
'
supervisor
'
:
track_supervisor
,
'
supervisee
'
:
track_supervisee
,
'
prefix
'
:
server_address
,
}
send_mail
(
subject
,
message
,
settings
.
DEFAULT_FROM_EMAIL
,
[
track_supervisee
.
email
])
except
:
pass
mail
.
send_email
(
'
registration/mail.supervisor_failed_rejected.subject.txt
'
,
'
registration/mail.supervisor_failed_rejected.message.txt
'
,
context
,
[
track_supervisee
.
email
])
if
track_supervisee
.
profile
.
status
==
Profile
.
WAITINGVALIDATION
:
registration_profile
=
RegistrationProfile
.
objects
.
get
(
user
=
track_supervisee
)
...
...
@@ -180,25 +163,17 @@ class Command(BaseCommand):
track_supervisee
=
track
.
supervisee
track_supervisor
=
track
.
supervisor
c
=
Context
({
'
supervisor
'
:
track_supervisor
,
'
supervisee
'
:
track_supervisee
,
'
prefix
'
:
server_address
,
})
context
=
{
'
supervisor
'
:
track_supervisor
,
'
supervisee
'
:
track_supervisee
,
'
prefix
'
:
server_address
,
}
#New user account waiting validation, so delete this account and inform by email the user
try
:
t
=
loader
.
get_template
(
'
registration/mail.supervisor_rejected.subject.txt
'
)
subject
=
t
.
render
(
c
)
# Note: e-mail subject *must not* contain newlines
subject
=
settings
.
EMAIL_SUBJECT_PREFIX
+
''
.
join
(
subject
.
splitlines
())
t
=
loader
.
get_template
(
'
registration/mail.supervisor_rejected_delete_account.message.txt
'
)
message
=
t
.
render
(
c
)
send_mail
(
subject
,
message
,
settings
.
DEFAULT_FROM_EMAIL
,
[
track_supervisee
.
email
])
except
:
pass
mail
.
send_email
(
'
registration/mail.supervisor_rejected.subject.txt
'
,
'
registration/mail.supervisor_rejected_delete_account.message.txt
'
,
context
,
[
track_supervisee
.
email
])
registration_profile
=
RegistrationProfile
.
objects
.
get
(
user
=
track_supervisee
)
track_supervisee
.
profile
.
delete
()
...
...
@@ -235,23 +210,15 @@ class Command(BaseCommand):
if
supervisiontrack
.
expiration_date
.
date
()
-
now
.
date
()
==
datetime
.
timedelta
(
days
=
expiration_reminder
):
warned_count
+=
1
c
=
Context
({
'
user
'
:
user
,
'
expiration_date
'
:
supervisiontrack
.
expiration_date
.
date
(),
})
try
:
t
=
loader
.
get_template
(
'
registration/mail.account_revalidation.subject.txt
'
)
subject
=
t
.
render
(
c
)
# Note: e-mail subject *must not* contain newlines
subject
=
settings
.
EMAIL_SUBJECT_PREFIX
+
''
.
join
(
subject
.
splitlines
())
t
=
loader
.
get_template
(
'
registration/mail.account_revalidation.message.txt
'
)
message
=
t
.
render
(
c
)
context
=
{
'
user
'
:
user
,
'
expiration_date
'
:
supervisiontrack
.
expiration_date
.
date
(),
}
send_mail
(
subject
,
message
,
settings
.
DEFAULT_FROM_EMAIL
,
[
supervisiontrack
.
supervisee
.
email
])
except
:
pass
mail
.
send_email
(
'
registration/mail.account_revalidation.subject.txt
'
,
'
registration/mail.account_revalidation.message.txt
'
,
context
,
[
supervisiontrack
.
supervisee
.
email
])
self
.
stdout
.
write
(
'
{} blocked user(s) and
'
.
format
(
blocked_count
)
+
'
{} warned user(s)/
'
.
format
(
warned_count
)
+
'
{} Total user(s) that need revalidation
'
.
format
(
torevalidate_profiles
.
count
()))
...
...
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