From 0a99f10899e1a16cbc9b030c0a55e3c3621ef5af Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sun, 4 Apr 2021 16:28:06 +0200 Subject: [PATCH] Create multiple channels in case of five people-pools --- .../commands/fix_matrix_channels.py | 187 +++++++++--------- .../templates/participation/pool_detail.html | 2 +- 2 files changed, 98 insertions(+), 91 deletions(-) diff --git a/apps/participation/management/commands/fix_matrix_channels.py b/apps/participation/management/commands/fix_matrix_channels.py index 459224f..819dadc 100644 --- a/apps/participation/management/commands/fix_matrix_channels.py +++ b/apps/participation/management/commands/fix_matrix_channels.py @@ -309,7 +309,7 @@ class Command(BaseCommand): await Matrix.set_room_power_level(f"#orga-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org", 50) await Matrix.set_room_power_level(f"#tirage-au-sort-{slug}:tfjm.org", - f"@{orga.matrix_username}:tfjm.org", 50) + f"@{orga.matrix_username}:tfjm.org", 50) # Invite participants for participation in tournament.participations.filter(valid=True).all(): @@ -327,97 +327,104 @@ class Command(BaseCommand): # Create pool-specific channels for pool in tournament.pools.all(): self.stdout.write(f"Managing {pool}...") - if not Matrix.resolve_room_alias(f"#poule-{slug}-{pool.id}:tfjm.org"): - await Matrix.create_room( - visibility=RoomVisibility.public, - alias=f"poule-{slug}-{pool.id}", - name= - f"{name} - Jour {pool.round} - Poule " - f"{', '.join(participation.team.trigram for participation in pool.participations.all())}", - topic=f"Discussion avec les équipes - {pool}", - federate=False, - preset=RoomPreset.private_chat, - ) - if not Matrix.resolve_room_alias(f"#poule-{slug}-{pool.id}-jurys:tfjm.org"): - await Matrix.create_room( - visibility=RoomVisibility.public, - alias=f"poule-{slug}-{pool.id}-jurys", - name= - f"{name} - Jour {pool.round} - Jurys poule " - f"{', '.join(participation.team.trigram for participation in pool.participations.all())}", - topic=f"Discussion avec les jurys - {pool}", - federate=False, - preset=RoomPreset.private_chat, - ) + five = pool.participations.count() >= 5 + for i in range(2 if five else 1): + # Fix for five teams-pools + suffix = f"-{chr(ord('A') + i)}" if five else "" + if not Matrix.resolve_room_alias(f"#poule-{slug}-{pool.id}{suffix}:tfjm.org"): + await Matrix.create_room( + visibility=RoomVisibility.public, + alias=f"poule-{slug}-{pool.id}{suffix}", + name=f"{name} - Jour {pool.round} - Poule " + + ', '.join(participation.team.trigram + for participation in pool.participations.all()) + suffix, + topic=f"Discussion avec les équipes - {pool}{suffix}", + federate=False, + preset=RoomPreset.private_chat, + ) + if not Matrix.resolve_room_alias(f"#poule-{slug}-{pool.id}{suffix}-jurys:tfjm.org"): + await Matrix.create_room( + visibility=RoomVisibility.public, + alias=f"poule-{slug}-{pool.id}{suffix}-jurys", + name=f"{name} - Jour {pool.round}{suffix} - Jurys poule " + + ', '.join(participation.team.trigram + for participation in pool.participations.all()) + suffix, + topic=f"Discussion avec les jurys - {pool}{suffix}", + federate=False, + preset=RoomPreset.private_chat, + ) + + await Matrix.set_room_avatar(f"#poule-{slug}-{pool.id}{suffix}:tfjm.org", avatar_uri) + await Matrix.set_room_avatar(f"#poule-{slug}-{pool.id}{suffix}-jurys:tfjm.org", avatar_uri) + + bbb_url = pool.bbb_url + if five: + bbb_url = bbb_url.split(";")[i].strip() + url_params = urlencode(dict(url=bbb_url, + isAudioConf='false', displayName='$matrix_display_name', + avatarUrl='$matrix_avatar_url', userId='$matrix_user_id')) \ + .replace("%24", "$") + await Matrix.add_integration( + f"#poule-{slug}-{pool.id}{suffix}:tfjm.org", + f"https://scalar.vector.im/api/widgets/bigbluebutton.html?{url_params}", + f"bbb-{slug}-{pool.id}{suffix}", "bigbluebutton", "BigBlueButton", str(pool)) + await Matrix.add_integration( + f"#poule-{slug}-{pool.id}:tfjm.org", + f"https://board.tfjm.org/boards/{slug}-{pool.id}", f"board-{slug}-{pool.id}", + "customwidget", "Tableau", str(pool)) - await Matrix.set_room_avatar(f"#poule-{slug}-{pool.id}:tfjm.org", avatar_uri) - await Matrix.set_room_avatar(f"#poule-{slug}-{pool.id}-jurys:tfjm.org", avatar_uri) + # Invite admins and give permissions + for admin in AdminRegistration.objects.all(): + await Matrix.invite(f"#poule-{slug}-{pool.id}{suffix}:tfjm.org", + f"@{admin.matrix_username}:tfjm.org") + await Matrix.invite(f"#poule-{slug}-{pool.id}{suffix}-jurys:tfjm.org", + f"@{admin.matrix_username}:tfjm.org") + + await Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}{suffix}:tfjm.org", + f"@{admin.matrix_username}:tfjm.org", 95) + await Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}{suffix}-jurys:tfjm.org", + f"@{admin.matrix_username}:tfjm.org", 95) - url_params = urlencode(dict(url=pool.bbb_url, - isAudioConf='false', displayName='$matrix_display_name', - avatarUrl='$matrix_avatar_url', userId='$matrix_user_id')) \ - .replace("%24", "$") - await Matrix.add_integration( - f"#poule-{slug}-{pool.id}:tfjm.org", - f"https://scalar.vector.im/api/widgets/bigbluebutton.html?{url_params}", - f"bbb-{slug}-{pool.id}", "bigbluebutton", "BigBlueButton", str(pool)) - await Matrix.add_integration( - f"#poule-{slug}-{pool.id}:tfjm.org", - f"https://board.tfjm.org/boards/{slug}-{pool.id}", f"board-{slug}-{pool.id}", - "customwidget", "Tableau", str(pool)) + # Invite organizers and give permissions + for orga in VolunteerRegistration.objects.all(): + await Matrix.invite(f"#poule-{slug}-{pool.id}{suffix}:tfjm.org", + f"@{orga.matrix_username}:tfjm.org") + await Matrix.invite(f"#poule-{slug}-{pool.id}{suffix}-jurys:tfjm.org", + f"@{orga.matrix_username}:tfjm.org") + + if not orga.is_admin: + await Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}{suffix}:tfjm.org", + f"@{orga.matrix_username}:tfjm.org", 50) + await Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}{suffix}-jurys:tfjm.org", + f"@{orga.matrix_username}:tfjm.org", 50) + + # Invite the jury, give good permissions + for jury in pool.juries.all(): + await Matrix.invite(f"#annonces-{slug}:tfjm.org", f"@{jury.matrix_username}:tfjm.org") + await Matrix.invite(f"#general-{slug}:tfjm.org", f"@{jury.matrix_username}:tfjm.org") + await Matrix.invite(f"#flood-{slug}:tfjm.org", f"@{jury.matrix_username}:tfjm.org") + await Matrix.invite(f"#jury-{slug}:tfjm.org", f"@{jury.matrix_username}:tfjm.org") + await Matrix.invite(f"#orga-{slug}:tfjm.org", f"@{jury.matrix_username}:tfjm.org") + await Matrix.invite(f"#poule-{slug}-{pool.id}{suffix}:tfjm.org", + f"@{jury.matrix_username}:tfjm.org") + await Matrix.invite(f"#poule-{slug}-{pool.id}{suffix}-jurys:tfjm.org", + f"@{jury.matrix_username}:tfjm.org") + await Matrix.invite(f"#tirage-au-sort-{slug}:tfjm.org", + f"@{jury.matrix_username}:tfjm.org") + + if not jury.is_admin: + await Matrix.set_room_power_level(f"#jury-{slug}:tfjm.org", + f"@{jury.matrix_username}:tfjm.org", 50) + await Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}{suffix}:tfjm.org", + f"@{jury.matrix_username}:tfjm.org", 50) + await Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}{suffix}-jurys:tfjm.org", + f"@{jury.matrix_username}:tfjm.org", 50) - # Invite admins and give permissions - for admin in AdminRegistration.objects.all(): - await Matrix.invite(f"#poule-{slug}-{pool.id}:tfjm.org", - f"@{admin.matrix_username}:tfjm.org") - await Matrix.invite(f"#poule-{slug}-{pool.id}-jurys:tfjm.org", - f"@{admin.matrix_username}:tfjm.org") - - await Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}:tfjm.org", - f"@{admin.matrix_username}:tfjm.org", 95) - await Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}-jurys:tfjm.org", - f"@{admin.matrix_username}:tfjm.org", 95) - - # Invite organizers and give permissions - for orga in VolunteerRegistration.objects.all(): - await Matrix.invite(f"#poule-{slug}-{pool.id}:tfjm.org", - f"@{orga.matrix_username}:tfjm.org") - await Matrix.invite(f"#poule-{slug}-{pool.id}-jurys:tfjm.org", - f"@{orga.matrix_username}:tfjm.org") - - if not orga.is_admin: - await Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}:tfjm.org", - f"@{orga.matrix_username}:tfjm.org", 50) - await Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}-jurys:tfjm.org", - f"@{orga.matrix_username}:tfjm.org", 50) - - # Invite the jury, give good permissions - for jury in pool.juries.all(): - await Matrix.invite(f"#annonces-{slug}:tfjm.org", f"@{jury.matrix_username}:tfjm.org") - await Matrix.invite(f"#general-{slug}:tfjm.org", f"@{jury.matrix_username}:tfjm.org") - await Matrix.invite(f"#flood-{slug}:tfjm.org", f"@{jury.matrix_username}:tfjm.org") - await Matrix.invite(f"#jury-{slug}:tfjm.org", f"@{jury.matrix_username}:tfjm.org") - await Matrix.invite(f"#orga-{slug}:tfjm.org", f"@{jury.matrix_username}:tfjm.org") - await Matrix.invite(f"#poule-{slug}-{pool.id}:tfjm.org", - f"@{jury.matrix_username}:tfjm.org") - await Matrix.invite(f"#poule-{slug}-{pool.id}-jurys:tfjm.org", - f"@{jury.matrix_username}:tfjm.org") - await Matrix.invite(f"#tirage-au-sort-{slug}:tfjm.org", - f"@{jury.matrix_username}:tfjm.org") - - if not jury.is_admin: - await Matrix.set_room_power_level(f"#jury-{slug}:tfjm.org", - f"@{jury.matrix_username}:tfjm.org", 50) - await Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}:tfjm.org", - f"@{jury.matrix_username}:tfjm.org", 50) - await Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}-jurys:tfjm.org", - f"@{jury.matrix_username}:tfjm.org", 50) - - # Invite participants to the right pool - for participation in pool.participations.all(): - for participant in participation.team.participants.all(): - await Matrix.invite(f"#poule-{slug}-{pool.id}:tfjm.org", - f"@{participant.matrix_username}:tfjm.org") + # Invite participants to the right pool + for participation in pool.participations.all(): + for participant in participation.team.participants.all(): + await Matrix.invite(f"#poule-{slug}-{pool.id}{suffix}:tfjm.org", + f"@{participant.matrix_username}:tfjm.org") # Create private channels for teams for team in Team.objects.all(): @@ -435,6 +442,6 @@ class Command(BaseCommand): await Matrix.invite(f"#equipe-{team.trigram.lower}:tfjm.org", f"@{participant.matrix_username}:tfjm.org") await Matrix.set_room_power_level(f"#equipe-{team.trigram.lower()}:tfjm.org", - f"@{participant.matrix_username}:tfjm.org", 50) + f"@{participant.matrix_username}:tfjm.org", 50) asyncio.get_event_loop().run_until_complete(main()) diff --git a/apps/participation/templates/participation/pool_detail.html b/apps/participation/templates/participation/pool_detail.html index 287cf71..83d52d0 100644 --- a/apps/participation/templates/participation/pool_detail.html +++ b/apps/participation/templates/participation/pool_detail.html @@ -33,7 +33,7 @@
{% trans "BigBlueButton link:" %}
-
{{ pool.bbb_url }}
+
{{ pool.bbb_url|urlize }}