diff --git a/beat/web/accounts/api.py b/beat/web/accounts/api.py index 1739565a9b5d2ed90b6b92b097a58d445044f3ed..b820cf32878dd3b75d671ab822b7a3578157cbde 100644 --- a/beat/web/accounts/api.py +++ b/beat/web/accounts/api.py @@ -583,7 +583,9 @@ class SuperviseeReValidationView(BaseUpdateSupervisionTrackFromSuperviseeView): supervisee__profile__supervision_key=models.F("supervision_key"), ) - success, error_message = perform_revalidation(request, supervisiontrack, supervisee, now) + success, error_message = perform_revalidation( + request, supervisiontrack, supervisee, now + ) result = { "error": error_message, } diff --git a/beat/web/accounts/migrations/0012_accounts_temporary_url.py b/beat/web/accounts/migrations/0012_accounts_temporary_url.py index 2febd0aca48c461d7b077b30c88eec2cb2492522..491cc79881553a5ea0e42a986f718dfbb62099aa 100644 --- a/beat/web/accounts/migrations/0012_accounts_temporary_url.py +++ b/beat/web/accounts/migrations/0012_accounts_temporary_url.py @@ -9,23 +9,62 @@ import django.db.models.deletion class Migration(migrations.Migration): dependencies = [ - ('accounts', '0011_check_all_accounts'), + ("accounts", "0011_check_all_accounts"), ] operations = [ migrations.CreateModel( - name='TemporaryUrl', + name="TemporaryUrl", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('status', models.CharField(choices=[('V', 'Supervisor validates supervisee'), ('Y', 'Self yearly revalidation from supervisee')], default='V', max_length=1)), - ('url_hash', models.CharField(max_length=32, unique=True, verbose_name='Url')), - ('expires', models.DateTimeField(verbose_name='Expires')), - ('supervision_track', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='supervisees', to='accounts.SupervisionTrack')), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "status", + models.CharField( + choices=[ + ("V", "Supervisor validates supervisee"), + ("Y", "Self yearly revalidation from supervisee"), + ], + default="V", + max_length=1, + ), + ), + ( + "url_hash", + models.CharField(max_length=32, unique=True, verbose_name="Url"), + ), + ("expires", models.DateTimeField(verbose_name="Expires")), + ( + "supervision_track", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="supervisees", + to="accounts.SupervisionTrack", + ), + ), ], ), migrations.AlterField( - model_name='profile', - name='status', - field=models.CharField(choices=[('N', 'New User'), ('W', 'Waiting Validation'), ('A', 'Accepted'), ('R', 'Rejected'), ('Y', 'Yearly revalidation'), ('B', 'Blocked no supervisor')], default='B', max_length=1), + model_name="profile", + name="status", + field=models.CharField( + choices=[ + ("N", "New User"), + ("W", "Waiting Validation"), + ("A", "Accepted"), + ("R", "Rejected"), + ("Y", "Yearly revalidation"), + ("B", "Blocked no supervisor"), + ], + default="B", + max_length=1, + ), ), ] 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 459b9ca9cecdc022f743c59302a3cf9408fc0d4d..e2ccb4575527c557fb3e971456960ba70b6132d5 100644 --- a/beat/web/accounts/migrations/0013_supervisee_rejection_temporary_url.py +++ b/beat/web/accounts/migrations/0013_supervisee_rejection_temporary_url.py @@ -8,13 +8,21 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('accounts', '0012_accounts_temporary_url'), + ("accounts", "0012_accounts_temporary_url"), ] operations = [ migrations.AlterField( - model_name='temporaryurl', - name='status', - field=models.CharField(choices=[('V', 'Supervisor validates supervisee'), ('Y', 'Self yearly revalidation from supervisee'), ('R', 'Supervisor rejects supervisee revalidation')], default='V', max_length=1), + model_name="temporaryurl", + name="status", + field=models.CharField( + choices=[ + ("V", "Supervisor validates supervisee"), + ("Y", "Self yearly revalidation from supervisee"), + ("R", "Supervisor rejects supervisee revalidation"), + ], + default="V", + max_length=1, + ), ), ] diff --git a/beat/web/accounts/models.py b/beat/web/accounts/models.py index 2444a6a243bf9045fac5ee9c98af41caa9b7df0e..a3de68edd822aa474407fa3e672648840c477900 100644 --- a/beat/web/accounts/models.py +++ b/beat/web/accounts/models.py @@ -42,6 +42,7 @@ TEMPORARY_URL_LENGTH = 32 # ------------------------------------------------------------------------------ + class AccountSettingsManager(models.Manager): def get_by_natural_key(self, owner): return self.get(owner=owner) diff --git a/beat/web/accounts/views.py b/beat/web/accounts/views.py index 4e5de831aa1a4a9108c74fd2166150c9f76a6e17..ab678d0560d2d21a11c235dc59a2b72b6106189a 100644 --- a/beat/web/accounts/views.py +++ b/beat/web/accounts/views.py @@ -47,7 +47,6 @@ from .models import Profile from .models import TemporaryUrl from ..utils import mail -from ..common.responses import BadRequestResponse import datetime from urllib.parse import urlparse @@ -253,10 +252,7 @@ def perform_revalidation(request, supervisiontrack, supervisee, now): # Inform supervisor about supervisee revalidation # Possible supervisor rejection available 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,) temp_url_rejection = TemporaryUrl.objects.create_temporary_url( TemporaryUrl.REJECTION, supervisiontrack @@ -276,23 +272,21 @@ def perform_revalidation(request, supervisiontrack, supervisee, now): [supervisiontrack.supervisor.email], ) success = True - return(success, error_message) + return (success, error_message) else: # Track already valid error_message = "You don't need to revalidate at the moment, your supervision is still valid" - return(success, error_message) + return (success, error_message) else: # A pending request already exist error_message = "You are not able to perform this action as you already have a pending supervision request" - return(success, error_message) + return (success, error_message) def accept_supervisee(supervisiontrack, supervisee, now): supervisiontrack.is_valid = True - expiration_date_delta = datetime.timedelta( - days=settings.ACCOUNT_EXPIRATION_DAYS - ) + expiration_date_delta = datetime.timedelta(days=settings.ACCOUNT_EXPIRATION_DAYS) supervisiontrack.expiration_date = now + expiration_date_delta supervisiontrack.start_date = now @@ -321,6 +315,7 @@ def accept_supervisee(supervisiontrack, supervisee, now): [supervisee.email], ) + def generate_load_response(request, temp_url, template, parameters): answer = {} answer["template"] = template @@ -357,7 +352,9 @@ def load_temporary_url_validation(request, hash_url): elif temp_url.status == TemporaryUrl.YEARREVALIDATION: # Supervisee re-validation if supervisee.profile.supervision_key is not None and now < temp_url.expires: - success, error_message = perform_revalidation(request, supervisiontrack, supervisee, now) + success, error_message = perform_revalidation( + request, supervisiontrack, supervisee, now + ) if not success: return generate_load_response( request,