mirror of
https://github.com/etesync/server
synced 2024-11-22 00:38:07 +00:00
Reformat some files using black.
This commit is contained in:
parent
7513b058ba
commit
c790b5f489
@ -4,6 +4,9 @@ from rest_framework import serializers, status
|
||||
class EtebaseValidationError(serializers.ValidationError):
|
||||
def __init__(self, code, detail, status_code=status.HTTP_400_BAD_REQUEST):
|
||||
super().__init__(
|
||||
{"code": code, "detail": detail,}
|
||||
{
|
||||
"code": code,
|
||||
"detail": detail,
|
||||
}
|
||||
)
|
||||
self.status_code = status_code
|
||||
|
@ -33,7 +33,9 @@ class Migration(migrations.Migration):
|
||||
("version", models.PositiveSmallIntegerField()),
|
||||
("owner", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={"unique_together": {("uid", "owner")},},
|
||||
options={
|
||||
"unique_together": {("uid", "owner")},
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="CollectionItem",
|
||||
@ -61,7 +63,9 @@ class Migration(migrations.Migration):
|
||||
),
|
||||
),
|
||||
],
|
||||
options={"unique_together": {("uid", "collection")},},
|
||||
options={
|
||||
"unique_together": {("uid", "collection")},
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="CollectionItemChunk",
|
||||
@ -122,7 +126,9 @@ class Migration(migrations.Migration):
|
||||
),
|
||||
),
|
||||
],
|
||||
options={"unique_together": {("item", "current")},},
|
||||
options={
|
||||
"unique_together": {("item", "current")},
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="RevisionChunkRelation",
|
||||
@ -145,7 +151,9 @@ class Migration(migrations.Migration):
|
||||
),
|
||||
),
|
||||
],
|
||||
options={"ordering": ("id",),},
|
||||
options={
|
||||
"ordering": ("id",),
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="CollectionMember",
|
||||
@ -170,6 +178,8 @@ class Migration(migrations.Migration):
|
||||
),
|
||||
("user", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={"unique_together": {("user", "collection")},},
|
||||
options={
|
||||
"unique_together": {("user", "collection")},
|
||||
},
|
||||
),
|
||||
]
|
||||
|
@ -54,6 +54,8 @@ class Migration(migrations.Migration):
|
||||
),
|
||||
),
|
||||
],
|
||||
options={"unique_together": {("user", "fromMember")},},
|
||||
options={
|
||||
"unique_together": {("user", "fromMember")},
|
||||
},
|
||||
),
|
||||
]
|
||||
|
@ -11,6 +11,8 @@ class Migration(migrations.Migration):
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="collectioninvitation", name="version", field=models.PositiveSmallIntegerField(default=1),
|
||||
model_name="collectioninvitation",
|
||||
name="version",
|
||||
field=models.PositiveSmallIntegerField(default=1),
|
||||
),
|
||||
]
|
||||
|
@ -10,5 +10,9 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(model_name="userinfo", old_name="pubkey", new_name="loginPubkey",),
|
||||
migrations.RenameField(
|
||||
model_name="userinfo",
|
||||
old_name="pubkey",
|
||||
new_name="loginPubkey",
|
||||
),
|
||||
]
|
||||
|
@ -33,6 +33,8 @@ class Migration(migrations.Migration):
|
||||
),
|
||||
("user", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={"unique_together": {("user", "collection")},},
|
||||
options={
|
||||
"unique_together": {("user", "collection")},
|
||||
},
|
||||
),
|
||||
]
|
||||
|
@ -10,5 +10,9 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(model_name="userinfo", old_name="encryptedSeckey", new_name="encryptedContent",),
|
||||
migrations.RenameField(
|
||||
model_name="userinfo",
|
||||
old_name="encryptedSeckey",
|
||||
new_name="encryptedContent",
|
||||
),
|
||||
]
|
||||
|
@ -11,6 +11,8 @@ class Migration(migrations.Migration):
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="collectionitemrevision", name="salt", field=models.BinaryField(default=b"", editable=True),
|
||||
model_name="collectionitemrevision",
|
||||
name="salt",
|
||||
field=models.BinaryField(default=b"", editable=True),
|
||||
),
|
||||
]
|
||||
|
@ -21,7 +21,16 @@ class Migration(migrations.Migration):
|
||||
to="django_etebase.CollectionItem",
|
||||
),
|
||||
),
|
||||
migrations.AlterUniqueTogether(name="collection", unique_together=set(),),
|
||||
migrations.RemoveField(model_name="collection", name="uid",),
|
||||
migrations.RemoveField(model_name="collection", name="version",),
|
||||
migrations.AlterUniqueTogether(
|
||||
name="collection",
|
||||
unique_together=set(),
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name="collection",
|
||||
name="uid",
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name="collection",
|
||||
name="version",
|
||||
),
|
||||
]
|
||||
|
@ -10,5 +10,8 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(model_name="collectionitemrevision", name="salt",),
|
||||
migrations.RemoveField(
|
||||
model_name="collectionitemrevision",
|
||||
name="salt",
|
||||
),
|
||||
]
|
||||
|
@ -10,5 +10,8 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterUniqueTogether(name="collectionitemchunk", unique_together={("item", "uid")},),
|
||||
migrations.AlterUniqueTogether(
|
||||
name="collectionitemchunk",
|
||||
unique_together={("item", "uid")},
|
||||
),
|
||||
]
|
||||
|
@ -18,6 +18,12 @@ class Migration(migrations.Migration):
|
||||
on_delete=django.db.models.deletion.CASCADE, related_name="chunks", to="django_etebase.Collection"
|
||||
),
|
||||
),
|
||||
migrations.AlterUniqueTogether(name="collectionitemchunk", unique_together={("collection", "uid")},),
|
||||
migrations.RemoveField(model_name="collectionitemchunk", name="item",),
|
||||
migrations.AlterUniqueTogether(
|
||||
name="collectionitemchunk",
|
||||
unique_together={("collection", "uid")},
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name="collectionitemchunk",
|
||||
name="item",
|
||||
),
|
||||
]
|
||||
|
@ -10,6 +10,14 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(model_name="collectioninvitation", old_name="accessLevel", new_name="accessLevelOld",),
|
||||
migrations.RenameField(model_name="collectionmember", old_name="accessLevel", new_name="accessLevelOld",),
|
||||
migrations.RenameField(
|
||||
model_name="collectioninvitation",
|
||||
old_name="accessLevel",
|
||||
new_name="accessLevelOld",
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name="collectionmember",
|
||||
old_name="accessLevel",
|
||||
new_name="accessLevelOld",
|
||||
),
|
||||
]
|
||||
|
@ -10,6 +10,12 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(model_name="collectioninvitation", name="accessLevelOld",),
|
||||
migrations.RemoveField(model_name="collectionmember", name="accessLevelOld",),
|
||||
migrations.RemoveField(
|
||||
model_name="collectioninvitation",
|
||||
name="accessLevelOld",
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name="collectionmember",
|
||||
name="accessLevelOld",
|
||||
),
|
||||
]
|
||||
|
@ -182,7 +182,10 @@ class CollectionMember(models.Model):
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||||
encryptionKey = models.BinaryField(editable=True, blank=False, null=False)
|
||||
collectionType = models.ForeignKey(CollectionType, on_delete=models.PROTECT, null=True)
|
||||
accessLevel = models.IntegerField(choices=AccessLevels.choices, default=AccessLevels.READ_ONLY,)
|
||||
accessLevel = models.IntegerField(
|
||||
choices=AccessLevels.choices,
|
||||
default=AccessLevels.READ_ONLY,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
unique_together = ("user", "collection")
|
||||
@ -193,7 +196,11 @@ class CollectionMember(models.Model):
|
||||
def revoke(self):
|
||||
with transaction.atomic():
|
||||
CollectionMemberRemoved.objects.update_or_create(
|
||||
collection=self.collection, user=self.user, defaults={"stoken": Stoken.objects.create(),},
|
||||
collection=self.collection,
|
||||
user=self.user,
|
||||
defaults={
|
||||
"stoken": Stoken.objects.create(),
|
||||
},
|
||||
)
|
||||
|
||||
self.delete()
|
||||
@ -220,7 +227,10 @@ class CollectionInvitation(models.Model):
|
||||
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="incoming_invitations", on_delete=models.CASCADE)
|
||||
signedEncryptionKey = models.BinaryField(editable=False, blank=False, null=False)
|
||||
accessLevel = models.IntegerField(choices=AccessLevels.choices, default=AccessLevels.READ_ONLY,)
|
||||
accessLevel = models.IntegerField(
|
||||
choices=AccessLevels.choices,
|
||||
default=AccessLevels.READ_ONLY,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
unique_together = ("user", "fromMember")
|
||||
|
@ -156,7 +156,11 @@ class BetterErrorsMixin:
|
||||
else:
|
||||
message = str(error)
|
||||
ret.append(
|
||||
{"field": field_name, "code": error.code, "detail": message,}
|
||||
{
|
||||
"field": field_name,
|
||||
"code": error.code,
|
||||
"detail": message,
|
||||
}
|
||||
)
|
||||
return ret
|
||||
|
||||
@ -169,7 +173,11 @@ class BetterErrorsMixin:
|
||||
raise EtebaseValidationError(err.code, err.message)
|
||||
|
||||
raise serializers.ValidationError(
|
||||
{"code": "field_errors", "detail": "Field validations failed.", "errors": errors,}
|
||||
{
|
||||
"code": "field_errors",
|
||||
"detail": "Field validations failed.",
|
||||
"errors": errors,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@ -343,7 +351,11 @@ class CollectionSerializer(BetterErrorsMixin, serializers.ModelSerializer):
|
||||
|
||||
|
||||
class CollectionMemberSerializer(BetterErrorsMixin, serializers.ModelSerializer):
|
||||
username = UserSlugRelatedField(source="user", read_only=True, style={"base_template": "input.html"},)
|
||||
username = UserSlugRelatedField(
|
||||
source="user",
|
||||
read_only=True,
|
||||
style={"base_template": "input.html"},
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = models.CollectionMember
|
||||
@ -365,7 +377,11 @@ class CollectionMemberSerializer(BetterErrorsMixin, serializers.ModelSerializer)
|
||||
|
||||
|
||||
class CollectionInvitationSerializer(BetterErrorsMixin, serializers.ModelSerializer):
|
||||
username = UserSlugRelatedField(source="user", queryset=User.objects, style={"base_template": "input.html"},)
|
||||
username = UserSlugRelatedField(
|
||||
source="user",
|
||||
queryset=User.objects,
|
||||
style={"base_template": "input.html"},
|
||||
)
|
||||
collection = serializers.CharField(source="collection.uid")
|
||||
fromUsername = BinaryBase64Field(source="fromMember.user.username", read_only=True)
|
||||
fromPubkey = BinaryBase64Field(source="fromMember.user.userinfo.pubkey", read_only=True)
|
||||
|
@ -413,7 +413,10 @@ class CollectionItemViewSet(BaseViewSet):
|
||||
return Response(ret, status=status.HTTP_200_OK)
|
||||
|
||||
return Response(
|
||||
{"items": serializer.errors, "deps": deps_serializer.errors if deps is not None else [],},
|
||||
{
|
||||
"items": serializer.errors,
|
||||
"deps": deps_serializer.errors if deps is not None else [],
|
||||
},
|
||||
status=status.HTTP_409_CONFLICT,
|
||||
)
|
||||
|
||||
@ -708,7 +711,7 @@ class AuthenticationViewSet(viewsets.ViewSet):
|
||||
elif challenge_data["userId"] != user.id:
|
||||
content = {"code": "wrong_user", "detail": "This challenge is for the wrong user"}
|
||||
return Response(content, status=status.HTTP_400_BAD_REQUEST)
|
||||
elif not settings.DEBUG and host.split(':', 1)[0] != request.get_host().split(':', 1)[0]:
|
||||
elif not settings.DEBUG and host.split(":", 1)[0] != request.get_host().split(":", 1)[0]:
|
||||
detail = 'Found wrong host name. Got: "{}" expected: "{}"'.format(host, request.get_host())
|
||||
content = {"code": "wrong_host", "detail": detail}
|
||||
return Response(content, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
Loading…
Reference in New Issue
Block a user