Use UUIDs as primary key for models with user context

This commit is contained in:
Daniel Egger 2023-07-14 14:37:59 +02:00
parent 7c2190feaa
commit 5ed883e83b
26 changed files with 74 additions and 48 deletions

View File

@ -1,8 +1,8 @@
// ids for cypress test data // ids for cypress test data
export const ADMIN_USER_ID = -1; export const ADMIN_USER_ID = "872efd96-3bd7-4a1e-a239-2d72cad9f604";
export const TEST_TRAINER1_USER_ID = -11; export const TEST_TRAINER1_USER_ID = "b9e71f59-c44f-4290-b93a-9b3151e9a2fc";
export const TEST_STUDENT1_USER_ID = -21; export const TEST_STUDENT1_USER_ID = "65c73ad0-6d53-43a9-a4a4-64143f27b03a";
export const TEST_STUDENT2_USER_ID = -22; export const TEST_STUDENT2_USER_ID = "19c40d94-15cc-4198-aaad-ef707c4b0900";
export const TEST_COURSE_SESSION_BERN_ID = -1; export const TEST_COURSE_SESSION_BERN_ID = -1;
export const TEST_COURSE_SESSION_ZURICH_ID = -2; export const TEST_COURSE_SESSION_ZURICH_ID = -2;

View File

@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2023-07-14 12:15 # Generated by Django 3.2.13 on 2023-07-14 12:28
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion

View File

@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2023-07-14 12:15 # Generated by Django 3.2.13 on 2023-07-14 12:28
from django.conf import settings from django.conf import settings
from django.db import migrations, models from django.db import migrations, models

View File

@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2023-07-14 12:15 # Generated by Django 3.2.13 on 2023-07-14 12:28
from django.conf import settings from django.conf import settings
from django.db import migrations, models from django.db import migrations, models
@ -10,10 +10,10 @@ class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
('course', '0001_initial'),
('assignment', '0002_assignmentcompletionauditlog_assignment_user'),
('wagtailcore', '0083_workflowcontenttype'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL), migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('assignment', '0002_assignmentcompletionauditlog_assignment_user'),
('course', '0001_initial'),
('wagtailcore', '0083_workflowcontenttype'),
] ]
operations = [ operations = [

View File

@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2023-07-14 12:15 # Generated by Django 3.2.13 on 2023-07-14 12:28
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion

View File

@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2023-07-14 12:15 # Generated by Django 3.2.13 on 2023-07-14 12:28
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
@ -9,8 +9,8 @@ class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
('learnpath', '0001_initial'),
('competence', '0001_initial'), ('competence', '0001_initial'),
('learnpath', '0001_initial'),
] ]
operations = [ operations = [

View File

@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2023-07-14 12:15 # Generated by Django 3.2.13 on 2023-07-14 12:28
import django.contrib.sites.models import django.contrib.sites.models
from django.db import migrations, models from django.db import migrations, models

View File

@ -11,10 +11,10 @@ DEFAULT_RICH_TEXT_FEATURES_WITH_HEADER = [
] ]
# ids for cypress test data # ids for cypress test data
ADMIN_USER_ID = -1 ADMIN_USER_ID = "872efd96-3bd7-4a1e-a239-2d72cad9f604"
TEST_TRAINER1_USER_ID = -11 TEST_TRAINER1_USER_ID = "b9e71f59-c44f-4290-b93a-9b3151e9a2fc"
TEST_STUDENT1_USER_ID = -21 TEST_STUDENT1_USER_ID = "65c73ad0-6d53-43a9-a4a4-64143f27b03a"
TEST_STUDENT2_USER_ID = -22 TEST_STUDENT2_USER_ID = "19c40d94-15cc-4198-aaad-ef707c4b0900"
TEST_COURSE_SESSION_BERN_ID = -1 TEST_COURSE_SESSION_BERN_ID = -1
TEST_COURSE_SESSION_ZURICH_ID = -2 TEST_COURSE_SESSION_ZURICH_ID = -2

View File

@ -1,9 +1,10 @@
# Generated by Django 3.2.13 on 2023-07-14 12:15 # Generated by Django 3.2.13 on 2023-07-14 12:28
import django.contrib.auth.models import django.contrib.auth.models
import django.contrib.auth.validators import django.contrib.auth.validators
from django.db import migrations, models from django.db import migrations, models
import django.utils.timezone import django.utils.timezone
import uuid
class Migration(migrations.Migration): class Migration(migrations.Migration):
@ -31,7 +32,6 @@ class Migration(migrations.Migration):
migrations.CreateModel( migrations.CreateModel(
name='User', name='User',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')), ('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
@ -41,6 +41,7 @@ class Migration(migrations.Migration):
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('avatar_url', models.CharField(blank=True, default='/static/avatars/myvbv-default-avatar.png', max_length=254)), ('avatar_url', models.CharField(blank=True, default='/static/avatars/myvbv-default-avatar.png', max_length=254)),
('email', models.EmailField(max_length=254, unique=True, verbose_name='email address')), ('email', models.EmailField(max_length=254, unique=True, verbose_name='email address')),
('sso_id', models.UUIDField(blank=True, default=None, null=True, unique=True, verbose_name='SSO subscriber ID')), ('sso_id', models.UUIDField(blank=True, default=None, null=True, unique=True, verbose_name='SSO subscriber ID')),

View File

@ -1,3 +1,5 @@
import uuid
from django.contrib.auth.models import AbstractUser from django.contrib.auth.models import AbstractUser
from django.db import models from django.db import models
from django.db.models import JSONField from django.db.models import JSONField
@ -15,8 +17,8 @@ class User(AbstractUser):
("it", "Italiano"), ("it", "Italiano"),
) )
# FIXME: look into it... id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
# objects = UserManager()
avatar_url = models.CharField( avatar_url = models.CharField(
max_length=254, blank=True, default="/static/avatars/myvbv-default-avatar.png" max_length=254, blank=True, default="/static/avatars/myvbv-default-avatar.png"
) )

View File

@ -1,7 +1,8 @@
# Generated by Django 3.2.13 on 2023-07-14 12:15 # Generated by Django 3.2.13 on 2023-07-14 12:28
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
import uuid
import vbv_lernwelt.course.models import vbv_lernwelt.course.models
@ -17,7 +18,7 @@ class Migration(migrations.Migration):
migrations.CreateModel( migrations.CreateModel(
name='CircleDocument', name='CircleDocument',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('created_at', models.DateTimeField(auto_now_add=True)), ('created_at', models.DateTimeField(auto_now_add=True)),
('name', models.CharField(max_length=100)), ('name', models.CharField(max_length=100)),
], ],
@ -45,7 +46,7 @@ class Migration(migrations.Migration):
migrations.CreateModel( migrations.CreateModel(
name='CourseCompletion', name='CourseCompletion',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('created_at', models.DateTimeField(auto_now_add=True)), ('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)), ('updated_at', models.DateTimeField(auto_now=True)),
('page_type', models.CharField(blank=True, default='', max_length=255)), ('page_type', models.CharField(blank=True, default='', max_length=255)),
@ -82,7 +83,7 @@ class Migration(migrations.Migration):
migrations.CreateModel( migrations.CreateModel(
name='CourseSessionUser', name='CourseSessionUser',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('created_at', models.DateTimeField(auto_now_add=True)), ('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)), ('updated_at', models.DateTimeField(auto_now=True)),
('role', models.CharField(choices=[('MEMBER', 'Teilnehmer'), ('EXPERT', 'Experte/Trainer'), ('TUTOR', 'Lernbegleitung')], default='MEMBER', max_length=255)), ('role', models.CharField(choices=[('MEMBER', 'Teilnehmer'), ('EXPERT', 'Experte/Trainer'), ('TUTOR', 'Lernbegleitung')], default='MEMBER', max_length=255)),

View File

@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2023-07-14 12:15 # Generated by Django 3.2.13 on 2023-07-14 12:28
from django.conf import settings from django.conf import settings
from django.db import migrations, models from django.db import migrations, models
@ -10,11 +10,11 @@ class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
('learnpath', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL), migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('wagtailcore', '0083_workflowcontenttype'), ('wagtailcore', '0083_workflowcontenttype'),
('files', '0001_initial'), ('files', '0001_initial'),
('course', '0001_initial'), ('course', '0001_initial'),
('learnpath', '0001_initial'),
] ]
operations = [ operations = [

View File

@ -1,4 +1,5 @@
import enum import enum
import uuid
from django.db import models from django.db import models
from django.db.models import UniqueConstraint from django.db.models import UniqueConstraint
@ -161,6 +162,8 @@ class CourseCompletionStatus(enum.Enum):
class CourseCompletion(models.Model): class CourseCompletion(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
created_at = models.DateTimeField(auto_now_add=True) created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True) updated_at = models.DateTimeField(auto_now=True)
@ -220,9 +223,11 @@ class CourseSession(models.Model):
class CourseSessionUser(models.Model): class CourseSessionUser(models.Model):
""" """
Ein Benutzer der an einer CourseSession teilnimmt Ein Benutzer der an einer Durchführung teilnimmt
""" """
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
created_at = models.DateTimeField(auto_now_add=True) created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True) updated_at = models.DateTimeField(auto_now=True)
@ -268,6 +273,8 @@ class CourseSessionUser(models.Model):
class CircleDocument(models.Model): class CircleDocument(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
created_at = models.DateTimeField(auto_now_add=True) created_at = models.DateTimeField(auto_now_add=True)
file = models.OneToOneField(UploadFile, on_delete=models.CASCADE) file = models.OneToOneField(UploadFile, on_delete=models.CASCADE)
name = models.CharField(max_length=100) name = models.CharField(max_length=100)

View File

@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2023-07-14 12:15 # Generated by Django 3.2.13 on 2023-07-14 12:28
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion

View File

@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2023-07-14 12:15 # Generated by Django 3.2.13 on 2023-07-14 12:28
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion

View File

@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2023-07-14 12:15 # Generated by Django 3.2.13 on 2023-07-14 12:28
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
@ -9,10 +9,10 @@ class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
('learnpath', '0001_initial'),
('duedate', '0001_initial'),
('course_session', '0002_coursesessionattendancecourse_due_date'), ('course_session', '0002_coursesessionattendancecourse_due_date'),
('course', '0001_initial'), ('course', '0001_initial'),
('duedate', '0001_initial'),
('learnpath', '0001_initial'),
] ]
operations = [ operations = [

View File

@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2023-07-14 12:15 # Generated by Django 3.2.13 on 2023-07-14 12:28
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion

View File

@ -1,6 +1,7 @@
# Generated by Django 3.2.13 on 2023-07-14 12:15 # Generated by Django 3.2.13 on 2023-07-14 12:28
from django.db import migrations, models from django.db import migrations, models
import uuid
class Migration(migrations.Migration): class Migration(migrations.Migration):
@ -14,7 +15,7 @@ class Migration(migrations.Migration):
migrations.CreateModel( migrations.CreateModel(
name='FeedbackResponse', name='FeedbackResponse',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('data', models.JSONField(default=dict)), ('data', models.JSONField(default=dict)),
('created_at', models.DateTimeField(auto_now_add=True)), ('created_at', models.DateTimeField(auto_now_add=True)),
], ],

View File

@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2023-07-14 12:15 # Generated by Django 3.2.13 on 2023-07-14 12:28
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
@ -9,9 +9,9 @@ class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
('learnpath', '0001_initial'),
('feedback', '0001_initial'), ('feedback', '0001_initial'),
('course', '0001_initial'), ('course', '0001_initial'),
('learnpath', '0001_initial'),
] ]
operations = [ operations = [

View File

@ -1,3 +1,5 @@
import uuid
from django.core.validators import MaxValueValidator, MinValueValidator from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models from django.db import models
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -19,6 +21,8 @@ class FeedbackIntegerField(models.IntegerField):
class FeedbackResponse(models.Model): class FeedbackResponse(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
class DiscoveredChoices(models.TextChoices): class DiscoveredChoices(models.TextChoices):
INTERNET = "I", _("Internet") INTERNET = "I", _("Internet")
LEAFLET = "L", _("Leaflet") LEAFLET = "L", _("Leaflet")

View File

@ -1,8 +1,9 @@
# Generated by Django 3.2.13 on 2023-07-14 12:15 # Generated by Django 3.2.13 on 2023-07-14 12:28
from django.conf import settings from django.conf import settings
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
import uuid
import vbv_lernwelt.files.utils import vbv_lernwelt.files.utils
@ -18,7 +19,7 @@ class Migration(migrations.Migration):
migrations.CreateModel( migrations.CreateModel(
name='UploadFile', name='UploadFile',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('file', models.FileField(blank=True, null=True, upload_to=vbv_lernwelt.files.utils.file_generate_upload_path)), ('file', models.FileField(blank=True, null=True, upload_to=vbv_lernwelt.files.utils.file_generate_upload_path)),
('original_file_name', models.TextField()), ('original_file_name', models.TextField()),
('file_name', models.CharField(max_length=255, unique=True)), ('file_name', models.CharField(max_length=255, unique=True)),

View File

@ -1,3 +1,5 @@
import uuid
from django.conf import settings from django.conf import settings
from django.db import models from django.db import models
@ -12,6 +14,8 @@ from vbv_lernwelt.files.utils import file_generate_upload_path
class UploadFile(models.Model): class UploadFile(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
file = models.FileField(upload_to=file_generate_upload_path, blank=True, null=True) file = models.FileField(upload_to=file_generate_upload_path, blank=True, null=True)
original_file_name = models.TextField() original_file_name = models.TextField()

View File

@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2023-07-14 12:15 # Generated by Django 3.2.13 on 2023-07-14 12:28
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
@ -11,8 +11,8 @@ class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
('course', '0001_initial'),
('assignment', '0003_initial'), ('assignment', '0003_initial'),
('course', '0001_initial'),
('wagtailcore', '0083_workflowcontenttype'), ('wagtailcore', '0083_workflowcontenttype'),
] ]

View File

@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2023-07-14 12:15 # Generated by Django 3.2.13 on 2023-07-14 12:28
from django.conf import settings from django.conf import settings
from django.db import migrations, models from django.db import migrations, models
@ -15,10 +15,10 @@ class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
('wagtailcore', '0083_workflowcontenttype'),
('course', '0002_initial'), ('course', '0002_initial'),
('taggit', '0004_alter_taggeditem_content_type_alter_taggeditem_tag'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL), migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('taggit', '0004_alter_taggeditem_content_type_alter_taggeditem_tag'),
('wagtailcore', '0083_workflowcontenttype'),
] ]
operations = [ operations = [

View File

@ -1,10 +1,11 @@
# Generated by Django 3.2.13 on 2023-07-14 12:15 # Generated by Django 3.2.13 on 2023-07-14 12:28
from django.conf import settings from django.conf import settings
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
import django.utils.timezone import django.utils.timezone
import jsonfield.fields import jsonfield.fields
import uuid
class Migration(migrations.Migration): class Migration(migrations.Migration):
@ -20,7 +21,6 @@ class Migration(migrations.Migration):
migrations.CreateModel( migrations.CreateModel(
name='Notification', name='Notification',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('level', models.CharField(choices=[('success', 'success'), ('info', 'info'), ('warning', 'warning'), ('error', 'error')], default='info', max_length=20, verbose_name='level')), ('level', models.CharField(choices=[('success', 'success'), ('info', 'info'), ('warning', 'warning'), ('error', 'error')], default='info', max_length=20, verbose_name='level')),
('unread', models.BooleanField(db_index=True, default=True, verbose_name='unread')), ('unread', models.BooleanField(db_index=True, default=True, verbose_name='unread')),
('actor_object_id', models.CharField(max_length=255, verbose_name='actor object id')), ('actor_object_id', models.CharField(max_length=255, verbose_name='actor object id')),
@ -33,6 +33,7 @@ class Migration(migrations.Migration):
('deleted', models.BooleanField(db_index=True, default=False, verbose_name='deleted')), ('deleted', models.BooleanField(db_index=True, default=False, verbose_name='deleted')),
('emailed', models.BooleanField(db_index=True, default=False, verbose_name='emailed')), ('emailed', models.BooleanField(db_index=True, default=False, verbose_name='emailed')),
('data', jsonfield.fields.JSONField(blank=True, null=True, verbose_name='data')), ('data', jsonfield.fields.JSONField(blank=True, null=True, verbose_name='data')),
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('notification_type', models.CharField(choices=[('USER_INTERACTION', 'User Interaction'), ('PROGRESS', 'Progress'), ('INFORMATION', 'Information')], default='INFORMATION', max_length=32)), ('notification_type', models.CharField(choices=[('USER_INTERACTION', 'User Interaction'), ('PROGRESS', 'Progress'), ('INFORMATION', 'Information')], default='INFORMATION', max_length=32)),
('target_url', models.URLField(blank=True, null=True)), ('target_url', models.URLField(blank=True, null=True)),
('actor_avatar_url', models.URLField(blank=True, null=True)), ('actor_avatar_url', models.URLField(blank=True, null=True)),

View File

@ -1,3 +1,5 @@
import uuid
from django.db import models from django.db import models
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from notifications.base.models import AbstractNotification from notifications.base.models import AbstractNotification
@ -10,6 +12,8 @@ class NotificationType(models.TextChoices):
class Notification(AbstractNotification): class Notification(AbstractNotification):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
notification_type = models.CharField( notification_type = models.CharField(
max_length=32, max_length=32,
choices=NotificationType.choices, choices=NotificationType.choices,