diff --git a/beat/web/accounts/migrations/0012_accounts_tempoary_url.py b/beat/web/accounts/migrations/0012_accounts_tempoary_url.py new file mode 100644 index 0000000000000000000000000000000000000000..b7fc41743ba3c88b6d168ca71bb564af172f4d51 --- /dev/null +++ b/beat/web/accounts/migrations/0012_accounts_tempoary_url.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.26 on 2020-04-27 23:41 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0011_check_all_accounts'), + ] + + operations = [ + migrations.CreateModel( + 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 sueprvisee')], 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), + ), + ] diff --git a/beat/web/accounts/models.py b/beat/web/accounts/models.py index 7e272e8969f96ece4d8bef053433d7cf03e28501..a67f3364bcb011ac77c0627d16611be577b73edb 100644 --- a/beat/web/accounts/models.py +++ b/beat/web/accounts/models.py @@ -29,9 +29,11 @@ from django.db import models from django.contrib.auth.models import User from django.db.models.signals import post_save from django.dispatch import receiver +from django.conf import settings import random import string +import datetime class AccountSettingsManager(models.Manager): @@ -149,3 +151,43 @@ def create_user_profile(sender, instance, created, **kwargs): def save_user_profile(sender, instance, **kwargs): player, created = Profile.objects.get_or_create(user=instance) instance.profile.save() + + +class TemporaryUrl(models.Model): + # _____ Constants __________ + + # Supervisor validates supervisee + # Self yearly revalidation from supervisee + VALIDATION = "V" + YEARREVALIDATION = "Y" + + URL_STATUS = ( + (VALIDATION, "Supervisor validates supervisee"), + (YEARREVALIDATION, "Self yearly revalidation from sueprvisee"), + ) + + # _____ Fields __________ + + status = models.CharField(max_length=1, choices=URL_STATUS, default=VALIDATION) + url_hash = models.CharField("Url", blank=False, max_length=32, unique=True) + expires = models.DateTimeField("Expires") + supervision_track = models.ForeignKey( + SupervisionTrack, on_delete=models.CASCADE, related_name="supervisees" + ) + + def _generate_temporary_url(self, status, supervision_track): + # Actions that result creating the object + + # url_hash creation + length = 32 + url_hash = "".join( + random.choice(string.ascii_letters + string.digits) # nosec + for _ in range(length) + ) + self.url_hash = url_hash + now = datetime.datetime.now() + expiration_date_delta = datetime.timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS_FROM_SUPERVISOR) + self.expires = now + expiration_date_delta + self.status = status + self.supervision_track = supervision_track + self.save()