diff --git a/beat/web/accounts/__init__.py b/beat/web/accounts/__init__.py index dffa547e89b67e27f68a24d0a9bddfc11cc7b476..441d3677ca5ea4117b69d038c705e04373df376e 100644 --- a/beat/web/accounts/__init__.py +++ b/beat/web/accounts/__init__.py @@ -25,4 +25,4 @@ # # ############################################################################### -default_app_config = 'beat.web.accounts.apps.AccountsConfig' +default_app_config = "beat.web.accounts.apps.AccountsConfig" diff --git a/beat/web/accounts/api.py b/beat/web/accounts/api.py index b820cf32878dd3b75d671ab822b7a3578157cbde..b8717751b106010284db4e9db82406913fa90015 100644 --- a/beat/web/accounts/api.py +++ b/beat/web/accounts/api.py @@ -25,43 +25,35 @@ # # ############################################################################### +import datetime +from urllib.parse import urlparse + from django.conf import settings from django.contrib.auth.models import User from django.db import models from django.db.models import Q - from rest_framework import generics from rest_framework import permissions -from rest_framework.response import Response from rest_framework import status +from rest_framework.response import Response -from .serializers import FullSupervisionTrackSerializer -from .serializers import SupervisionTrackUpdateSerializer -from .serializers import UserSerializer - +from ..common.responses import BadRequestResponse +from ..ui.registration.models import RegistrationProfile +from ..utils import mail from .models import Profile from .models import SupervisionTrack from .models import TemporaryUrl +from .permissions import IsAuthorAndNotSupervisor +from .permissions import IsAuthorAndPossiblySupervisor +from .permissions import IsSuperUser +from .permissions import IsSupervisorAndAuthor +from .serializers import FullSupervisionTrackSerializer +from .serializers import SupervisionTrackUpdateSerializer +from .serializers import UserSerializer from .views import accept_supervisee +from .views import emergency_rejection from .views import perform_revalidation from .views import supervisee_rejection -from .views import emergency_rejection -from ..ui.registration.models import RegistrationProfile -from ..utils import mail - -from .permissions import ( - IsSupervisorAndAuthor, - IsAuthorAndNotSupervisor, - IsAuthorAndPossiblySupervisor, - IsSuperUser, -) - -from ..common.responses import BadRequestResponse - -import datetime - -from urllib.parse import urlparse - # ---------------------------------------------------------- diff --git a/beat/web/accounts/apps.py b/beat/web/accounts/apps.py index 537ec0b2830d57b364f98c3cfa18767f0c4e07b3..ea634ecd8cd1e9fd0a37a11e7f6eab82cf6e1462 100644 --- a/beat/web/accounts/apps.py +++ b/beat/web/accounts/apps.py @@ -28,14 +28,17 @@ from django.apps import AppConfig from django.utils.translation import ugettext_lazy as _ + class AccountsConfig(AppConfig): - name = 'beat.web.accounts' - verbose_name = _('Accounts') + name = "beat.web.accounts" + verbose_name = _("Accounts") def ready(self): super(AccountsConfig, self).ready() - from django.contrib.auth.models import User from actstream import registry + from django.contrib.auth.models import User + registry.register(User) - from .signals import setup_user + + from .signals import setup_user # noqa Django signal registration diff --git a/beat/web/accounts/forms.py b/beat/web/accounts/forms.py index 0a0adc7166cafb4766a08b9858e8812e48183572..e25ead140f09d77c8fa05488c867ac2afad8b144 100644 --- a/beat/web/accounts/forms.py +++ b/beat/web/accounts/forms.py @@ -26,14 +26,16 @@ ############################################################################### from django.forms import ModelForm + from .models import AccountSettings + class AccountSettingsForm(ModelForm): class Meta: model = AccountSettings fields = [ - 'daily_summary', - 'experiment_mail_notifications_enabled', - 'database_notifications_enabled', - 'environment_notifications_enabled', + "daily_summary", + "experiment_mail_notifications_enabled", + "database_notifications_enabled", + "environment_notifications_enabled", ] diff --git a/beat/web/accounts/management/commands/block_rejected_users.py b/beat/web/accounts/management/commands/block_rejected_users.py index 9613bc83efac76e175dd45dd19226f5ef0b7716a..05d9f4bb2227c2150103aae2527107ac1f5698b4 100644 --- a/beat/web/accounts/management/commands/block_rejected_users.py +++ b/beat/web/accounts/management/commands/block_rejected_users.py @@ -27,42 +27,43 @@ ############################################################################### -from django.core.management.base import BaseCommand, CommandError - -from datetime import date import datetime +import sys -from django.contrib.auth.models import User -from django.conf import settings +from django.core.management.base import BaseCommand -from ...models import SupervisionTrack from ...models import Profile -from ....ui.registration.models import RegistrationProfile +from ...models import SupervisionTrack -import sys -import random class Command(BaseCommand): - help = 'Block rejected users after rejection date with no valid supervisor' + help = "Block rejected users after rejection date with no valid supervisor" def add_arguments(self, parser): - parser.add_argument('--noinput', action='store_false', dest='interactive', default=False, - help=('Tells Django to NOT prompt the user for input of any kind.')) - + parser.add_argument( + "--noinput", + action="store_false", + dest="interactive", + default=False, + help=("Tells Django to NOT prompt the user for input of any kind."), + ) def handle(self, *args, **options): block = True - if options['interactive']: + if options["interactive"]: try: - answer = self.get_input_data('Block rejected user(s) that have not been validated by a supervisor? (y/n)? ', 'y').lower() + answer = self.get_input_data( + "Block rejected user(s) that have not been validated by a supervisor? (y/n)? ", + "y", + ).lower() except KeyboardInterrupt: self.stderr.write("\nOperation canceled.") sys.exit(1) - if answer != 'y': - self.stdout.write('Block users operation canceled') + if answer != "y": + self.stdout.write("Block users operation canceled") sys.exit(1) if block: @@ -71,31 +72,38 @@ class Command(BaseCommand): for rejected_profile in rejected_profiles: user = rejected_profile.user if user.profile.rejection_date < datetime.datetime.now(): - count +=1 + count += 1 user.profile.status = Profile.BLOCKED user.profile.rejection_date = None user.is_active = False - if user.profile.supervision_key != None: - supervisiontrack = SupervisionTrack.objects.get(supervision_key=rejected_profile.supervision_key) - if supervisiontrack.is_valid == False and supervisiontrack.start_date is None: + if user.profile.supervision_key is not None: + supervisiontrack = SupervisionTrack.objects.get( + supervision_key=rejected_profile.supervision_key + ) + if ( + not supervisiontrack.is_valid + and supervisiontrack.start_date is None + ): user.profile.supervision_key = None supervisiontrack.delete() user.profile.save() user.save() - self.stdout.write('{} Rejected user(s) successfully blocked/'.format(count) + '{} Total user(s) checked'.format(rejected_profiles.count())) - + self.stdout.write( + "{} Rejected user(s) successfully blocked/".format(count) + + "{} Total user(s) checked".format(rejected_profiles.count()) + ) def get_input_data(self, message, default=None): """ Override this method if you want to customize data inputs or validation exceptions. """ - raw_value = raw_input(message) + raw_value = input(message) - if default and raw_value == '': + if default and raw_value == "": raw_value = default return raw_value diff --git a/beat/web/accounts/management/commands/clean_blocked_users_expired_requests.py b/beat/web/accounts/management/commands/clean_blocked_users_expired_requests.py index a18167f69a6dbaed929154e584b50a94c2afce3b..a321e4f4e2806959d3a90fc475b2349281b6fd77 100644 --- a/beat/web/accounts/management/commands/clean_blocked_users_expired_requests.py +++ b/beat/web/accounts/management/commands/clean_blocked_users_expired_requests.py @@ -27,42 +27,41 @@ ############################################################################### -from django.core.management.base import BaseCommand, CommandError - -from datetime import date import datetime - -from django.contrib.auth.models import User -from django.conf import settings - -from ...models import SupervisionTrack +import sys +from django.core.management.base import BaseCommand from ...models import Profile -from ....ui.registration.models import RegistrationProfile +from ...models import SupervisionTrack -import sys -import random class Command(BaseCommand): - help = 'Clean blocked users expired requests for supervisor validation' + help = "Clean blocked users expired requests for supervisor validation" def add_arguments(self, parser): - parser.add_argument('--noinput', action='store_false', dest='interactive', default=False, - help=('Tells Django to NOT prompt the user for input of any kind.')) - + parser.add_argument( + "--noinput", + action="store_false", + dest="interactive", + default=False, + help=("Tells Django to NOT prompt the user for input of any kind."), + ) def handle(self, *args, **options): block = True - if options['interactive']: + if options["interactive"]: try: - answer = self.get_input_data('Clean blocked user(s) that have not been validated by a supervisor? (y/n)? ', 'y').lower() + answer = self.get_input_data( + "Clean blocked user(s) that have not been validated by a supervisor? (y/n)? ", + "y", + ).lower() except KeyboardInterrupt: self.stderr.write("\nOperation canceled.") sys.exit(1) - if answer != 'y': - self.stdout.write('Clean blocked users operation canceled') + if answer != "y": + self.stdout.write("Clean blocked users operation canceled") sys.exit(1) if block: @@ -72,31 +71,40 @@ class Command(BaseCommand): user = blocked_profile.user if user.profile.rejection_date is not None: if user.profile.rejection_date < datetime.datetime.now(): - count +=1 + count += 1 user.profile.status = Profile.BLOCKED user.profile.rejection_date = None user.is_active = False - if user.profile.supervision_key != None: - supervisiontrack = SupervisionTrack.objects.get(supervision_key=blocked_profile.supervision_key) - if supervisiontrack.is_valid == False and supervisiontrack.start_date is None: + if user.profile.supervision_key is not None: + supervisiontrack = SupervisionTrack.objects.get( + supervision_key=blocked_profile.supervision_key + ) + if ( + not supervisiontrack.is_valid + and supervisiontrack.start_date is None + ): user.profile.supervision_key = None supervisiontrack.delete() user.profile.save() user.save() - self.stdout.write('{} Blocked user(s) successfully cleaned from expired supervision/'.format(count) + '{} Total user(s) checked'.format(blocked_profiles.count())) - + self.stdout.write( + "{} Blocked user(s) successfully cleaned from expired supervision/".format( + count + ) + + "{} Total user(s) checked".format(blocked_profiles.count()) + ) def get_input_data(self, message, default=None): """ Override this method if you want to customize data inputs or validation exceptions. """ - raw_value = raw_input(message) + raw_value = input(message) - if default and raw_value == '': + if default and raw_value == "": raw_value = default return raw_value diff --git a/beat/web/accounts/management/commands/clean_expired_temporary_urls.py b/beat/web/accounts/management/commands/clean_expired_temporary_urls.py index 92a762f909eccc2f2f47cc6c482c45089c976b72..2b7db73dace09852178a461a8556c79ea051bcd3 100644 --- a/beat/web/accounts/management/commands/clean_expired_temporary_urls.py +++ b/beat/web/accounts/management/commands/clean_expired_temporary_urls.py @@ -27,50 +27,59 @@ ############################################################################### -from django.core.management.base import BaseCommand - import datetime import sys +from django.core.management.base import BaseCommand + from ...models import TemporaryUrl class Command(BaseCommand): - help = 'Clean expired temporary urls' + help = "Clean expired temporary urls" def add_arguments(self, parser): - parser.add_argument('--noinput', action='store_false', dest='interactive', default=False, - help=('Tells Django to NOT prompt the user for input of any kind.')) - + parser.add_argument( + "--noinput", + action="store_false", + dest="interactive", + default=False, + help=("Tells Django to NOT prompt the user for input of any kind."), + ) def handle(self, *args, **options): - if options['interactive']: + if options["interactive"]: try: - answer = self.get_input_data('Clean expired temporary url(s) that have not been used? (y/n)? ', 'y').lower() + answer = self.get_input_data( + "Clean expired temporary url(s) that have not been used? (y/n)? ", + "y", + ).lower() except KeyboardInterrupt: self.stderr.write("\nOperation canceled.") sys.exit(1) - if answer != 'y': - self.stdout.write('Clean expired temporary urls operation canceled') + if answer != "y": + self.stdout.write("Clean expired temporary urls operation canceled") sys.exit(1) temporary_urls_count = TemporaryUrl.objects.all().count() now = datetime.datetime.now() count, _ = TemporaryUrl.objects.filter(expires__lt=now).delete() - self.stdout.write('{} Expired temporary url(s) successfully cleaned/'.format(count) + '{} Total temporary url(s) checked'.format(temporary_urls_count)) - + self.stdout.write( + "{} Expired temporary url(s) successfully cleaned/".format(count) + + "{} Total temporary url(s) checked".format(temporary_urls_count) + ) def get_input_data(self, message, default=None): """ Override this method if you want to customize data inputs or validation exceptions. """ - raw_value = raw_input(message) + raw_value = input(message) - if default and raw_value == '': + if default and raw_value == "": raw_value = default return raw_value diff --git a/beat/web/accounts/management/commands/clean_invalid_users.py b/beat/web/accounts/management/commands/clean_invalid_users.py index f698b37f96919145bbc9502854121b4841cdcf6a..ec56088cd18c8118751e74f54007ae02c246e2ee 100644 --- a/beat/web/accounts/management/commands/clean_invalid_users.py +++ b/beat/web/accounts/management/commands/clean_invalid_users.py @@ -27,16 +27,15 @@ ############################################################################### -import sys import datetime +import sys -from django.core.management.base import BaseCommand from django.conf import settings +from django.core.management.base import BaseCommand from ....ui.registration.models import RegistrationProfile - -from ...models import SupervisionTrack from ...models import Profile +from ...models import SupervisionTrack class Command(BaseCommand): diff --git a/beat/web/accounts/management/commands/postpone_users_validation.py b/beat/web/accounts/management/commands/postpone_users_validation.py index 63b46d6c565a83a7177243de1fd46fad36afa908..91db6e4717b7830be965a0b5ceea1f3693128ade 100644 --- a/beat/web/accounts/management/commands/postpone_users_validation.py +++ b/beat/web/accounts/management/commands/postpone_users_validation.py @@ -30,13 +30,12 @@ import datetime import sys -from django.core.management.base import BaseCommand from django.conf import settings +from django.core.management.base import BaseCommand from ....ui.registration.models import RegistrationProfile - -from ...models import SupervisionTrack from ...models import Profile +from ...models import SupervisionTrack class Command(BaseCommand): diff --git a/beat/web/accounts/management/commands/year_revalidation_users.py b/beat/web/accounts/management/commands/year_revalidation_users.py index 7b4021ada48ee850d48688a197e8e8bd7aaa5dde..e701e823a0bd0e7fa573744c9c78f739503a4ecf 100644 --- a/beat/web/accounts/management/commands/year_revalidation_users.py +++ b/beat/web/accounts/management/commands/year_revalidation_users.py @@ -27,80 +27,96 @@ ############################################################################### -from django.core.management.base import BaseCommand, CommandError - -from datetime import date import datetime +import sys +from django.conf import settings +from django.core.management.base import BaseCommand 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.template import loader -from ...models import SupervisionTrack -from ...models import Profile -from ...models import TemporaryUrl from ....ui.registration.models import RegistrationProfile from ....utils import mail +from ...models import Profile +from ...models import SupervisionTrack +from ...models import TemporaryUrl -import sys -import random try: from urlparse import urlparse except ImportError: from urllib.parse import urlparse + class Command(BaseCommand): - help = 'Check users for yearly revalidation' + help = "Check users for yearly revalidation" def add_arguments(self, parser): - parser.add_argument('--noinput', action='store_false', dest='interactive', default=False, - help=('Tells Django to NOT prompt the user for input of any kind.')) - + parser.add_argument( + "--noinput", + action="store_false", + dest="interactive", + default=False, + help=("Tells Django to NOT prompt the user for input of any kind."), + ) def handle(self, *args, **options): yearrevalidate = True - if options['interactive']: + if options["interactive"]: try: - answer = self.get_input_data('Check user(s) for yearly revalidation by a supervisor? (y/n)? ', 'y').lower() + answer = self.get_input_data( + "Check user(s) for yearly revalidation by a supervisor? (y/n)? ", + "y", + ).lower() except KeyboardInterrupt: self.stderr.write("\nOperation canceled.") sys.exit(1) - if answer != 'y': - self.stdout.write('Check users yearly revalidation operation canceled') + if answer != "y": + self.stdout.write("Check users yearly revalidation operation canceled") sys.exit(1) if yearrevalidate: specialusers = ["AnonymousUser", "plot", "system", "scheduler"] - torevalidate_profiles = Profile.objects.filter(Q(status=Profile.ACCEPTED)|Q(status=Profile.YEARREVALIDATION)).exclude(user__is_superuser=True).exclude(user__username__in=specialusers) + torevalidate_profiles = ( + Profile.objects.filter( + Q(status=Profile.ACCEPTED) | Q(status=Profile.YEARREVALIDATION) + ) + .exclude(user__is_superuser=True) + .exclude(user__username__in=specialusers) + ) now = datetime.datetime.now() blocked_count = 0 warned_count = 0 parsed_url = urlparse(settings.URL_PREFIX) - server_address = '%s://%s' % (parsed_url.scheme, parsed_url.hostname) + server_address = "%s://%s" % (parsed_url.scheme, parsed_url.hostname) for torevalidate_profile in torevalidate_profiles: user = torevalidate_profile.user - if user.profile.supervision_key != None: - supervisiontrack = SupervisionTrack.objects.get(supervision_key=torevalidate_profile.supervision_key) + if user.profile.supervision_key is not None: + supervisiontrack = SupervisionTrack.objects.get( + supervision_key=torevalidate_profile.supervision_key + ) if supervisiontrack.is_valid: - #Check expiration date - expiration_date_delta = datetime.timedelta(days=settings.ACCOUNT_BLOCKAGE_AFTER_FIRST_REJECTION_DAYS) - if supervisiontrack.expiration_date < now + expiration_date_delta: - #check if need to block account + # Check expiration date + expiration_date_delta = datetime.timedelta( + days=settings.ACCOUNT_BLOCKAGE_AFTER_FIRST_REJECTION_DAYS + ) + if ( + supervisiontrack.expiration_date + < now + expiration_date_delta + ): + # check if need to block account if now > supervisiontrack.expiration_date: - #if supervisor account reject all supervisees and inform them + # if supervisor account reject all supervisees and inform them if user.profile.is_supervisor: context = { - 'supervisor': user, - 'supervisee': user, - 'prefix': server_address, + "supervisor": user, + "supervisee": user, + "prefix": server_address, } # Transform supervisor account to normal account and inform by email @@ -108,15 +124,47 @@ class Command(BaseCommand): user.profile.save() user.save() - mail.send_email('registration/mail.beatadmin_supervisor_rejected.subject.txt', - 'registration/mail.beatadmin_supervisor_rejected_blocked.message.txt', - context, - [user.email]) + 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 - supervisiontracks = SupervisionTrack.objects.filter(supervisor=user).filter(Q(supervisee__profile__status=Profile.REJECTED)|Q(supervisee__profile__status=Profile.YEARREVALIDATION)|Q(supervisee__profile__status=Profile.ACCEPTED)|Q(supervisee__profile__status=Profile.BLOCKED)).filter(Q(supervisee__profile__supervision_key=models.F('supervision_key'))) - supervisiontracks_new_users = SupervisionTrack.objects.filter(supervisor=user).filter(Q(supervisee__profile__status=Profile.NEWUSER)|Q(supervisee__profile__status=Profile.WAITINGVALIDATION)) + supervisiontracks = ( + SupervisionTrack.objects.filter(supervisor=user) + .filter( + Q( + supervisee__profile__status=Profile.REJECTED + ) + | Q( + supervisee__profile__status=Profile.YEARREVALIDATION + ) + | Q( + supervisee__profile__status=Profile.ACCEPTED + ) + | Q( + supervisee__profile__status=Profile.BLOCKED + ) + ) + .filter( + Q( + supervisee__profile__supervision_key=models.F( + "supervision_key" + ) + ) + ) + ) + supervisiontracks_new_users = SupervisionTrack.objects.filter( + supervisor=user + ).filter( + Q(supervisee__profile__status=Profile.NEWUSER) + | Q( + supervisee__profile__status=Profile.WAITINGVALIDATION + ) + ) if supervisiontracks.count() > 0: for track in supervisiontracks: @@ -125,37 +173,58 @@ class Command(BaseCommand): track_supervisee = track.supervisee track_supervisor = track.supervisor - if track_supervisee.profile.status != Profile.BLOCKED: - track_supervisee.profile.status = Profile.REJECTED - if track_supervisee.profile.rejection_date == None: - track_supervisee.profile.rejection_date = now + expiration_date_delta + if ( + track_supervisee.profile.status + != Profile.BLOCKED + ): + track_supervisee.profile.status = ( + Profile.REJECTED + ) + if ( + track_supervisee.profile.rejection_date + is None + ): + track_supervisee.profile.rejection_date = ( + now + expiration_date_delta + ) else: - track_supervisee.profile.rejection_date = None + track_supervisee.profile.rejection_date = ( + None + ) - track_supervisee.profile.supervision_key = None + track_supervisee.profile.supervision_key = ( + None + ) track.save() track_supervisee.profile.save() track_supervisee.save() context = { - 'supervisor': track_supervisor, - 'supervisee': track_supervisee, - 'prefix': server_address, + "supervisor": track_supervisor, + "supervisee": track_supervisee, + "prefix": server_address, } - 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) + 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 + ) track_supervisee.profile.delete() track_supervisee.delete() registration_profile.delete() - #New supervision request refused + # New supervision request refused if track.start_date is None: track.delete() @@ -165,77 +234,95 @@ class Command(BaseCommand): track_supervisor = track.supervisor context = { - 'supervisor': track_supervisor, - 'supervisee': track_supervisee, - 'prefix': server_address, + "supervisor": track_supervisor, + "supervisee": track_supervisee, + "prefix": server_address, } - #New user account waiting validation, so delete this account and inform by email the user - 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) + # New user account waiting validation, so delete this account and inform by email the user + 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() track_supervisee.delete() registration_profile.delete() - #New supervision request refused + # New supervision request refused if track.start_date is None: track.delete() blocked_count += 1 - #terminate supervision + # terminate supervision supervisiontrack.expiration_date = now supervisiontrack.is_valid = False - #block user + # block user user.profile.status = Profile.BLOCKED user.profile.rejection_date = None user.profile.supervision_key = None user.is_active = False - #save all changes + # save all changes supervisiontrack.save() user.profile.save() user.save() else: - #send the warning information - #set user to YEARREVALIDATION + # send the warning information + # set user to YEARREVALIDATION if user.profile.status == Profile.ACCEPTED: user.profile.status = Profile.YEARREVALIDATION user.profile.save() - #send email to user - for expiration_reminder in settings.EXPIRATION_REMINDERS_REVALIDATION: - if supervisiontrack.expiration_date.date() - now.date() == datetime.timedelta(days=expiration_reminder): + # send email to user + for ( + expiration_reminder + ) in settings.EXPIRATION_REMINDERS_REVALIDATION: + if supervisiontrack.expiration_date.date() - now.date() == datetime.timedelta( + days=expiration_reminder + ): warned_count += 1 - temp_url = TemporaryUrl.objects.create_temporary_url(TemporaryUrl.YEARREVALIDATION, supervisiontrack) + temp_url = TemporaryUrl.objects.create_temporary_url( + TemporaryUrl.YEARREVALIDATION, + supervisiontrack, + ) context = { - 'user': user, - 'expiration_date': supervisiontrack.expiration_date.date(), + "user": user, + "expiration_date": supervisiontrack.expiration_date.date(), "prefix": server_address, "temp_url": temp_url.url_hash, } - 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())) - + 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() + ) + ) def get_input_data(self, message, default=None): """ Override this method if you want to customize data inputs or validation exceptions. """ - raw_value = raw_input(message) + raw_value = input(message) - if default and raw_value == '': + if default and raw_value == "": raw_value = default return raw_value diff --git a/beat/web/accounts/migrations/0001_initial.py b/beat/web/accounts/migrations/0001_initial.py index d625ed392219b0bdc068116681ace6581fd7d4ae..eff3bc50534a7a138e9bc4e7b1b2bb8aeb413007 100644 --- a/beat/web/accounts/migrations/0001_initial.py +++ b/beat/web/accounts/migrations/0001_initial.py @@ -27,8 +27,9 @@ from __future__ import unicode_literals -from django.db import migrations, models from django.conf import settings +from django.db import migrations +from django.db import models class Migration(migrations.Migration): @@ -39,17 +40,34 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name='AccountSettings', + name="AccountSettings", fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('daily_summary', models.BooleanField(default=True)), - ('experiment_mail_notifications_enabled', models.BooleanField(default=True)), - ('database_notifications_enabled', models.BooleanField(default=True)), - ('environment_notifications_enabled', models.BooleanField(default=True)), - ('owner', models.OneToOneField(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)), + ( + "id", + models.AutoField( + verbose_name="ID", + serialize=False, + auto_created=True, + primary_key=True, + ), + ), + ("daily_summary", models.BooleanField(default=True)), + ( + "experiment_mail_notifications_enabled", + models.BooleanField(default=True), + ), + ("database_notifications_enabled", models.BooleanField(default=True)), + ( + "environment_notifications_enabled", + models.BooleanField(default=True), + ), + ( + "owner", + models.OneToOneField( + to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE + ), + ), ], - options={ - 'verbose_name_plural': 'account settings', - }, + options={"verbose_name_plural": "account settings"}, ), ] diff --git a/beat/web/accounts/migrations/0002_profile.py b/beat/web/accounts/migrations/0002_profile.py index d20bbcfb9c4b69511ca77f4e43166d827bf1c1c9..6eb131319050dc7f5a5d9d602a5880aefca5a4f5 100644 --- a/beat/web/accounts/migrations/0002_profile.py +++ b/beat/web/accounts/migrations/0002_profile.py @@ -2,27 +2,59 @@ # Generated by Django 1.9.5 on 2017-05-08 17:00 from __future__ import unicode_literals -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion +from django.conf import settings +from django.db import migrations +from django.db import models class Migration(migrations.Migration): dependencies = [ migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('accounts', '0001_initial'), + ("accounts", "0001_initial"), ] operations = [ migrations.CreateModel( - name='Profile', + name="Profile", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('status', models.CharField(choices=[(b'A', b'Accepted'), (b'R', b'Rejected'), (b'W', b'Waiting Validation'), (b'B', b'Blocked')], default=b'B', max_length=1)), - ('is_godfather', models.BooleanField(default=False)), - ('supervisees', models.ManyToManyField(blank=True, related_name='users', to=settings.AUTH_USER_MODEL)), - ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "status", + models.CharField( + choices=[ + (b"A", b"Accepted"), + (b"R", b"Rejected"), + (b"W", b"Waiting Validation"), + (b"B", b"Blocked"), + ], + default=b"B", + max_length=1, + ), + ), + ("is_godfather", models.BooleanField(default=False)), + ( + "supervisees", + models.ManyToManyField( + blank=True, related_name="users", to=settings.AUTH_USER_MODEL + ), + ), + ( + "user", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + to=settings.AUTH_USER_MODEL, + ), + ), ], ), ] diff --git a/beat/web/accounts/migrations/0003_auto_20170518_1232.py b/beat/web/accounts/migrations/0003_auto_20170518_1232.py index f14663979235a4738808109856b055b994e611a1..460d297c1f60c00436fc0adeedf9328bbea6b669 100644 --- a/beat/web/accounts/migrations/0003_auto_20170518_1232.py +++ b/beat/web/accounts/migrations/0003_auto_20170518_1232.py @@ -2,38 +2,60 @@ # Generated by Django 1.9.5 on 2017-05-18 12:32 from __future__ import unicode_literals -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion +from django.conf import settings +from django.db import migrations +from django.db import models class Migration(migrations.Migration): dependencies = [ migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('accounts', '0002_profile'), + ("accounts", "0002_profile"), ] operations = [ migrations.CreateModel( - name='SupervisionTrack', + name="SupervisionTrack", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('is_valid', models.BooleanField(default=False)), - ('start_date', models.DateTimeField(blank=True, null=True)), - ('expiration_date', models.DateTimeField(blank=True, null=True)), - ('last_validation_date', models.DateTimeField(blank=True, null=True)), - ('godfather', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='supervisees', to=settings.AUTH_USER_MODEL)), - ('supervisee', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='supervisors', to=settings.AUTH_USER_MODEL)), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("is_valid", models.BooleanField(default=False)), + ("start_date", models.DateTimeField(blank=True, null=True)), + ("expiration_date", models.DateTimeField(blank=True, null=True)), + ("last_validation_date", models.DateTimeField(blank=True, null=True)), + ( + "godfather", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + related_name="supervisees", + to=settings.AUTH_USER_MODEL, + ), + ), + ( + "supervisee", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + related_name="supervisors", + to=settings.AUTH_USER_MODEL, + ), + ), ], ), - migrations.RemoveField( - model_name='profile', - name='supervisees', - ), + migrations.RemoveField(model_name="profile", name="supervisees",), migrations.AddField( - model_name='profile', - name='supervision', - field=models.ManyToManyField(blank=True, related_name='profiles', to='accounts.SupervisionTrack'), + model_name="profile", + name="supervision", + field=models.ManyToManyField( + blank=True, related_name="profiles", to="accounts.SupervisionTrack" + ), ), ] diff --git a/beat/web/accounts/migrations/0004_auto_20170523_1736.py b/beat/web/accounts/migrations/0004_auto_20170523_1736.py index bfe5e0b238a1bd465a7d22391db1a93ca0c552d7..af6606c049d5e78705fd53e5cb094f9d71526b63 100644 --- a/beat/web/accounts/migrations/0004_auto_20170523_1736.py +++ b/beat/web/accounts/migrations/0004_auto_20170523_1736.py @@ -2,24 +2,25 @@ # Generated by Django 1.9.5 on 2017-05-23 17:36 from __future__ import unicode_literals -from django.db import migrations, models +from django.db import migrations +from django.db import models class Migration(migrations.Migration): dependencies = [ - ('accounts', '0003_auto_20170518_1232'), + ("accounts", "0003_auto_20170518_1232"), ] operations = [ migrations.AddField( - model_name='profile', - name='supervision_key', + model_name="profile", + name="supervision_key", field=models.CharField(blank=True, max_length=40, null=True), ), migrations.AddField( - model_name='supervisiontrack', - name='supervision_key', + model_name="supervisiontrack", + name="supervision_key", field=models.CharField(blank=True, max_length=40, null=True), ), ] diff --git a/beat/web/accounts/migrations/0005_auto_20170608_0935.py b/beat/web/accounts/migrations/0005_auto_20170608_0935.py index 60270a7b442a6e638d721252c11c18aeb325c3f6..d9e2997323e436b93903f206e695fc4f2a56dd46 100644 --- a/beat/web/accounts/migrations/0005_auto_20170608_0935.py +++ b/beat/web/accounts/migrations/0005_auto_20170608_0935.py @@ -2,24 +2,36 @@ # Generated by Django 1.9.5 on 2017-06-08 09:35 from __future__ import unicode_literals -from django.db import migrations, models +from django.db import migrations +from django.db import models class Migration(migrations.Migration): dependencies = [ - ('accounts', '0004_auto_20170523_1736'), + ("accounts", "0004_auto_20170523_1736"), ] operations = [ migrations.AddField( - model_name='profile', - name='registration_date', + model_name="profile", + name="registration_date", field=models.DateTimeField(blank=True, null=True), ), migrations.AlterField( - model_name='profile', - name='status', - field=models.CharField(choices=[(b'N', b'New User'), (b'W', b'Waiting Validation'), (b'A', b'Accepted'), (b'R', b'Rejected'), (b'Y', b'Yearly revalidation'), (b'B', b'Blocked no supervisor')], default=b'B', max_length=1), + model_name="profile", + name="status", + field=models.CharField( + choices=[ + (b"N", b"New User"), + (b"W", b"Waiting Validation"), + (b"A", b"Accepted"), + (b"R", b"Rejected"), + (b"Y", b"Yearly revalidation"), + (b"B", b"Blocked no supervisor"), + ], + default=b"B", + max_length=1, + ), ), ] diff --git a/beat/web/accounts/migrations/0006_auto_20170608_1451.py b/beat/web/accounts/migrations/0006_auto_20170608_1451.py index a0e80203a504f995905542446ee1186823e12505..fc7fcd8418f78eb95db7c5d90029d2648790ee50 100644 --- a/beat/web/accounts/migrations/0006_auto_20170608_1451.py +++ b/beat/web/accounts/migrations/0006_auto_20170608_1451.py @@ -2,21 +2,26 @@ # Generated by Django 1.9.5 on 2017-06-08 14:51 from __future__ import unicode_literals -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion +from django.conf import settings +from django.db import migrations +from django.db import models class Migration(migrations.Migration): dependencies = [ - ('accounts', '0005_auto_20170608_0935'), + ("accounts", "0005_auto_20170608_0935"), ] operations = [ migrations.AlterField( - model_name='supervisiontrack', - name='godfather', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='supervisees', to=settings.AUTH_USER_MODEL), + model_name="supervisiontrack", + name="godfather", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="supervisees", + to=settings.AUTH_USER_MODEL, + ), ), ] diff --git a/beat/web/accounts/migrations/0007_profile_first_rejection_date.py b/beat/web/accounts/migrations/0007_profile_first_rejection_date.py index ff5cac2066bca90f4a195a5f5936c1e0c86780d7..7eace043e191959dce14415f7230c5adfcdf34f8 100644 --- a/beat/web/accounts/migrations/0007_profile_first_rejection_date.py +++ b/beat/web/accounts/migrations/0007_profile_first_rejection_date.py @@ -2,19 +2,20 @@ # Generated by Django 1.9.5 on 2017-06-26 14:06 from __future__ import unicode_literals -from django.db import migrations, models +from django.db import migrations +from django.db import models class Migration(migrations.Migration): dependencies = [ - ('accounts', '0006_auto_20170608_1451'), + ("accounts", "0006_auto_20170608_1451"), ] operations = [ migrations.AddField( - model_name='profile', - name='first_rejection_date', + model_name="profile", + name="first_rejection_date", field=models.DateTimeField(blank=True, null=True), ), ] diff --git a/beat/web/accounts/migrations/0008_auto_20170626_1516.py b/beat/web/accounts/migrations/0008_auto_20170626_1516.py index f1ac0352304f8d6924686edc1f12ddf0397abe4c..60f13a2395e85a80d2d32e72a56de145cb52847c 100644 --- a/beat/web/accounts/migrations/0008_auto_20170626_1516.py +++ b/beat/web/accounts/migrations/0008_auto_20170626_1516.py @@ -8,13 +8,13 @@ from django.db import migrations class Migration(migrations.Migration): dependencies = [ - ('accounts', '0007_profile_first_rejection_date'), + ("accounts", "0007_profile_first_rejection_date"), ] operations = [ migrations.RenameField( - model_name='profile', - old_name='first_rejection_date', - new_name='rejection_date', + model_name="profile", + old_name="first_rejection_date", + new_name="rejection_date", ), ] diff --git a/beat/web/accounts/migrations/0009_auto_20170627_0956.py b/beat/web/accounts/migrations/0009_auto_20170627_0956.py index 00e134aecaa5d92635068f42feab0b5102feeec5..9b052bba7ea978fc4339d5aa740432132cbe8522 100644 --- a/beat/web/accounts/migrations/0009_auto_20170627_0956.py +++ b/beat/web/accounts/migrations/0009_auto_20170627_0956.py @@ -2,21 +2,26 @@ # Generated by Django 1.9.5 on 2017-06-27 09:56 from __future__ import unicode_literals -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion +from django.conf import settings +from django.db import migrations +from django.db import models class Migration(migrations.Migration): dependencies = [ - ('accounts', '0008_auto_20170626_1516'), + ("accounts", "0008_auto_20170626_1516"), ] operations = [ migrations.AlterField( - model_name='supervisiontrack', - name='supervisee', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='supervisors', to=settings.AUTH_USER_MODEL), + model_name="supervisiontrack", + name="supervisee", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="supervisors", + to=settings.AUTH_USER_MODEL, + ), ), ] diff --git a/beat/web/accounts/migrations/0010_rename_godfather_to_supervisor.py b/beat/web/accounts/migrations/0010_rename_godfather_to_supervisor.py index 8471d56a2861c66dd453adadbb6b6c82c8041654..8a247142fa44bb85d5e6eea9006abef34b0918a3 100644 --- a/beat/web/accounts/migrations/0010_rename_godfather_to_supervisor.py +++ b/beat/web/accounts/migrations/0010_rename_godfather_to_supervisor.py @@ -8,18 +8,14 @@ from django.db import migrations class Migration(migrations.Migration): dependencies = [ - ('accounts', '0009_auto_20170627_0956'), + ("accounts", "0009_auto_20170627_0956"), ] operations = [ migrations.RenameField( - model_name='profile', - old_name='is_godfather', - new_name='is_supervisor', + model_name="profile", old_name="is_godfather", new_name="is_supervisor", ), migrations.RenameField( - model_name='supervisiontrack', - old_name='godfather', - new_name='supervisor', + model_name="supervisiontrack", old_name="godfather", new_name="supervisor", ), ] diff --git a/beat/web/accounts/migrations/0011_check_all_accounts.py b/beat/web/accounts/migrations/0011_check_all_accounts.py index ae3df134561f591ca4b09c82c2e364cb3025f498..b0de5e7b1f0864ff3cea4ff8f5e1103c089be58d 100755 --- a/beat/web/accounts/migrations/0011_check_all_accounts.py +++ b/beat/web/accounts/migrations/0011_check_all_accounts.py @@ -27,62 +27,60 @@ from __future__ import unicode_literals -from django.db.models import Q -from django.urls import reverse -from django.template import loader +import datetime from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion from django.contrib.auth.models import User -from datetime import datetime, timedelta -import datetime -import re +from django.db import migrations +from django.template import loader + try: from urlparse import urlparse except ImportError: from urllib.parse import urlparse -import simplejson as json def set_profile_state(apps, schema_editor): - '''Set profile status''' - - profiles = apps.get_model("accounts", "Profile") - supervisiontracks = apps.get_model("accounts", "SupervisionTrack") + """Set profile status""" users = User.objects.all() now = datetime.datetime.now() - expiration_date_delta = datetime.timedelta(days=settings.ACCOUNT_BLOCKAGE_AFTER_FIRST_REJECTION_DAYS) + 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.status = "A" user.profile.rejection_date = None else: - #reject this account and inform by email the user - user.profile.status = 'R' + # 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) + server_address = "%s://%s" % (parsed_url.scheme, parsed_url.hostname) context = { - 'user': user, - 'prefix': server_address, + "user": user, + "prefix": server_address, } - t = loader.get_template('registration/mail.migration_10_accounts.subject.txt') - subject = t.render(c) + 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()) + subject = settings.EMAIL_SUBJECT_PREFIX + "".join(subject.splitlines()) - t = loader.get_template('registration/mail.migration_10_accounts.message.txt') - message = t.render(c) + 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]) @@ -91,15 +89,15 @@ def set_profile_state(apps, schema_editor): user.profile.save() user.save() + def backward_dummy(apps, schema_editor): pass + class Migration(migrations.Migration): dependencies = [ - ('accounts', '0010_rename_godfather_to_supervisor'), + ("accounts", "0010_rename_godfather_to_supervisor"), ] - operations = [ - migrations.RunPython(set_profile_state, backward_dummy) - ] + operations = [migrations.RunPython(set_profile_state, backward_dummy)] diff --git a/beat/web/accounts/migrations/0012_accounts_temporary_url.py b/beat/web/accounts/migrations/0012_accounts_temporary_url.py index 491cc79881553a5ea0e42a986f718dfbb62099aa..97b52d4362913630a64cbd0f9724939f5e84cec8 100644 --- a/beat/web/accounts/migrations/0012_accounts_temporary_url.py +++ b/beat/web/accounts/migrations/0012_accounts_temporary_url.py @@ -2,8 +2,9 @@ # Generated by Django 1.11.26 on 2020-05-02 03:02 from __future__ import unicode_literals -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations +from django.db import models class Migration(migrations.Migration): diff --git a/beat/web/accounts/migrations/0013_supervisee_rejection_temporary_url.py b/beat/web/accounts/migrations/0013_supervisee_rejection_temporary_url.py index e2ccb4575527c557fb3e971456960ba70b6132d5..c82f8e9331213235815d156ac16fb20c8e533b5b 100644 --- a/beat/web/accounts/migrations/0013_supervisee_rejection_temporary_url.py +++ b/beat/web/accounts/migrations/0013_supervisee_rejection_temporary_url.py @@ -2,7 +2,8 @@ # Generated by Django 1.11.26 on 2020-05-13 18:48 from __future__ import unicode_literals -from django.db import migrations, models +from django.db import migrations +from django.db import models class Migration(migrations.Migration): diff --git a/beat/web/accounts/models.py b/beat/web/accounts/models.py index 456e5d5773c2ff6e5ffe2bf98f32ea5e7a820764..5e49647d48af52d067cbe7d070c740a34be392b3 100644 --- a/beat/web/accounts/models.py +++ b/beat/web/accounts/models.py @@ -25,15 +25,15 @@ # # ############################################################################### -from django.db import models +import datetime +import random +import string + +from django.conf import settings from django.contrib.auth.models import User +from django.db import models from django.db.models.signals import post_save from django.dispatch import receiver -from django.conf import settings - -import random -import string -import datetime # ------------------------------------------------------------------------------ # Constants diff --git a/beat/web/accounts/permissions.py b/beat/web/accounts/permissions.py index 6f702c7bc9700db5ddc4b5874845295dcb18ec74..86d1756e46aeb0aa4aa65448e25089547e132362 100644 --- a/beat/web/accounts/permissions.py +++ b/beat/web/accounts/permissions.py @@ -27,53 +27,59 @@ from rest_framework import permissions - -#---------------------------------------------------------- +# ---------------------------------------------------------- class IsSupervisorAndAuthor(permissions.BasePermission): """ The logged in user should also be the author """ - message = 'Not a supervisor account' + + message = "Not a supervisor account" def has_permission(self, request, view): return request.user.profile.is_supervisor or request.user.is_superuser -#---------------------------------------------------------- +# ---------------------------------------------------------- class IsAuthorAndNotSupervisor(permissions.BasePermission): """ The logged in user should also be the author """ - message = 'Not a supervisee account' + + message = "Not a supervisee account" def has_permission(self, request, view): return not request.user.profile.is_supervisor -#---------------------------------------------------------- +# ---------------------------------------------------------- class IsAuthorAndPossiblySupervisor(permissions.BasePermission): """ The logged in user should also be the author """ - message = 'Not a supervisee account' + + message = "Not a supervisee account" def has_permission(self, request, view): - return not request.user.profile.is_supervisor or request.user.profile.is_supervisor + return ( + not request.user.profile.is_supervisor or request.user.profile.is_supervisor + ) + -#---------------------------------------------------------- +# ---------------------------------------------------------- class IsSuperUser(permissions.BasePermission): """ The logged in user should also be the author """ - message = 'Not a supervisee account' + + message = "Not a supervisee account" def has_permission(self, request, view): return request.user.is_superuser diff --git a/beat/web/accounts/serializers.py b/beat/web/accounts/serializers.py index 59679a3754d2e917cc8aeee30d320da82e7d26b4..8b0ab06c260521e2008d66f4ab0987c889dc86dc 100644 --- a/beat/web/accounts/serializers.py +++ b/beat/web/accounts/serializers.py @@ -30,7 +30,6 @@ from rest_framework import serializers from .models import SupervisionTrack - # ---------------------------------------------------------- diff --git a/beat/web/accounts/signals.py b/beat/web/accounts/signals.py index a2e4c1c842369a87dc35a289eb6919d79dbc0936..b47339e955eac49b9ece9cd30151b7a5ebfa69db 100644 --- a/beat/web/accounts/signals.py +++ b/beat/web/accounts/signals.py @@ -25,22 +25,17 @@ # # ############################################################################### +import django.dispatch +from actstream import action +from django.conf import settings +from django.contrib.auth.models import Group +from django.contrib.auth.models import User from django.db.models.signals import post_save from django.dispatch import receiver - -from django.contrib.auth.models import User -from django.contrib.auth.models import Group - -from django.conf import settings - from rest_framework.authtoken.models import Token -from actstream import action - from .models import AccountSettings -import django.dispatch - supervision_request = django.dispatch.Signal() diff --git a/beat/web/accounts/templates/accounts/dialogs/admin_remove_supervisor_mode.html b/beat/web/accounts/templates/accounts/dialogs/admin_remove_supervisor_mode.html index f59bb60d4856fa6ef9f29a9aae5fe0e0cd67dde5..4c4837847a2b7ae6c47d11e8c0af92361901802c 100644 --- a/beat/web/accounts/templates/accounts/dialogs/admin_remove_supervisor_mode.html +++ b/beat/web/accounts/templates/accounts/dialogs/admin_remove_supervisor_mode.html @@ -1,21 +1,21 @@ {% comment %} * Copyright (c) 2016 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/. {% endcomment %} diff --git a/beat/web/accounts/templates/accounts/dialogs/admin_set_supervisor_mode.html b/beat/web/accounts/templates/accounts/dialogs/admin_set_supervisor_mode.html index e94776e70a4b8106ca4a5b6f8ada54feaeee0192..be92591211aad3f02f4192476cf438bcafa43bc8 100644 --- a/beat/web/accounts/templates/accounts/dialogs/admin_set_supervisor_mode.html +++ b/beat/web/accounts/templates/accounts/dialogs/admin_set_supervisor_mode.html @@ -1,21 +1,21 @@ {% comment %} * Copyright (c) 2016 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/. {% endcomment %} diff --git a/beat/web/accounts/templates/accounts/dialogs/change_supervisor.html b/beat/web/accounts/templates/accounts/dialogs/change_supervisor.html index eecd972442a89839749e3ccc0fb5b654ae839576..83a261b85eae744bab00038558652606b018f0b0 100644 --- a/beat/web/accounts/templates/accounts/dialogs/change_supervisor.html +++ b/beat/web/accounts/templates/accounts/dialogs/change_supervisor.html @@ -1,21 +1,21 @@ {% comment %} * Copyright (c) 2016 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/. {% endcomment %} diff --git a/beat/web/accounts/templates/accounts/dialogs/remove_supervisee.html b/beat/web/accounts/templates/accounts/dialogs/remove_supervisee.html index a4743fbe2a34563d33aa71b2cc6fdccca05ab6cd..1d893d0f1c38acc7455c7cbbeb9869b8329dba0e 100644 --- a/beat/web/accounts/templates/accounts/dialogs/remove_supervisee.html +++ b/beat/web/accounts/templates/accounts/dialogs/remove_supervisee.html @@ -1,21 +1,21 @@ {% comment %} * Copyright (c) 2016 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/. {% endcomment %} diff --git a/beat/web/accounts/templates/accounts/dialogs/remove_supervisor_supervisee.html b/beat/web/accounts/templates/accounts/dialogs/remove_supervisor_supervisee.html index d1875f3b16d8840f6072d4d9dd103c1a53c6a5b4..e308a24dc5a05b48e508a90594e1e943fb3a97fa 100644 --- a/beat/web/accounts/templates/accounts/dialogs/remove_supervisor_supervisee.html +++ b/beat/web/accounts/templates/accounts/dialogs/remove_supervisor_supervisee.html @@ -1,21 +1,21 @@ {% comment %} * Copyright (c) 2016 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/. {% endcomment %} diff --git a/beat/web/accounts/templates/accounts/dialogs/renew_account.html b/beat/web/accounts/templates/accounts/dialogs/renew_account.html index e94afdb87174c7054c4a3c8db55a3cf643492431..3a1ee192379fa87d8d48de9295250062fe09e1fd 100644 --- a/beat/web/accounts/templates/accounts/dialogs/renew_account.html +++ b/beat/web/accounts/templates/accounts/dialogs/renew_account.html @@ -1,21 +1,21 @@ {% comment %} * Copyright (c) 2016 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/. {% endcomment %} diff --git a/beat/web/accounts/templates/accounts/dialogs/validate_supervisee.html b/beat/web/accounts/templates/accounts/dialogs/validate_supervisee.html index e90a8ed36cb54c4c6fedb0a9524dae437c179ee6..c01d2550066841325bd47bc0274d64e3ae99e979 100644 --- a/beat/web/accounts/templates/accounts/dialogs/validate_supervisee.html +++ b/beat/web/accounts/templates/accounts/dialogs/validate_supervisee.html @@ -1,21 +1,21 @@ {% comment %} * Copyright (c) 2016 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/. {% endcomment %} diff --git a/beat/web/accounts/templatetags/account_tags.py b/beat/web/accounts/templatetags/account_tags.py index b581cbafc1ca0601bd78cc497df15384fabc23c9..952976fd90ef6c1a28b5641d51712b1b1b0fc9b7 100644 --- a/beat/web/accounts/templatetags/account_tags.py +++ b/beat/web/accounts/templatetags/account_tags.py @@ -26,45 +26,55 @@ ############################################################################### -import random - from django import template -from django.conf import settings register = template.Library() -@register.inclusion_tag('accounts/dialogs/renew_account.html') +@register.inclusion_tag("accounts/dialogs/renew_account.html") def account_renew(id): - return { 'dialog_id': id, - } + return { + "dialog_id": id, + } + -@register.inclusion_tag('accounts/dialogs/change_supervisor.html') +@register.inclusion_tag("accounts/dialogs/change_supervisor.html") def change_supervisor(id): - return { 'dialog_id': id, - } + return { + "dialog_id": id, + } -@register.inclusion_tag('accounts/dialogs/validate_supervisee.html') + +@register.inclusion_tag("accounts/dialogs/validate_supervisee.html") def validate_supervisee(id): - return { 'dialog_id': id, - } + return { + "dialog_id": id, + } + -@register.inclusion_tag('accounts/dialogs/remove_supervisee.html') +@register.inclusion_tag("accounts/dialogs/remove_supervisee.html") def remove_supervisee(id): - return { 'dialog_id': id, - } + return { + "dialog_id": id, + } -@register.inclusion_tag('accounts/dialogs/remove_supervisor_supervisee.html') + +@register.inclusion_tag("accounts/dialogs/remove_supervisor_supervisee.html") def remove_supervisor_supervisee(id): - return { 'dialog_id': id, - } + return { + "dialog_id": id, + } + -@register.inclusion_tag('accounts/dialogs/admin_set_supervisor_mode.html') +@register.inclusion_tag("accounts/dialogs/admin_set_supervisor_mode.html") def admin_set_supervisor_mode(id): - return { 'dialog_id': id, - } + return { + "dialog_id": id, + } + -@register.inclusion_tag('accounts/dialogs/admin_remove_supervisor_mode.html') +@register.inclusion_tag("accounts/dialogs/admin_remove_supervisor_mode.html") def admin_remove_supervisor_mode(id): - return { 'dialog_id': id, - } + return { + "dialog_id": id, + } diff --git a/beat/web/accounts/views.py b/beat/web/accounts/views.py index ab678d0560d2d21a11c235dc59a2b72b6106189a..19df8d28355fc0b9a5249b3fd3be85c47facbdd7 100644 --- a/beat/web/accounts/views.py +++ b/beat/web/accounts/views.py @@ -25,32 +25,26 @@ # # ############################################################################### -from django.conf import settings - -from django.shortcuts import render -from django.shortcuts import get_object_or_404 +import datetime +from urllib.parse import urlparse +from django.conf import settings +from django.contrib import messages from django.contrib.auth.decorators import login_required from django.contrib.auth.forms import PasswordChangeForm from django.contrib.auth.models import User -from django.contrib import messages - from django.db import models - +from django.shortcuts import get_object_or_404 +from django.shortcuts import render from rest_framework.authtoken.models import Token +from ..utils import mail from .forms import AccountSettingsForm - from .models import AccountSettings -from .models import SupervisionTrack from .models import Profile +from .models import SupervisionTrack from .models import TemporaryUrl -from ..utils import mail - -import datetime -from urllib.parse import urlparse - @login_required def account_settings(request):