ircbot: tie bot users to django auth user, part 1
sets up the foreign key and changes how is_admin() works, though it will be going away pretty soon, i just need to do this migration in parts so as to not confuse django too much
This commit is contained in:
parent
243531c017
commit
123acbbd8d
|
@ -1,5 +1,7 @@
|
||||||
"""Manage ircbot models and admin actions in the admin interface."""
|
"""Manage ircbot models and admin actions in the admin interface."""
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import xmlrpclib
|
import xmlrpclib
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
"""Library and convenience methods for the IRC bot and plugins."""
|
"""Library and convenience methods for the IRC bot and plugins."""
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import irc.client
|
import irc.client
|
||||||
|
@ -45,11 +47,14 @@ class Plugin(object):
|
||||||
def is_admin(source):
|
def is_admin(source):
|
||||||
"""Check if the provided event source is a bot admin."""
|
"""Check if the provided event source is a bot admin."""
|
||||||
|
|
||||||
if source in BotAdmin.objects.values_list('nickmask', flat=True):
|
try:
|
||||||
log.debug(u"in is_admin; True")
|
bot_user = BotAdmin.objects.get(nickmask=source)
|
||||||
return True
|
log.debug("found bot user {0:s}".format(bot_user))
|
||||||
log.debug(u"in is_admin; False")
|
except BotAdmin.DoesNotExist:
|
||||||
return False
|
log.debug("could not find bot user for {0:s}".format(source))
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def reply_destination_for_event(event):
|
def reply_destination_for_event(event):
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, migrations
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
('ircbot', '0008_auto_20150521_2113'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='botadmin',
|
||||||
|
name='user',
|
||||||
|
field=models.ForeignKey(default=1, to=settings.AUTH_USER_MODEL),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,8 +1,11 @@
|
||||||
"""Track basic IRC settings and similar."""
|
"""Track basic IRC settings and similar."""
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
|
@ -23,7 +26,7 @@ class Alias(models.Model):
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
"""String representation."""
|
"""String representation."""
|
||||||
|
|
||||||
return u"{0:s} -> {1:s}".format(self.pattern, self.replacement)
|
return "{0:s} -> {1:s}".format(self.pattern, self.replacement)
|
||||||
|
|
||||||
def replace(self, what):
|
def replace(self, what):
|
||||||
command = None
|
command = None
|
||||||
|
@ -38,11 +41,12 @@ class BotAdmin(models.Model):
|
||||||
"""Configure admins, which can do things through the bot that others can't."""
|
"""Configure admins, which can do things through the bot that others can't."""
|
||||||
|
|
||||||
nickmask = models.CharField(max_length=200, unique=True)
|
nickmask = models.CharField(max_length=200, unique=True)
|
||||||
|
user = models.ForeignKey(settings.AUTH_USER_MODEL)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
"""String representation."""
|
"""String representation."""
|
||||||
|
|
||||||
return u"{0:s}".format(self.nickmask)
|
return "{0:s} (Django user {1:s})".format(self.nickmask, self.user.username)
|
||||||
|
|
||||||
|
|
||||||
class IrcChannel(models.Model):
|
class IrcChannel(models.Model):
|
||||||
|
@ -59,7 +63,7 @@ class IrcChannel(models.Model):
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
"""String representation."""
|
"""String representation."""
|
||||||
|
|
||||||
return u"{0:s}".format(self.name)
|
return "{0:s}".format(self.name)
|
||||||
|
|
||||||
|
|
||||||
class IrcPlugin(models.Model):
|
class IrcPlugin(models.Model):
|
||||||
|
@ -75,4 +79,4 @@ class IrcPlugin(models.Model):
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
"""String representation."""
|
"""String representation."""
|
||||||
|
|
||||||
return u"{0:s}".format(self.path)
|
return "{0:s}".format(self.path)
|
||||||
|
|
Loading…
Reference in New Issue