CollectionItem: move version and encryption key to the item itself.
This commit is contained in:
parent
d587f8185b
commit
dfbfa01bc5
33
django_etesync/migrations/0022_auto_20200310_1547.py
Normal file
33
django_etesync/migrations/0022_auto_20200310_1547.py
Normal file
@ -0,0 +1,33 @@
|
||||
# Generated by Django 3.0.3 on 2020-03-10 15:47
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('django_etesync', '0021_auto_20200310_1439'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='collectionitemrevision',
|
||||
name='encryptionKey',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='collectionitemrevision',
|
||||
name='version',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='collectionitem',
|
||||
name='encryptionKey',
|
||||
field=models.BinaryField(default=b'aoesnutheounth', editable=True),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='collectionitem',
|
||||
name='version',
|
||||
field=models.PositiveSmallIntegerField(default=1),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
@ -41,6 +41,8 @@ class CollectionItem(models.Model):
|
||||
uid = models.CharField(db_index=True, blank=False, null=False,
|
||||
max_length=44, validators=[UidValidator])
|
||||
collection = models.ForeignKey(Collection, related_name='items', on_delete=models.CASCADE)
|
||||
version = models.PositiveSmallIntegerField()
|
||||
encryptionKey = models.BinaryField(editable=True, blank=False, null=False)
|
||||
|
||||
class Meta:
|
||||
unique_together = ('uid', 'collection')
|
||||
@ -76,8 +78,6 @@ class CollectionItemChunk(models.Model):
|
||||
|
||||
|
||||
class CollectionItemRevision(models.Model):
|
||||
version = models.PositiveSmallIntegerField()
|
||||
encryptionKey = models.BinaryField(editable=True, blank=False, null=False)
|
||||
item = models.ForeignKey(CollectionItem, related_name='revisions', on_delete=models.CASCADE)
|
||||
chunks = models.ManyToManyField(CollectionItemChunk, related_name='items')
|
||||
hmac = models.CharField(max_length=50, blank=False, null=False)
|
||||
|
@ -54,7 +54,8 @@ class CollectionSerializer(serializers.ModelSerializer):
|
||||
return None
|
||||
|
||||
def get_ctag(self, obj):
|
||||
# FIXME: we need to have something that's more privacy friendly
|
||||
# FIXME: we need to have something that's more privacy friendly. Can probably just generate a uid per revision
|
||||
# on revision creation (on the server) and just use that.
|
||||
last_revision = models.CollectionItemRevision.objects.filter(item__collection=obj).last()
|
||||
if last_revision is None:
|
||||
# FIXME: what is the etag for None? Though if we use the revision for collection it should be shared anyway.
|
||||
@ -86,7 +87,6 @@ class CollectionItemChunkSerializer(serializers.ModelSerializer):
|
||||
|
||||
|
||||
class CollectionItemRevisionBaseSerializer(serializers.ModelSerializer):
|
||||
encryptionKey = BinaryBase64Field()
|
||||
chunks = serializers.SlugRelatedField(
|
||||
slug_field='uid',
|
||||
queryset=models.CollectionItemChunk.objects.all(),
|
||||
@ -95,7 +95,7 @@ class CollectionItemRevisionBaseSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = models.CollectionItemRevision
|
||||
fields = ('version', 'encryptionKey', 'chunks', 'hmac', 'deleted')
|
||||
fields = ('chunks', 'hmac', 'deleted')
|
||||
|
||||
|
||||
class CollectionItemRevisionSerializer(CollectionItemRevisionBaseSerializer):
|
||||
@ -132,11 +132,12 @@ class CollectionItemRevisionInlineSerializer(CollectionItemRevisionBaseSerialize
|
||||
|
||||
|
||||
class CollectionItemSerializer(serializers.ModelSerializer):
|
||||
encryptionKey = BinaryBase64Field()
|
||||
content = CollectionItemRevisionSerializer(many=False)
|
||||
|
||||
class Meta:
|
||||
model = models.CollectionItem
|
||||
fields = ('uid', 'content')
|
||||
fields = ('uid', 'version', 'encryptionKey', 'content')
|
||||
|
||||
def create(self, validated_data):
|
||||
"""Function that's called when this serializer creates an item"""
|
||||
|
Loading…
Reference in New Issue
Block a user