Found a better solution for default role assignments

This commit is contained in:
Patrick Jentsch 2023-02-24 10:30:42 +01:00
parent ff3ac3658f
commit c565b08f9c

View File

@ -479,6 +479,8 @@ class CorpusFollowerAssociation(HashidMixin, db.Model):
) )
def __init__(self, **kwargs): def __init__(self, **kwargs):
if 'role' not in kwargs:
kwargs['role'] = CorpusFollowerRole.query.filter_by(default=True).first()
super().__init__(**kwargs) super().__init__(**kwargs)
def __repr__(self): def __repr__(self):
@ -575,13 +577,12 @@ class User(HashidMixin, UserMixin, db.Model):
) )
def __init__(self, **kwargs): 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) 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): def __repr__(self):
return f'<User {self.username}>' return f'<User {self.username}>'