2017-03-31 15:29:28 +00:00
from django . views . generic import ListView , DetailView
2018-03-04 13:42:57 +00:00
from django . views . generic . edit import CreateView , UpdateView
2017-03-31 15:29:28 +00:00
from camps . mixins import CampViewMixin
2017-11-23 22:09:14 +00:00
from . models import Team , TeamMember , TeamTask
2017-05-23 20:25:06 +00:00
from . email import add_added_membership_email , add_removed_membership_email
2017-04-02 16:04:57 +00:00
from django . contrib . auth . mixins import LoginRequiredMixin
from django . shortcuts import redirect
from django . contrib import messages
2018-03-04 13:42:57 +00:00
from django . http import HttpResponseRedirect
2017-05-23 19:21:47 +00:00
from django . views . generic . detail import SingleObjectMixin
2017-05-23 19:50:53 +00:00
from django . core . urlresolvers import reverse_lazy
Merge teamcomms branch. Refactor team app and add events app.
* Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have.
* default to the console backend for email unless we specifically ask for realworld email
* fix signal for public_credit_name approval irc message
* fix name display on /people/ page
* fix the text on people pages when all non-responsible team members are anonymous
* handle cases where we fallback to the area responsible properly
* readd removed property, it is used in team_detail view
* make it possible to filter profiles by public_credit_name_approved
* add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin
* add a few missing early returns
2018-04-09 21:11:05 +00:00
from django . conf import settings
2017-08-13 09:43:28 +00:00
from profiles . models import Profile
2017-05-23 20:28:21 +00:00
import logging
2017-05-23 20:25:06 +00:00
logger = logging . getLogger ( " bornhack. %s " % __name__ )
2017-03-31 15:29:28 +00:00
2017-11-24 21:19:17 +00:00
class EnsureTeamResponsibleMixin ( object ) :
Merge teamcomms branch. Refactor team app and add events app.
* Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have.
* default to the console backend for email unless we specifically ask for realworld email
* fix signal for public_credit_name approval irc message
* fix name display on /people/ page
* fix the text on people pages when all non-responsible team members are anonymous
* handle cases where we fallback to the area responsible properly
* readd removed property, it is used in team_detail view
* make it possible to filter profiles by public_credit_name_approved
* add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin
* add a few missing early returns
2018-04-09 21:11:05 +00:00
"""
Use to make sure request . user is responsible for the team specified by kwargs [ ' team_slug ' ]
"""
2017-05-24 05:49:32 +00:00
def dispatch ( self , request , * args , * * kwargs ) :
2017-11-24 21:19:17 +00:00
self . team = Team . objects . get ( slug = kwargs [ ' team_slug ' ] , camp = self . camp )
Merge teamcomms branch. Refactor team app and add events app.
* Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have.
* default to the console backend for email unless we specifically ask for realworld email
* fix signal for public_credit_name approval irc message
* fix name display on /people/ page
* fix the text on people pages when all non-responsible team members are anonymous
* handle cases where we fallback to the area responsible properly
* readd removed property, it is used in team_detail view
* make it possible to filter profiles by public_credit_name_approved
* add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin
* add a few missing early returns
2018-04-09 21:11:05 +00:00
if request . user not in self . team . responsible_members . all ( ) :
2017-05-24 05:49:32 +00:00
messages . error ( request , ' No thanks ' )
2017-11-24 21:19:17 +00:00
return redirect ( ' teams:detail ' , camp_slug = self . camp . slug , team_slug = self . team . slug )
2017-05-24 05:49:32 +00:00
return super ( ) . dispatch (
request , * args , * * kwargs
)
Merge teamcomms branch. Refactor team app and add events app.
* Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have.
* default to the console backend for email unless we specifically ask for realworld email
* fix signal for public_credit_name approval irc message
* fix name display on /people/ page
* fix the text on people pages when all non-responsible team members are anonymous
* handle cases where we fallback to the area responsible properly
* readd removed property, it is used in team_detail view
* make it possible to filter profiles by public_credit_name_approved
* add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin
* add a few missing early returns
2018-04-09 21:11:05 +00:00
class EnsureTeamMemberResponsibleMixin ( SingleObjectMixin ) :
"""
Use to make sure request . user is responsible for the team which TeamMember belongs to
"""
model = TeamMember
def dispatch ( self , request , * args , * * kwargs ) :
if request . user not in self . get_object ( ) . team . responsible_members . all ( ) :
messages . error ( request , ' No thanks ' )
return redirect ( ' teams:detail ' , camp_slug = self . get_object ( ) . team . camp . slug , team_slug = self . get_object ( ) . team . slug )
return super ( ) . dispatch (
request , * args , * * kwargs
)
2017-03-31 15:29:28 +00:00
class TeamListView ( CampViewMixin , ListView ) :
template_name = " team_list.html "
2017-04-02 16:04:57 +00:00
model = Team
2017-03-31 15:29:28 +00:00
context_object_name = ' teams '
2017-05-24 05:49:32 +00:00
class TeamDetailView ( CampViewMixin , DetailView ) :
2017-03-31 15:29:28 +00:00
template_name = " team_detail.html "
context_object_name = ' team '
2017-05-24 05:49:32 +00:00
model = Team
2017-11-24 21:06:23 +00:00
slug_url_kwarg = ' team_slug '
2017-05-24 05:49:32 +00:00
Merge teamcomms branch. Refactor team app and add events app.
* Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have.
* default to the console backend for email unless we specifically ask for realworld email
* fix signal for public_credit_name approval irc message
* fix name display on /people/ page
* fix the text on people pages when all non-responsible team members are anonymous
* handle cases where we fallback to the area responsible properly
* readd removed property, it is used in team_detail view
* make it possible to filter profiles by public_credit_name_approved
* add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin
* add a few missing early returns
2018-04-09 21:11:05 +00:00
def get_context_data ( self , * * kwargs ) :
context = super ( TeamDetailView , self ) . get_context_data ( * * kwargs )
context [ ' IRCBOT_SERVER_HOSTNAME ' ] = settings . IRCBOT_SERVER_HOSTNAME
context [ ' IRCBOT_PUBLIC_CHANNEL ' ] = settings . IRCBOT_PUBLIC_CHANNEL
return context
2017-05-24 05:49:32 +00:00
class TeamManageView ( CampViewMixin , EnsureTeamResponsibleMixin , UpdateView ) :
model = Team
template_name = " team_manage.html "
Merge teamcomms branch. Refactor team app and add events app.
* Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have.
* default to the console backend for email unless we specifically ask for realworld email
* fix signal for public_credit_name approval irc message
* fix name display on /people/ page
* fix the text on people pages when all non-responsible team members are anonymous
* handle cases where we fallback to the area responsible properly
* readd removed property, it is used in team_detail view
* make it possible to filter profiles by public_credit_name_approved
* add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin
* add a few missing early returns
2018-04-09 21:11:05 +00:00
fields = [ ' description ' , ' needs_members ' , ' irc_channel ' , ' irc_channel_name ' , ' irc_channel_managed ' , ' irc_channel_private ' ]
2017-11-24 21:06:23 +00:00
slug_url_kwarg = ' team_slug '
2017-05-24 05:49:32 +00:00
def get_success_url ( self ) :
2018-03-04 15:34:10 +00:00
return reverse_lazy ( ' teams:detail ' , kwargs = { ' camp_slug ' : self . camp . slug , ' team_slug ' : self . get_object ( ) . slug } )
2017-04-02 16:04:57 +00:00
Merge teamcomms branch. Refactor team app and add events app.
* Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have.
* default to the console backend for email unless we specifically ask for realworld email
* fix signal for public_credit_name approval irc message
* fix name display on /people/ page
* fix the text on people pages when all non-responsible team members are anonymous
* handle cases where we fallback to the area responsible properly
* readd removed property, it is used in team_detail view
* make it possible to filter profiles by public_credit_name_approved
* add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin
* add a few missing early returns
2018-04-09 21:11:05 +00:00
def form_valid ( self , form ) :
messages . success ( self . request , " Team has been saved " )
return super ( ) . form_valid ( form )
2017-04-02 16:04:57 +00:00
class TeamJoinView ( LoginRequiredMixin , CampViewMixin , UpdateView ) :
template_name = " team_join.html "
model = Team
fields = [ ]
2017-11-24 21:06:23 +00:00
slug_url_kwarg = ' team_slug '
2017-04-02 16:04:57 +00:00
def get ( self , request , * args , * * kwargs ) :
2017-08-13 09:43:28 +00:00
if not Profile . objects . get ( user = request . user ) . description :
messages . warning (
request ,
" Please fill the description in your profile before joining a team "
)
2017-11-23 22:09:14 +00:00
return redirect ( ' teams:list ' , camp_slug = self . camp . slug )
2017-08-13 09:43:28 +00:00
2017-04-02 16:04:57 +00:00
if request . user in self . get_object ( ) . members . all ( ) :
messages . warning ( request , " You are already a member of this team " )
2017-11-23 22:09:14 +00:00
return redirect ( ' teams:list ' , camp_slug = self . camp . slug )
2017-04-02 16:04:57 +00:00
if not self . get_object ( ) . needs_members :
messages . warning ( request , " This team does not need members right now " )
2017-11-23 22:09:14 +00:00
return redirect ( ' teams:list ' , camp_slug = self . get_object ( ) . camp . slug )
2017-04-02 16:04:57 +00:00
return super ( ) . get ( request , * args , * * kwargs )
def form_valid ( self , form ) :
TeamMember . objects . create ( team = self . get_object ( ) , user = self . request . user )
messages . success ( self . request , " You request to join the team %s has been registered, thank you. " % self . get_object ( ) . name )
2017-11-23 22:09:14 +00:00
return redirect ( ' teams:list ' , camp_slug = self . get_object ( ) . camp . slug )
2017-04-02 16:04:57 +00:00
class TeamLeaveView ( LoginRequiredMixin , CampViewMixin , UpdateView ) :
template_name = " team_leave.html "
model = Team
fields = [ ]
2017-11-24 21:06:23 +00:00
slug_url_kwarg = ' team_slug '
2017-04-02 16:04:57 +00:00
def get ( self , request , * args , * * kwargs ) :
if request . user not in self . get_object ( ) . members . all ( ) :
messages . warning ( request , " You are not a member of this team " )
2017-11-23 22:09:14 +00:00
return redirect ( ' teams:list ' , camp_slug = self . get_object ( ) . camp . slug )
2017-04-02 16:04:57 +00:00
return super ( ) . get ( request , * args , * * kwargs )
def form_valid ( self , form ) :
TeamMember . objects . filter ( team = self . get_object ( ) , user = self . request . user ) . delete ( )
messages . success ( self . request , " You are no longer a member of the team %s " % self . get_object ( ) . name )
2017-11-23 22:09:14 +00:00
return redirect ( ' teams:list ' , camp_slug = self . get_object ( ) . camp . slug )
2017-05-23 19:21:47 +00:00
2017-05-24 05:49:32 +00:00
class TeamMemberRemoveView ( LoginRequiredMixin , CampViewMixin , EnsureTeamMemberResponsibleMixin , UpdateView ) :
2017-05-23 19:21:47 +00:00
template_name = " teammember_remove.html "
model = TeamMember
fields = [ ]
def form_valid ( self , form ) :
form . instance . delete ( )
2017-05-23 20:25:06 +00:00
if add_removed_membership_email ( form . instance ) :
messages . success ( self . request , " Team member removed " )
else :
messages . success ( self . request , " Team member removed (unable to add email to outgoing queue). " )
logger . error (
' Unable to add removed email to outgoing queue for teammember: {} ' . format ( form . instance )
)
2017-11-24 21:06:23 +00:00
return redirect ( ' teams:detail ' , camp_slug = self . camp . slug , team_slug = form . instance . team . slug )
2017-05-23 19:50:53 +00:00
2017-05-24 05:49:32 +00:00
class TeamMemberApproveView ( LoginRequiredMixin , CampViewMixin , EnsureTeamMemberResponsibleMixin , UpdateView ) :
2017-05-23 19:50:53 +00:00
template_name = " teammember_approve.html "
model = TeamMember
fields = [ ]
def form_valid ( self , form ) :
form . instance . approved = True
form . instance . save ( )
2017-05-23 20:25:06 +00:00
if add_added_membership_email ( form . instance ) :
messages . success ( self . request , " Team member approved " )
else :
messages . success ( self . request , " Team member removed (unable to add email to outgoing queue). " )
logger . error (
' Unable to add approved email to outgoing queue for teammember: {} ' . format ( form . instance )
)
2017-11-24 21:06:23 +00:00
return redirect ( ' teams:detail ' , camp_slug = self . camp . slug , team_slug = form . instance . team . slug )
2017-05-24 05:49:32 +00:00
2017-11-23 22:09:14 +00:00
class TaskDetailView ( CampViewMixin , DetailView ) :
template_name = " task_detail.html "
context_object_name = " task "
model = TeamTask
2017-11-24 21:06:23 +00:00
class TaskCreateView ( LoginRequiredMixin , CampViewMixin , EnsureTeamResponsibleMixin , CreateView ) :
model = TeamTask
2017-11-25 12:02:32 +00:00
template_name = " task_form.html "
2017-11-24 21:06:23 +00:00
fields = [ ' name ' , ' description ' ]
def get_context_data ( self , * args , * * kwargs ) :
context = super ( ) . get_context_data ( * * kwargs )
context [ ' team ' ] = self . team
return context
2017-11-25 12:02:32 +00:00
def form_valid ( self , form ) :
task = form . save ( commit = False )
task . team = self . team
if not task . name :
task . name = " noname "
task . save ( )
return HttpResponseRedirect ( task . get_absolute_url ( ) )
2017-11-24 21:06:23 +00:00
def get_success_url ( self ) :
2017-11-25 12:02:32 +00:00
return self . get_object ( ) . get_absolute_url ( )
class TaskUpdateView ( LoginRequiredMixin , CampViewMixin , EnsureTeamResponsibleMixin , UpdateView ) :
model = TeamTask
template_name = " task_form.html "
fields = [ ' name ' , ' description ' ]
def get_context_data ( self , * args , * * kwargs ) :
context = super ( ) . get_context_data ( * * kwargs )
context [ ' team ' ] = self . team
return context
def form_valid ( self , form ) :
task = form . save ( commit = False )
task . team = self . team
if not task . name :
task . name = " noname "
task . save ( )
return HttpResponseRedirect ( task . get_absolute_url ( ) )
def get_success_url ( self ) :
return self . get_object ( ) . get_absolute_url ( )
2017-11-24 21:06:23 +00:00
2018-04-11 08:22:28 +00:00
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 )