Skip to content

Commit e3541c0

Browse files
committed
Adding missing leave functionality on team channel creation page
1 parent 5033a7a commit e3541c0

4 files changed

Lines changed: 40 additions & 8 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 3.1.13 on 2024-10-11 16:42
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('accounts', '0021_slacksitesettings_remove_admin_from_channel'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='slacksitesettings',
15+
name='use_hackathon_slack_admins',
16+
field=models.BooleanField(default=False),
17+
),
18+
]

accounts/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ class SlackSiteSettings(SingletonModel):
211211
"be added to any new channels. If this is ticked, the user "
212212
"will be removed from private team channels if they are not "
213213
"part of the team, facilitator or the slack admins"))
214+
use_hackathon_slack_admins = models.BooleanField(
215+
default=False,
216+
help_text=("If ticked, the global Slack Admins will be ignored "
217+
"and the slack admins who are selected when creating "
218+
"the hackathon will be used instead"))
214219

215220
def __str__(self):
216221
return "Slack Settings"

hackathon/tasks.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ def create_new_hackathon_slack_channel(hackathon_id, channel_name):
7979
logger.info(f"Channel with id {channel} created.")
8080

8181
# Add admins to channel for administration purposes
82-
admin_usernames = [admin.username for admin in hackathon.channel_admins.all()]
82+
slack_admins = (hackathon.channel_admins.all()
83+
if slack_site_settings.use_hackathon_slack_admins
84+
else slack_site_settings.slack_admins.all())
85+
admin_usernames = [admin.username for admin in slack_admins]
8386
pattern = re.compile(r'^U[a-zA-Z0-9]*[_]T[a-zA-Z0-9]*$')
8487
admin_user_ids = ','.join([username.split('_')[0]
8588
for username in admin_usernames

teams/views.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
create_teams_in_view, update_team_participants,
2424
calculate_timezone_offset)
2525
from teams.forms import HackProjectForm, EditTeamName
26-
# from teams.tasks import remove_admin_from_channel
2726

2827
SLACK_CHANNEL_ENDPOINT = 'https://slack.com/api/conversations.create'
2928
SLACK_CHANNEL_INVITE_ENDPOINT = 'https://slack.com/api/conversations.invite'
@@ -47,8 +46,13 @@ def change_teams(request, hackathon_id):
4746
team_size = hackathon.team_size
4847
team_sizes = sorted(choose_team_sizes(participants, team_size))
4948
if len(team_sizes) == 0:
50-
return render(request, 'change_teams.html',
51-
{'num_participants': len(participants)})
49+
return render(request, 'change_teams.html', {
50+
'num_participants': len(participants),
51+
'hackathon_id': hackathon_id,
52+
'teams': [],
53+
'leftover_participants': [],
54+
'edit': edit,
55+
})
5256
grouped_participants, hackathon_level = group_participants(
5357
participants, len(team_sizes))
5458
team_levels = sorted(choose_team_levels(len(team_sizes), hackathon_level))
@@ -279,7 +283,10 @@ def create_private_channel(request, team_id):
279283
users.append(team.mentor.username)
280284

281285
# Add admins to channel for administration purposes
282-
for admin in slack_site_settings.slack_admins.all():
286+
slack_admins = (team.hackathon.channel_admins.all()
287+
if slack_site_settings.use_hackathon_slack_admins
288+
else slack_site_settings.slack_admins.all())
289+
for admin in slack_admins:
283290
users.append(admin.username)
284291
# First need to add Slack Bot to then add users to channel
285292
response = admin_client.invite_users_to_slack_channel(
@@ -311,10 +318,9 @@ def create_private_channel(request, team_id):
311318
f'Please add the missing users manually.'))
312319
else:
313320
messages.success(request, 'Private Slack Channel successfully created')
314-
321+
315322
if slack_site_settings.remove_admin_from_channel:
316-
# remove_admin_from_channel.apply_async(args=[users_to_invite, channel])
317-
pass
323+
admin_client.leave_channel(channel)
318324

319325
return redirect(reverse('view_team', kwargs={'team_id': team_id}))
320326

0 commit comments

Comments
 (0)