Uid: Change how validation is done.

This commit is contained in:
Tom Hacohen 2020-05-26 16:26:57 +03:00
parent 10b9d33ffe
commit fce844bfc3
2 changed files with 45 additions and 6 deletions

View File

@ -0,0 +1,39 @@
# Generated by Django 3.0.3 on 2020-05-26 13:36
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('django_etesync', '0006_auto_20200526_1040'),
]
operations = [
migrations.AlterField(
model_name='collection',
name='uid',
field=models.CharField(db_index=True, max_length=43, validators=[django.core.validators.RegexValidator(message='Not a valid UID', regex='^[a-zA-Z0-9]*$')]),
),
migrations.AlterField(
model_name='collectioninvitation',
name='uid',
field=models.CharField(db_index=True, max_length=43, validators=[django.core.validators.RegexValidator(message='Expected a base64url.', regex='^[a-zA-Z0-9\\-_]{42,43}$')]),
),
migrations.AlterField(
model_name='collectionitem',
name='uid',
field=models.CharField(db_index=True, max_length=43, null=True, validators=[django.core.validators.RegexValidator(message='Not a valid UID', regex='^[a-zA-Z0-9]*$')]),
),
migrations.AlterField(
model_name='collectionitemchunk',
name='uid',
field=models.CharField(db_index=True, max_length=43, validators=[django.core.validators.RegexValidator(message='Expected a base64url.', regex='^[a-zA-Z0-9\\-_]{42,43}$')]),
),
migrations.AlterField(
model_name='collectionitemrevision',
name='uid',
field=models.CharField(db_index=True, max_length=43, unique=True, validators=[django.core.validators.RegexValidator(message='Expected a base64url.', regex='^[a-zA-Z0-9\\-_]{42,43}$')]),
),
]

View File

@ -20,13 +20,13 @@ from django.core.validators import RegexValidator
from django.utils.functional import cached_property from django.utils.functional import cached_property
Base64Url256BitValidator = RegexValidator(regex=r'^[a-zA-Z0-9\-_]{43}$', message='Expected a 256bit base64url.') Base64Url256BitlValidator = RegexValidator(regex=r'^[a-zA-Z0-9\-_]{42,43}$', message='Expected a base64url.')
UidValidator = RegexValidator(regex=r'^[a-zA-Z0-9]*$', message='Not a valid UID') UidValidator = RegexValidator(regex=r'^[a-zA-Z0-9]*$', message='Not a valid UID')
class Collection(models.Model): class Collection(models.Model):
uid = models.CharField(db_index=True, blank=False, null=False, uid = models.CharField(db_index=True, blank=False, null=False,
max_length=44, validators=[UidValidator]) max_length=43, validators=[UidValidator])
version = models.PositiveSmallIntegerField() version = models.PositiveSmallIntegerField()
owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
@ -60,7 +60,7 @@ class Collection(models.Model):
class CollectionItem(models.Model): class CollectionItem(models.Model):
uid = models.CharField(db_index=True, blank=False, null=True, uid = models.CharField(db_index=True, blank=False, null=True,
max_length=44, validators=[UidValidator]) max_length=43, validators=[UidValidator])
collection = models.ForeignKey(Collection, related_name='items', on_delete=models.CASCADE) collection = models.ForeignKey(Collection, related_name='items', on_delete=models.CASCADE)
version = models.PositiveSmallIntegerField() version = models.PositiveSmallIntegerField()
encryptionKey = models.BinaryField(editable=True, blank=False, null=True) encryptionKey = models.BinaryField(editable=True, blank=False, null=True)
@ -90,7 +90,7 @@ def chunk_directory_path(instance, filename):
class CollectionItemChunk(models.Model): class CollectionItemChunk(models.Model):
uid = models.CharField(db_index=True, blank=False, null=False, uid = models.CharField(db_index=True, blank=False, null=False,
max_length=44, validators=[Base64Url256BitValidator]) max_length=43, validators=[Base64Url256BitlValidator])
item = models.ForeignKey(CollectionItem, related_name='chunks', on_delete=models.CASCADE) item = models.ForeignKey(CollectionItem, related_name='chunks', on_delete=models.CASCADE)
chunkFile = models.FileField(upload_to=chunk_directory_path, max_length=150, unique=True) chunkFile = models.FileField(upload_to=chunk_directory_path, max_length=150, unique=True)
@ -100,7 +100,7 @@ class CollectionItemChunk(models.Model):
class CollectionItemRevision(models.Model): class CollectionItemRevision(models.Model):
uid = models.CharField(db_index=True, unique=True, blank=False, null=False, uid = models.CharField(db_index=True, unique=True, blank=False, null=False,
max_length=44, validators=[Base64Url256BitValidator]) max_length=43, validators=[Base64Url256BitlValidator])
item = models.ForeignKey(CollectionItem, related_name='revisions', on_delete=models.CASCADE) item = models.ForeignKey(CollectionItem, related_name='revisions', on_delete=models.CASCADE)
meta = models.BinaryField(editable=True, blank=False, null=False) meta = models.BinaryField(editable=True, blank=False, null=False)
current = models.BooleanField(db_index=True, default=True, null=True) current = models.BooleanField(db_index=True, default=True, null=True)
@ -146,7 +146,7 @@ class CollectionMember(models.Model):
class CollectionInvitation(models.Model): class CollectionInvitation(models.Model):
uid = models.CharField(db_index=True, blank=False, null=False, uid = models.CharField(db_index=True, blank=False, null=False,
max_length=44, validators=[Base64Url256BitValidator]) max_length=43, validators=[Base64Url256BitlValidator])
version = models.PositiveSmallIntegerField(default=1) version = models.PositiveSmallIntegerField(default=1)
fromMember = models.ForeignKey(CollectionMember, on_delete=models.CASCADE) fromMember = models.ForeignKey(CollectionMember, on_delete=models.CASCADE)
# FIXME: make sure to delete all invitations for the same collection once one is accepted # FIXME: make sure to delete all invitations for the same collection once one is accepted