Commit cbfc8313 authored by Samuel GAIST's avatar Samuel GAIST

Merge branch '569_proper_cleanup_account_supervision_check_migration' into 'django3_migration'

Proper cleanup account supervision check migration

See merge request !393
parents b282f739 7a80c6e5
Pipeline #43203 passed with stage
in 16 minutes and 6 seconds
......@@ -27,73 +27,19 @@
from __future__ import unicode_literals
import datetime
from urllib.parse import urlparse
from django.conf import settings
from django.contrib.auth.models import User
from django.db import migrations
from django.template import loader
def set_profile_state(apps, schema_editor):
"""Set profile status"""
users = User.objects.all()
now =
expiration_date_delta = datetime.timedelta(
specialusers = ["AnonymousUser", "plot", "system", "scheduler"]
for user in users:
if user.is_staff or user.username in specialusers:
user.profile.status = "A"
user.profile.rejection_date = None
# reject this account and inform by email the user
user.profile.status = "R"
user.profile.rejection_date = now + expiration_date_delta
from django.core.mail import send_mail
parsed_url = urlparse(settings.URL_PREFIX)
server_address = "%s://%s" % (parsed_url.scheme, parsed_url.hostname)
context = {
"user": user,
"prefix": server_address,
subject_template = loader.get_template(
subject = subject_template.render(context)
# Note: e-mail subject *must not* contain newlines
subject = settings.EMAIL_SUBJECT_PREFIX + "".join(subject.splitlines())
message_template = loader.get_template(
message = message_template.render(context)
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [])
user.profile.supervision_key = None
def backward_dummy(apps, schema_editor):
class Migration(migrations.Migration):
""" This migration was initially used to help setup registered users with
on the new supervision ecosystem.
Current registered users were warned by email that they would need to have a valid
supervisor in order to continue using the platform.
class Migration(migrations.Migration):
This migration has been cleaned up as it is no more used by the system.
dependencies = [
("accounts", "0010_rename_godfather_to_supervisor"),
operations = [migrations.RunPython(set_profile_state, backward_dummy)]
Dear {{ user.first_name }},
The admin of the BEAT platform would like to inform you of a security update
to your account used under username {{ user.username}}
From now on you will need to be supervised by a known supervisor.
To comply with this new rule, please go to your account settings and under
Account Management click on "Add a supervisor" and validate it with a known
Failing to do so, your account will be blocked after a few weeks! (you
can however still re-activate it through an account reactivation procedure)
If you are having problems to revalidate your account, contact a member of our
support staff at {{ prefix }}{% url 'contact' %}.
BEAT Administrators at the Idiap Research Institute
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment