mirror of
https://github.com/etesync/server
synced 2024-11-26 02:38:15 +00:00
CollectionMember: add stokens when we create/change the member.
This commit is contained in:
parent
91aadb6565
commit
1f18f4e50b
19
django_etesync/migrations/0011_collectionmember_stoken.py
Normal file
19
django_etesync/migrations/0011_collectionmember_stoken.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 3.0.3 on 2020-05-27 07:43
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('django_etesync', '0010_auto_20200526_1539'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='collectionmember',
|
||||||
|
name='stoken',
|
||||||
|
field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.PROTECT, to='django_etesync.Stoken'),
|
||||||
|
),
|
||||||
|
]
|
23
django_etesync/migrations/0012_auto_20200527_0743.py
Normal file
23
django_etesync/migrations/0012_auto_20200527_0743.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 3.0.3 on 2020-05-27 07:43
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def create_stokens(apps, schema_editor):
|
||||||
|
Stoken = apps.get_model('django_etesync', 'Stoken')
|
||||||
|
CollectionMember = apps.get_model('django_etesync', 'CollectionMember')
|
||||||
|
|
||||||
|
for member in CollectionMember.objects.all():
|
||||||
|
member.stoken = Stoken.objects.create()
|
||||||
|
member.save()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('django_etesync', '0011_collectionmember_stoken'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(create_stokens),
|
||||||
|
]
|
@ -139,6 +139,7 @@ class AccessLevels(models.TextChoices):
|
|||||||
|
|
||||||
|
|
||||||
class CollectionMember(models.Model):
|
class CollectionMember(models.Model):
|
||||||
|
stoken = models.OneToOneField(Stoken, on_delete=models.PROTECT, null=True)
|
||||||
collection = models.ForeignKey(Collection, related_name='members', on_delete=models.CASCADE)
|
collection = models.ForeignKey(Collection, related_name='members', on_delete=models.CASCADE)
|
||||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||||||
encryptionKey = models.BinaryField(editable=True, blank=False, null=False)
|
encryptionKey = models.BinaryField(editable=True, blank=False, null=False)
|
||||||
|
@ -212,6 +212,7 @@ class CollectionSerializer(serializers.ModelSerializer):
|
|||||||
process_revisions_for_item(main_item, revision_data)
|
process_revisions_for_item(main_item, revision_data)
|
||||||
|
|
||||||
models.CollectionMember(collection=instance,
|
models.CollectionMember(collection=instance,
|
||||||
|
stoken=models.Stoken.objects.create(),
|
||||||
user=validated_data.get('owner'),
|
user=validated_data.get('owner'),
|
||||||
accessLevel=models.AccessLevels.ADMIN,
|
accessLevel=models.AccessLevels.ADMIN,
|
||||||
encryptionKey=encryption_key,
|
encryptionKey=encryption_key,
|
||||||
@ -258,7 +259,10 @@ class CollectionMemberSerializer(serializers.ModelSerializer):
|
|||||||
def update(self, instance, validated_data):
|
def update(self, instance, validated_data):
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
# We only allow updating accessLevel
|
# We only allow updating accessLevel
|
||||||
instance.accessLevel = validated_data.pop('accessLevel')
|
access_level = validated_data.pop('accessLevel')
|
||||||
|
if instance.accessLevel != access_level:
|
||||||
|
instance.stoken = models.Stoken.objects.create()
|
||||||
|
instance.accessLevel = access_level
|
||||||
instance.save()
|
instance.save()
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
@ -314,6 +318,7 @@ class InvitationAcceptSerializer(serializers.Serializer):
|
|||||||
|
|
||||||
member = models.CollectionMember.objects.create(
|
member = models.CollectionMember.objects.create(
|
||||||
collection=invitation.collection,
|
collection=invitation.collection,
|
||||||
|
stoken=models.Stoken.objects.create(),
|
||||||
user=invitation.user,
|
user=invitation.user,
|
||||||
accessLevel=invitation.accessLevel,
|
accessLevel=invitation.accessLevel,
|
||||||
encryptionKey=encryption_key,
|
encryptionKey=encryption_key,
|
||||||
|
Loading…
Reference in New Issue
Block a user