mirror of
https://github.com/etesync/server
synced 2024-11-29 12:08:07 +00:00
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,
|
uid = models.CharField(db_index=True, blank=False, null=False,
|
||||||
max_length=44, validators=[UidValidator])
|
max_length=44, 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()
|
||||||
|
encryptionKey = models.BinaryField(editable=True, blank=False, null=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = ('uid', 'collection')
|
unique_together = ('uid', 'collection')
|
||||||
@ -76,8 +78,6 @@ class CollectionItemChunk(models.Model):
|
|||||||
|
|
||||||
|
|
||||||
class CollectionItemRevision(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)
|
item = models.ForeignKey(CollectionItem, related_name='revisions', on_delete=models.CASCADE)
|
||||||
chunks = models.ManyToManyField(CollectionItemChunk, related_name='items')
|
chunks = models.ManyToManyField(CollectionItemChunk, related_name='items')
|
||||||
hmac = models.CharField(max_length=50, blank=False, null=False)
|
hmac = models.CharField(max_length=50, blank=False, null=False)
|
||||||
|
@ -54,7 +54,8 @@ class CollectionSerializer(serializers.ModelSerializer):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def get_ctag(self, obj):
|
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()
|
last_revision = models.CollectionItemRevision.objects.filter(item__collection=obj).last()
|
||||||
if last_revision is None:
|
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.
|
# 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):
|
class CollectionItemRevisionBaseSerializer(serializers.ModelSerializer):
|
||||||
encryptionKey = BinaryBase64Field()
|
|
||||||
chunks = serializers.SlugRelatedField(
|
chunks = serializers.SlugRelatedField(
|
||||||
slug_field='uid',
|
slug_field='uid',
|
||||||
queryset=models.CollectionItemChunk.objects.all(),
|
queryset=models.CollectionItemChunk.objects.all(),
|
||||||
@ -95,7 +95,7 @@ class CollectionItemRevisionBaseSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.CollectionItemRevision
|
model = models.CollectionItemRevision
|
||||||
fields = ('version', 'encryptionKey', 'chunks', 'hmac', 'deleted')
|
fields = ('chunks', 'hmac', 'deleted')
|
||||||
|
|
||||||
|
|
||||||
class CollectionItemRevisionSerializer(CollectionItemRevisionBaseSerializer):
|
class CollectionItemRevisionSerializer(CollectionItemRevisionBaseSerializer):
|
||||||
@ -132,11 +132,12 @@ class CollectionItemRevisionInlineSerializer(CollectionItemRevisionBaseSerialize
|
|||||||
|
|
||||||
|
|
||||||
class CollectionItemSerializer(serializers.ModelSerializer):
|
class CollectionItemSerializer(serializers.ModelSerializer):
|
||||||
|
encryptionKey = BinaryBase64Field()
|
||||||
content = CollectionItemRevisionSerializer(many=False)
|
content = CollectionItemRevisionSerializer(many=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.CollectionItem
|
model = models.CollectionItem
|
||||||
fields = ('uid', 'content')
|
fields = ('uid', 'version', 'encryptionKey', 'content')
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
"""Function that's called when this serializer creates an item"""
|
"""Function that's called when this serializer creates an item"""
|
||||||
|
Loading…
Reference in New Issue
Block a user