Skip to content

Commit ce023a6

Browse files
Changing logic to create private channels instead of IM Groups (#276)
* Changing logic to create private channels instead of IM Groups * Fixing some linting
1 parent 8cd5580 commit ce023a6

19 files changed

Lines changed: 407 additions & 63 deletions

File tree

accounts/admin.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.contrib.auth.decorators import login_required
55

66
from .models import CustomUser, Organisation
7+
from accounts.models import SlackSiteSettings
78

89

910
class CustomUserAdmin(BaseUserAdmin):
@@ -38,7 +39,7 @@ class CustomUserAdmin(BaseUserAdmin):
3839

3940
form = UserChangeForm
4041
add_form = UserCreationForm
41-
list_display = ('email', 'full_name', 'is_superuser', 'user_type',
42+
list_display = ('email', 'username', 'full_name', 'is_superuser', 'user_type',
4243
'is_external')
4344
list_filter = ('is_staff', 'is_superuser', 'is_active', 'groups',
4445
'is_external')
@@ -52,3 +53,4 @@ class CustomUserAdmin(BaseUserAdmin):
5253
admin.site.login = login_required(admin.site.login)
5354
admin.site.register(CustomUser, CustomUserAdmin)
5455
admin.site.register(Organisation)
56+
admin.site.register(SlackSiteSettings)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Generated by Django 3.1.13 on 2022-12-19 14:45
2+
3+
from django.conf import settings
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('accounts', '0017_customuser_timezone'),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='SlackSiteSettings',
16+
fields=[
17+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('enable_welcome_emails', models.BooleanField(default=True)),
19+
('communication_channel_type', models.CharField(choices=[('slack_private_channel', 'Private Slack Channel'), ('other', 'Other')], default='slack_private_channel', max_length=50)),
20+
('slack_admins', models.ManyToManyField(related_name='slacksitesettings', to=settings.AUTH_USER_MODEL)),
21+
],
22+
options={
23+
'verbose_name': 'Slack Site Settings',
24+
'verbose_name_plural': 'Slack Site Settings',
25+
},
26+
),
27+
]

accounts/models.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66
from django.contrib.auth.models import AbstractUser
77

88
from .lists import LMS_MODULES_CHOICES, TIMEZONE_CHOICES
9+
from main.models import SingletonModel
910
from teams.lists import LMS_LEVELS
1011

12+
COMMUNICATION_CHANNEL_TYPES = [
13+
('slack_private_channel', 'Private Slack Channel'),
14+
('other', 'Other'),
15+
]
16+
1117

1218
class UserType(Enum):
1319
SUPERUSER = 0
@@ -144,6 +150,13 @@ def participant_label(self):
144150
return 'Hackathon Enthusiast'
145151
else:
146152
return 'Hackathon Veteran'
153+
154+
def is_participant(self, hackathon):
155+
if not hackathon:
156+
return False
157+
158+
return self in hackathon.participants.all()
159+
147160

148161
@property
149162
def user_type(self):
@@ -180,3 +193,20 @@ def user_type(self):
180193
else:
181194
# A non-specified group
182195
return None
196+
197+
198+
class SlackSiteSettings(SingletonModel):
199+
""" Model to set how the showcase should be constructed"""
200+
slack_admins = models.ManyToManyField(CustomUser,
201+
related_name="slacksitesettings")
202+
enable_welcome_emails = models.BooleanField(default=True)
203+
communication_channel_type = models.CharField(
204+
max_length=50, choices=COMMUNICATION_CHANNEL_TYPES,
205+
default='slack_private_channel')
206+
207+
def __str__(self):
208+
return "Slack Settings"
209+
210+
class Meta:
211+
verbose_name = 'Slack Site Settings'
212+
verbose_name_plural = 'Slack Site Settings'
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Generated by Django 3.1.13 on 2022-12-19 14:21
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('competencies', '0002_auto_20220808_1029'),
10+
]
11+
12+
operations = [
13+
migrations.AlterModelOptions(
14+
name='competencyassessment',
15+
options={'verbose_name': 'Competency Self Assessment', 'verbose_name_plural': 'Competency Self Assessments'},
16+
),
17+
migrations.AlterModelOptions(
18+
name='competencyassessmentrating',
19+
options={'verbose_name': 'Competency Self Assessment Rating', 'verbose_name_plural': 'Competency Self Assessment Ratings'},
20+
),
21+
]
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 2022-12-19 14:21
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('hackathon', '0046_auto_20220113_1350'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='hackathon',
15+
name='is_public',
16+
field=models.BooleanField(default=True),
17+
),
18+
]
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 2022-12-19 16:55
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('hackathon', '0047_auto_20221219_1421'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='hackteam',
15+
name='communication_channel',
16+
field=models.CharField(blank=True, default='', help_text='Usually a link to the Private Slack Channel, but can be a link to something else.', max_length=255),
17+
),
18+
]

hackathon/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class HackTeam(models.Model):
188188
on_delete=models.SET_NULL)
189189
communication_channel = models.CharField(
190190
default="", max_length=255, blank=True,
191-
help_text=("Usually a link to the Slack group IM, but can be a link "
191+
help_text=("Usually a link to the Private Slack Channel, but can be a link "
192192
"to something else."))
193193

194194
def __str__(self):

hackathon/templates/hackathon/hackathon_view.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@
9999
<p class="hackathon-sub-details"><i class="far fa-question-circle"></i> Status: {{ hackathon.status }}</p>
100100
<p class="hackathon-sub-details"><i class="fas fa-chalkboard-teacher"></i> Organiser: {{ hackathon.organiser }}</p>
101101
<p class="hackathon-sub-details"><i class="fas fa-users"></i>
102+
Participants: {{ hackathon.participants.all|length }} / Teams: {{ hackathon.teams.all|length }}</p>
103+
</p>
104+
<p class="hackathon-sub-details"><i class="fas fa-user-friends"></i>
102105
Max Participants: {% if hackathon.max_participants %}{{ hackathon.max_participants }}{% else %}Unlimited{% endif %}
103106
{% if hackathon.max_participants_reached %}(Max Reached){% endif %}
104107
</p>

hackathon/templates/hackathon/includes/enrollpart.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<a class="ci-link ml-2" href="/teams/{{participant_team.id}}/">{{participant_team}}</a>
4747
</strong>
4848
<div class="mt-2 slack-mpim">
49-
{% include 'includes/create_slack_mpim.html' with team=participant_team button_class='btn btn-sm btn-ci' %}
49+
{% include 'includes/create_slack_private_channel.html' with team=participant_team button_class='btn btn-sm btn-ci' %}
5050
</div>
5151
{% else %}
5252
You have not been assigned a team yet.

hackathon/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,13 @@ def view_hackathon(request, hackathon_id):
360360
paginator = Paginator(teams, 3)
361361
page = request.GET.get('page')
362362
paged_teams = paginator.get_page(page)
363-
create_group_im = (settings.SLACK_ENABLED and settings.SLACK_BOT_TOKEN)
363+
create_private_channel = (settings.SLACK_ENABLED and settings.SLACK_BOT_TOKEN)
364364

365365
context = {
366366
'hackathon': hackathon,
367367
'teams': paged_teams,
368368
'change_status_form': ChangeHackathonStatusForm(instance=hackathon),
369-
'create_group_im': create_group_im,
369+
'create_private_channel': create_private_channel,
370370
}
371371

372372
return render(request, "hackathon/hackathon_view.html", context)

0 commit comments

Comments
 (0)