Skip to content
Snippets Groups Projects

Revert "Merge branch '569_cleanup_account_supervision_check_migration' into 'django3_migration'"

Merged Samuel GAIST requested to merge revert-af2e7192 into django3_migration
5 files
+ 120
2
Compare changes
  • Side-by-side
  • Inline
Files
5
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
###############################################################################
# #
# Copyright (c) 2017 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.web module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
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 = datetime.datetime.now()
expiration_date_delta = datetime.timedelta(
days=settings.ACCOUNT_BLOCKAGE_AFTER_FIRST_REJECTION_DAYS
)
specialusers = ["AnonymousUser", "plot", "system", "scheduler"]
for user in users:
user.save()
if user.is_staff or user.username in specialusers:
user.profile.status = "A"
user.profile.rejection_date = None
else:
# 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(
"registration/mail.migration_10_accounts.subject.txt"
)
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(
"registration/mail.migration_10_accounts.message.txt"
)
message = message_template.render(context)
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [user.email])
user.profile.supervision_key = None
user.profile.save()
user.save()
def backward_dummy(apps, schema_editor):
pass
class Migration(migrations.Migration):
dependencies = [
("accounts", "0010_rename_godfather_to_supervisor"),
]
operations = [migrations.RunPython(set_profile_state, backward_dummy)]
Loading