1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-30 12:31:12 +02:00

Manage private chats

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello
2024-04-28 15:35:32 +02:00
parent c6b9a84def
commit d6aa5eb0cc
3 changed files with 67 additions and 6 deletions

View File

@ -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