Create multiple channels in case of five people-pools

This commit is contained in:
Yohann D'ANELLO 2021-04-04 16:28:06 +02:00
parent 5101746d29
commit 0a99f10899
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
2 changed files with 98 additions and 91 deletions

View File

@ -309,7 +309,7 @@ class Command(BaseCommand):
await Matrix.set_room_power_level(f"#orga-{slug}:tfjm.org", await Matrix.set_room_power_level(f"#orga-{slug}:tfjm.org",
f"@{orga.matrix_username}:tfjm.org", 50) f"@{orga.matrix_username}:tfjm.org", 50)
await Matrix.set_room_power_level(f"#tirage-au-sort-{slug}:tfjm.org", 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 # Invite participants
for participation in tournament.participations.filter(valid=True).all(): for participation in tournament.participations.filter(valid=True).all():
@ -327,97 +327,104 @@ class Command(BaseCommand):
# Create pool-specific channels # Create pool-specific channels
for pool in tournament.pools.all(): for pool in tournament.pools.all():
self.stdout.write(f"Managing {pool}...") self.stdout.write(f"Managing {pool}...")
if not Matrix.resolve_room_alias(f"#poule-{slug}-{pool.id}:tfjm.org"): five = pool.participations.count() >= 5
await Matrix.create_room( for i in range(2 if five else 1):
visibility=RoomVisibility.public, # Fix for five teams-pools
alias=f"poule-{slug}-{pool.id}", suffix = f"-{chr(ord('A') + i)}" if five else ""
name= if not Matrix.resolve_room_alias(f"#poule-{slug}-{pool.id}{suffix}:tfjm.org"):
f"{name} - Jour {pool.round} - Poule " await Matrix.create_room(
f"{', '.join(participation.team.trigram for participation in pool.participations.all())}", visibility=RoomVisibility.public,
topic=f"Discussion avec les équipes - {pool}", alias=f"poule-{slug}-{pool.id}{suffix}",
federate=False, name=f"{name} - Jour {pool.round} - Poule " +
preset=RoomPreset.private_chat, ', '.join(participation.team.trigram
) for participation in pool.participations.all()) + suffix,
if not Matrix.resolve_room_alias(f"#poule-{slug}-{pool.id}-jurys:tfjm.org"): topic=f"Discussion avec les équipes - {pool}{suffix}",
await Matrix.create_room( federate=False,
visibility=RoomVisibility.public, preset=RoomPreset.private_chat,
alias=f"poule-{slug}-{pool.id}-jurys", )
name= if not Matrix.resolve_room_alias(f"#poule-{slug}-{pool.id}{suffix}-jurys:tfjm.org"):
f"{name} - Jour {pool.round} - Jurys poule " await Matrix.create_room(
f"{', '.join(participation.team.trigram for participation in pool.participations.all())}", visibility=RoomVisibility.public,
topic=f"Discussion avec les jurys - {pool}", alias=f"poule-{slug}-{pool.id}{suffix}-jurys",
federate=False, name=f"{name} - Jour {pool.round}{suffix} - Jurys poule " +
preset=RoomPreset.private_chat, ', '.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) # Invite admins and give permissions
await Matrix.set_room_avatar(f"#poule-{slug}-{pool.id}-jurys:tfjm.org", avatar_uri) 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, # Invite organizers and give permissions
isAudioConf='false', displayName='$matrix_display_name', for orga in VolunteerRegistration.objects.all():
avatarUrl='$matrix_avatar_url', userId='$matrix_user_id')) \ await Matrix.invite(f"#poule-{slug}-{pool.id}{suffix}:tfjm.org",
.replace("%24", "$") f"@{orga.matrix_username}:tfjm.org")
await Matrix.add_integration( await Matrix.invite(f"#poule-{slug}-{pool.id}{suffix}-jurys:tfjm.org",
f"#poule-{slug}-{pool.id}:tfjm.org", f"@{orga.matrix_username}:tfjm.org")
f"https://scalar.vector.im/api/widgets/bigbluebutton.html?{url_params}",
f"bbb-{slug}-{pool.id}", "bigbluebutton", "BigBlueButton", str(pool)) if not orga.is_admin:
await Matrix.add_integration( await Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}{suffix}:tfjm.org",
f"#poule-{slug}-{pool.id}:tfjm.org", f"@{orga.matrix_username}:tfjm.org", 50)
f"https://board.tfjm.org/boards/{slug}-{pool.id}", f"board-{slug}-{pool.id}", await Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}{suffix}-jurys:tfjm.org",
"customwidget", "Tableau", str(pool)) 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 # Invite participants to the right pool
for admin in AdminRegistration.objects.all(): for participation in pool.participations.all():
await Matrix.invite(f"#poule-{slug}-{pool.id}:tfjm.org", for participant in participation.team.participants.all():
f"@{admin.matrix_username}:tfjm.org") await Matrix.invite(f"#poule-{slug}-{pool.id}{suffix}:tfjm.org",
await Matrix.invite(f"#poule-{slug}-{pool.id}-jurys:tfjm.org", f"@{participant.matrix_username}: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")
# Create private channels for teams # Create private channels for teams
for team in Team.objects.all(): for team in Team.objects.all():
@ -435,6 +442,6 @@ class Command(BaseCommand):
await Matrix.invite(f"#equipe-{team.trigram.lower}:tfjm.org", await Matrix.invite(f"#equipe-{team.trigram.lower}:tfjm.org",
f"@{participant.matrix_username}:tfjm.org") f"@{participant.matrix_username}:tfjm.org")
await Matrix.set_room_power_level(f"#equipe-{team.trigram.lower()}: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()) asyncio.get_event_loop().run_until_complete(main())

View File

@ -33,7 +33,7 @@
</dd> </dd>
<dt class="col-sm-3">{% trans "BigBlueButton link:" %}</dt> <dt class="col-sm-3">{% trans "BigBlueButton link:" %}</dt>
<dd class="col-sm-9"><a href="{{ pool.bbb_url }}">{{ pool.bbb_url }}</a></dd> <dd class="col-sm-9">{{ pool.bbb_url|urlize }}</dd>
</dl> </dl>
<div class="card bg-light shadow"> <div class="card bg-light shadow">