mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 03:42:11 +01:00 
			
		
		
		
	Manage private chats
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
		@@ -91,6 +91,13 @@ class Channel(models.Model):
 | 
			
		||||
                    "in addition to the permitted group of the channel."),
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    def get_visible_name(self, user: User) -> str:
 | 
			
		||||
        if self.private:
 | 
			
		||||
            users = [f"{u.first_name} {u.last_name}" for u in self.invited.all() if u != user] \
 | 
			
		||||
                    or [f"{user.first_name} {user.last_name}"]
 | 
			
		||||
            return ", ".join(users)
 | 
			
		||||
        return self.name
 | 
			
		||||
 | 
			
		||||
    def __str__(self):
 | 
			
		||||
        return str(format_lazy(_("Channel {name}"), name=self.name))
 | 
			
		||||
 | 
			
		||||
@@ -106,7 +113,7 @@ class Channel(models.Model):
 | 
			
		||||
        registration = await Registration.objects.prefetch_related('user').aget(user_id=user.id)
 | 
			
		||||
 | 
			
		||||
        if registration.is_admin:
 | 
			
		||||
            return Channel.objects.all()
 | 
			
		||||
            return Channel.objects.prefetch_related('invited').exclude(~Q(invited=user) & Q(private=True)).all()
 | 
			
		||||
 | 
			
		||||
        if registration.is_volunteer:
 | 
			
		||||
            registration = await VolunteerRegistration.objects \
 | 
			
		||||
@@ -153,7 +160,7 @@ class Channel(models.Model):
 | 
			
		||||
            qs |= Channel.objects.filter(Q(team=team),
 | 
			
		||||
                                         **{permission_type: PermissionType.TEAM_MEMBER})
 | 
			
		||||
 | 
			
		||||
        qs |= Channel.objects.filter(invited=user)
 | 
			
		||||
        qs |= Channel.objects.filter(invited=user).prefetch_related('invited')
 | 
			
		||||
 | 
			
		||||
        return qs
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user