Commit 7fba594c authored by Flavio TARSETTI's avatar Flavio TARSETTI

[accounts] pre-commit cleanup including migrations

parent efc8efeb
Pipeline #39874 passed with stage
in 14 minutes and 24 seconds
......@@ -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,
}
......
......@@ -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,
),
),
]
......@@ -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,
),
),
]
......@@ -42,6 +42,7 @@ TEMPORARY_URL_LENGTH = 32
# ------------------------------------------------------------------------------
class AccountSettingsManager(models.Manager):
def get_by_natural_key(self, owner):
return self.get(owner=owner)
......
......@@ -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,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment