From c565b08f9c9aecfc384fce1a0a58189890aafb66 Mon Sep 17 00:00:00 2001
From: Patrick Jentsch <p.jentsch@uni-bielefeld.de>
Date: Fri, 24 Feb 2023 10:30:42 +0100
Subject: [PATCH] Found a better solution for default role assignments

---
 app/models.py | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/app/models.py b/app/models.py
index d73b01b6..df992ccb 100644
--- a/app/models.py
+++ b/app/models.py
@@ -479,6 +479,8 @@ class CorpusFollowerAssociation(HashidMixin, db.Model):
     )
 
     def __init__(self, **kwargs):
+        if 'role' not in kwargs:
+            kwargs['role'] = CorpusFollowerRole.query.filter_by(default=True).first()
         super().__init__(**kwargs)
 
     def __repr__(self):
@@ -575,13 +577,12 @@ class User(HashidMixin, UserMixin, db.Model):
     )
 
     def __init__(self, **kwargs):
+        if 'role' not in kwargs:
+            if kwargs['email'] == current_app.config['NOPAQUE_ADMIN']:
+                kwargs['role'] = Role.query.filter_by(name='Administrator').first()
+            else:
+                kwargs['role'] = Role.query.filter_by(default=True).first()
         super().__init__(**kwargs)
-        if self.role is not None:
-            return
-        if self.email == current_app.config['NOPAQUE_ADMIN']:
-            self.role = Role.query.filter_by(name='Administrator').first()
-        else:
-            self.role = Role.query.filter_by(default=True).first()
 
     def __repr__(self):
         return f'<User {self.username}>'
-- 
GitLab