Make access level an int instead of a string.
We started with a string because we thought it could maybe provide more flexibility, though really, an int makes much more sense, especially on all the platforms etebase runs nowadays.
This commit is contained in:
parent
43569727f4
commit
d90931fbe5
23
django_etebase/migrations/0026_auto_20200907_0752.py
Normal file
23
django_etebase/migrations/0026_auto_20200907_0752.py
Normal file
@ -0,0 +1,23 @@
|
||||
# Generated by Django 3.1 on 2020-09-07 07:52
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('django_etebase', '0025_auto_20200804_1216'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='collectioninvitation',
|
||||
old_name='accessLevel',
|
||||
new_name='accessLevelOld',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='collectionmember',
|
||||
old_name='accessLevel',
|
||||
new_name='accessLevelOld',
|
||||
),
|
||||
]
|
23
django_etebase/migrations/0027_auto_20200907_0752.py
Normal file
23
django_etebase/migrations/0027_auto_20200907_0752.py
Normal file
@ -0,0 +1,23 @@
|
||||
# Generated by Django 3.1 on 2020-09-07 07:52
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('django_etebase', '0026_auto_20200907_0752'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='collectioninvitation',
|
||||
name='accessLevel',
|
||||
field=models.IntegerField(choices=[(0, 'Read Only'), (1, 'Admin'), (2, 'Read Write')], default=0),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='collectionmember',
|
||||
name='accessLevel',
|
||||
field=models.IntegerField(choices=[(0, 'Read Only'), (1, 'Admin'), (2, 'Read Write')], default=0),
|
||||
),
|
||||
]
|
39
django_etebase/migrations/0028_auto_20200907_0754.py
Normal file
39
django_etebase/migrations/0028_auto_20200907_0754.py
Normal file
@ -0,0 +1,39 @@
|
||||
# Generated by Django 3.1 on 2020-09-07 07:54
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
from django_etebase.models import AccessLevels
|
||||
|
||||
|
||||
def change_access_level_to_int(apps, schema_editor):
|
||||
CollectionMember = apps.get_model('django_etebase', 'CollectionMember')
|
||||
CollectionInvitation = apps.get_model('django_etebase', 'CollectionInvitation')
|
||||
|
||||
for member in CollectionMember.objects.all():
|
||||
if member.accessLevelOld == 'adm':
|
||||
member.accessLevel = AccessLevels.ADMIN
|
||||
elif member.accessLevelOld == 'rw':
|
||||
member.accessLevel = AccessLevels.READ_WRITE
|
||||
elif member.accessLevelOld == 'ro':
|
||||
member.accessLevel = AccessLevels.READ_ONLY
|
||||
member.save()
|
||||
|
||||
for invitation in CollectionInvitation.objects.all():
|
||||
if invitation.accessLevelOld == 'adm':
|
||||
invitation.accessLevel = AccessLevels.ADMIN
|
||||
elif invitation.accessLevelOld == 'rw':
|
||||
invitation.accessLevel = AccessLevels.READ_WRITE
|
||||
elif invitation.accessLevelOld == 'ro':
|
||||
invitation.accessLevel = AccessLevels.READ_ONLY
|
||||
invitation.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('django_etebase', '0027_auto_20200907_0752'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(change_access_level_to_int),
|
||||
]
|
21
django_etebase/migrations/0029_auto_20200907_0801.py
Normal file
21
django_etebase/migrations/0029_auto_20200907_0801.py
Normal file
@ -0,0 +1,21 @@
|
||||
# Generated by Django 3.1 on 2020-09-07 08:01
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('django_etebase', '0028_auto_20200907_0754'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='collectioninvitation',
|
||||
name='accessLevelOld',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='collectionmember',
|
||||
name='accessLevelOld',
|
||||
),
|
||||
]
|
@ -138,10 +138,10 @@ class RevisionChunkRelation(models.Model):
|
||||
ordering = ('id', )
|
||||
|
||||
|
||||
class AccessLevels(models.TextChoices):
|
||||
ADMIN = 'adm'
|
||||
READ_WRITE = 'rw'
|
||||
READ_ONLY = 'ro'
|
||||
class AccessLevels(models.IntegerChoices):
|
||||
READ_ONLY = 0
|
||||
ADMIN = 1
|
||||
READ_WRITE = 2
|
||||
|
||||
|
||||
class CollectionMember(models.Model):
|
||||
@ -149,8 +149,7 @@ class CollectionMember(models.Model):
|
||||
collection = models.ForeignKey(Collection, related_name='members', on_delete=models.CASCADE)
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||||
encryptionKey = models.BinaryField(editable=True, blank=False, null=False)
|
||||
accessLevel = models.CharField(
|
||||
max_length=3,
|
||||
accessLevel = models.IntegerField(
|
||||
choices=AccessLevels.choices,
|
||||
default=AccessLevels.READ_ONLY,
|
||||
)
|
||||
@ -195,8 +194,7 @@ 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.CharField(
|
||||
max_length=3,
|
||||
accessLevel = models.IntegerField(
|
||||
choices=AccessLevels.choices,
|
||||
default=AccessLevels.READ_ONLY,
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user