add a view to re-add IRC ACL if something went wrong the first time, add button on team_detail page to activate it

This commit is contained in:
Thomas Steen Rasmussen 2018-04-11 10:22:28 +02:00
parent fdb22777c4
commit 9951869a49
4 changed files with 89 additions and 0 deletions

View file

@ -0,0 +1,18 @@
{% extends 'base.html' %}
{% load commonmark %}
{% block title %}
Fix IRC permissions for NickServ user {{ request.user.profile.nickserv_username }} for IRC channel {{ team.irc_channel_name }}
{% endblock %}
{% block content %}
<h3>Fix IRC permissions</h3>
<p class="lead">This will make the bot re-add IRC ACL for your NickServ user <b>{{ request.user.profile.nickserv_username }}</b> for IRC channel <b>{{ team.irc_channel_name }}</b>. Use this in cases where you are unable to join the team IRC channel after entering your NickServ username in your profile.</p>
<form method="POST">
{% csrf_token %}
{{ form }}
<button class="btn btn-success" type="submit"><i class="fa fa-check"></i> Yes Please</button>
<a href="{% url 'teams:detail' camp_slug=team.camp.slug team_slug=team.slug %}" class="btn btn-default" type="submit"><i class="fa fa-remove"></i> Cancel</a>
</form>
{% endblock %}

View file

@ -70,6 +70,9 @@ Team: {{ team.name }} | {{ block.super }}
<p>Your membership status: <b>{% membershipstatus user team %}</b></p>
{% if request.user in team.members.all %}
{% if team.irc_channel and team.irc_channel_managed and request.user.profile.nickserv_username %}
<a href="{% url 'teams:fix_irc_acl' camp_slug=camp.slug team_slug=team.slug %}" class="btn btn-primary"><i class="fa fa-wrench"></i> Fix IRC ACL</a>&nbsp;
{% endif %}
<a href="{% url 'teams:leave' camp_slug=camp.slug team_slug=team.slug %}" class="btn btn-danger"><i class="fa fa-remove"></i> Leave Team</a>
{% else %}
{% if team.needs_members %}

View file

@ -43,6 +43,11 @@ urlpatterns = [
TeamManageView.as_view(),
name='manage'
),
url(
r'^fix_irc_acl/$',
FixIrcAclView.as_view(),
name='fix_irc_acl',
),
url(
r'^tasks/', include([
url(

View file

@ -215,3 +215,66 @@ class TaskUpdateView(LoginRequiredMixin, CampViewMixin, EnsureTeamResponsibleMix
def get_success_url(self):
return self.get_object().get_absolute_url()
class FixIrcAclView(LoginRequiredMixin, CampViewMixin, UpdateView):
template_name = "fix_irc_acl.html"
model = Team
fields = []
slug_url_kwarg = 'team_slug'
def dispatch(self, request, *args, **kwargs):
# we need to call the super().dispatch() method early so self.camp gets populated by CampViewMixin,
# because the lookups below depend on self.camp being set :)
response = super().dispatch(
request, *args, **kwargs
)
# check if the logged in user has an approved membership of this team
if request.user not in self.get_object().approved_members.all():
messages.error(request, 'No thanks')
return redirect('teams:detail', camp_slug=self.get_object().camp.slug, team_slug=self.get_object().slug)
# check if we manage the channel for this team
if not self.get_object().irc_channel or not self.get_object().irc_channel_managed:
messages.error(request, 'IRC functionality is disabled for this team, or the team channel is not managed by the bot')
return redirect('teams:detail', camp_slug=self.get_object().camp.slug, team_slug=self.get_object().slug)
# check if user has a nickserv username
if not request.user.profile.nickserv_username:
messages.error(request, 'Please go to your profile and set your NickServ username first. Make sure the account is registered with NickServ first!')
return redirect('teams:detail', camp_slug=self.get_object().camp.slug, team_slug=self.get_object().slug)
return response
def get(self, request, *args, **kwargs):
# get membership
try:
TeamMember.objects.get(
user=request.user,
team=self.get_object(),
approved=True,
irc_channel_acl_ok=True
)
except TeamMember.DoesNotExist:
# this membership is already marked as membership.irc_channel_acl_ok=False, no need to do anything
messages.error(request, 'No need, this membership is already marked as irc_channel_acl_ok=False, so the bot will fix the ACL soon')
return redirect('teams:detail', camp_slug=self.get_object().camp.slug, team_slug=self.get_object().slug)
return super().get(
request, *args, **kwargs
)
def form_valid(self, form):
membership = TeamMember.objects.get(
user=self.request.user,
team=self.get_object(),
approved=True,
irc_channel_acl_ok=True
)
membership.irc_channel_acl_ok = False
membership.save()
messages.success(self.request, "OK, hang on while we fix the permissions for your NickServ user '%s' for IRC channel '%s'" % (self.request.user.profile.nickserv_username, form.instance.irc_channel_name))
return redirect('teams:detail', camp_slug=form.instance.camp.slug, team_slug=form.instance.slug)