mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-04 12:22:47 +00:00 
			
		
		
		
	Allow to change role by using a corpus follow link
This commit is contained in:
		@@ -787,11 +787,17 @@ class User(HashidMixin, UserMixin, db.Model):
 | 
			
		||||
    #endregion Profile Privacy settings
 | 
			
		||||
 | 
			
		||||
    def follow_corpus(self, corpus, role=None):
 | 
			
		||||
        if role is None:
 | 
			
		||||
            cfr = CorpusFollowerRole.query.filter_by(default=True).first()
 | 
			
		||||
        else:
 | 
			
		||||
            cfr = role
 | 
			
		||||
        if self.is_following_corpus(corpus):
 | 
			
		||||
            return
 | 
			
		||||
        r = CorpusFollowerRole.query.filter_by(default=True).first() if role is None else role
 | 
			
		||||
        cfa = CorpusFollowerAssociation(corpus=corpus, role=r, follower=self)
 | 
			
		||||
        db.session.add(cfa)
 | 
			
		||||
            cfa = CorpusFollowerAssociation.query.filter_by(corpus=corpus, follower=self).first()
 | 
			
		||||
            if cfa.role != cfr:
 | 
			
		||||
                cfa.role = cfr
 | 
			
		||||
        else:
 | 
			
		||||
            cfa = CorpusFollowerAssociation(corpus=corpus, role=cfr, follower=self)
 | 
			
		||||
            db.session.add(cfa)
 | 
			
		||||
 | 
			
		||||
    def unfollow_corpus(self, corpus):
 | 
			
		||||
        if not self.is_following_corpus(corpus):
 | 
			
		||||
@@ -840,7 +846,7 @@ class User(HashidMixin, UserMixin, db.Model):
 | 
			
		||||
        if role is None:
 | 
			
		||||
            return False
 | 
			
		||||
        self.follow_corpus(corpus, role)
 | 
			
		||||
        db.session.add(self)
 | 
			
		||||
        # db.session.add(self)
 | 
			
		||||
        return True
 | 
			
		||||
 | 
			
		||||
    def to_json_serializeable(self, backrefs=False, relationships=False, filter_by_privacy_settings=False):
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user