mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-10-31 16:20:00 +01:00 
			
		
		
		
	Automatically create appropriated channels when tournaments/pools/participations are updated
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
		
							
								
								
									
										100
									
								
								chat/signals.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										100
									
								
								chat/signals.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,100 @@ | ||||
| # Copyright (C) 2024 by Animath | ||||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||||
|  | ||||
| from chat.models import Channel | ||||
| from participation.models import Participation, Pool, Tournament | ||||
| from tfjm.permissions import PermissionType | ||||
|  | ||||
|  | ||||
| def create_tournament_channels(instance: Tournament, **_kwargs): | ||||
|     tournament = instance | ||||
|  | ||||
|     Channel.objects.update_or_create( | ||||
|         name=f"{tournament.name} - Annonces", | ||||
|         defaults=dict( | ||||
|             category=Channel.ChannelCategory.TOURNAMENT, | ||||
|             read_access=PermissionType.TOURNAMENT_MEMBER, | ||||
|             write_access=PermissionType.TOURNAMENT_ORGANIZER, | ||||
|             tournament=tournament, | ||||
|         ), | ||||
|     ) | ||||
|  | ||||
|     Channel.objects.update_or_create( | ||||
|         name=f"{tournament.name} - Général", | ||||
|         defaults=dict( | ||||
|             category=Channel.ChannelCategory.TOURNAMENT, | ||||
|             read_access=PermissionType.TOURNAMENT_MEMBER, | ||||
|             write_access=PermissionType.TOURNAMENT_MEMBER, | ||||
|             tournament=tournament, | ||||
|         ), | ||||
|     ) | ||||
|  | ||||
|     Channel.objects.update_or_create( | ||||
|         name=f"{tournament.name} - Détente", | ||||
|         defaults=dict( | ||||
|             category=Channel.ChannelCategory.TOURNAMENT, | ||||
|             read_access=PermissionType.TOURNAMENT_MEMBER, | ||||
|             write_access=PermissionType.TOURNAMENT_MEMBER, | ||||
|             tournament=tournament, | ||||
|         ), | ||||
|     ) | ||||
|  | ||||
|     Channel.objects.update_or_create( | ||||
|         name=f"{tournament.name} - Juré⋅es", | ||||
|         defaults=dict( | ||||
|             category=Channel.ChannelCategory.TOURNAMENT, | ||||
|             read_access=PermissionType.JURY_MEMBER, | ||||
|             write_access=PermissionType.JURY_MEMBER, | ||||
|             tournament=tournament, | ||||
|         ), | ||||
|     ) | ||||
|  | ||||
|     if tournament.remote: | ||||
|         Channel.objects.update_or_create( | ||||
|             name=f"{tournament.name} - Président⋅es de jury", | ||||
|             defaults=dict( | ||||
|                 category=Channel.ChannelCategory.TOURNAMENT, | ||||
|                 read_access=PermissionType.TOURNAMENT_JURY_PRESIDENT, | ||||
|                 write_access=PermissionType.TOURNAMENT_JURY_PRESIDENT, | ||||
|                 tournament=tournament, | ||||
|             ), | ||||
|         ) | ||||
|  | ||||
|  | ||||
| def create_pool_channels(instance: Pool, **_kwargs): | ||||
|     pool = instance | ||||
|     tournament = pool.tournament | ||||
|  | ||||
|     if tournament.remote: | ||||
|         Channel.objects.update_or_create( | ||||
|             name=f"{tournament.name} - Poule {pool.short_name}", | ||||
|             defaults=dict( | ||||
|                 category=Channel.ChannelCategory.TOURNAMENT, | ||||
|                 read_access=PermissionType.POOL_MEMBER, | ||||
|                 write_access=PermissionType.POOL_MEMBER, | ||||
|                 pool=pool, | ||||
|             ), | ||||
|         ) | ||||
|  | ||||
|         Channel.objects.update_or_create( | ||||
|             name=f"{tournament.name} - Poule {pool.short_name} - Jury", | ||||
|             defaults=dict( | ||||
|                 category=Channel.ChannelCategory.TOURNAMENT, | ||||
|                 read_access=PermissionType.JURY_MEMBER, | ||||
|                 write_access=PermissionType.JURY_MEMBER, | ||||
|                 pool=pool, | ||||
|             ), | ||||
|         ) | ||||
|  | ||||
|  | ||||
| def create_team_channel(instance: Participation, **_kwargs): | ||||
|     if instance.valid: | ||||
|         Channel.objects.update_or_create( | ||||
|             name=f"Équipe {instance.team.trigram}", | ||||
|             defaults=dict( | ||||
|                 category=Channel.ChannelCategory.TEAM, | ||||
|                 read_access=PermissionType.TEAM_MEMBER, | ||||
|                 write_access=PermissionType.TEAM_MEMBER, | ||||
|                 team=instance.team, | ||||
|             ), | ||||
|         ) | ||||
		Reference in New Issue
	
	Block a user