mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-03 20:02:47 +00:00 
			
		
		
		
	Found a better solution for default role assignments
This commit is contained in:
		@@ -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}>'
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user