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."""
 | 
			
		||||
 | 
			
		||||
from __future__ import unicode_literals
 | 
			
		||||
 | 
			
		||||
import logging
 | 
			
		||||
import xmlrpclib
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,7 @@
 | 
			
		||||
"""Library and convenience methods for the IRC bot and plugins."""
 | 
			
		||||
 | 
			
		||||
from __future__ import unicode_literals
 | 
			
		||||
 | 
			
		||||
import logging
 | 
			
		||||
 | 
			
		||||
import irc.client
 | 
			
		||||
@ -45,12 +47,15 @@ class Plugin(object):
 | 
			
		||||
def is_admin(source):
 | 
			
		||||
    """Check if the provided event source is a bot admin."""
 | 
			
		||||
 | 
			
		||||
    if source in BotAdmin.objects.values_list('nickmask', flat=True):
 | 
			
		||||
        log.debug(u"in is_admin; True")
 | 
			
		||||
        return True
 | 
			
		||||
    log.debug(u"in is_admin; False")
 | 
			
		||||
    try:
 | 
			
		||||
        bot_user = BotAdmin.objects.get(nickmask=source)
 | 
			
		||||
        log.debug("found bot user {0:s}".format(bot_user))
 | 
			
		||||
    except BotAdmin.DoesNotExist:
 | 
			
		||||
        log.debug("could not find bot user for {0:s}".format(source))
 | 
			
		||||
        return False
 | 
			
		||||
 | 
			
		||||
    return True
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def reply_destination_for_event(event):
 | 
			
		||||
    """Get the "natural" reply destination for an event.
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										22
									
								
								dr_botzo/ircbot/migrations/0009_botadmin_user.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								dr_botzo/ircbot/migrations/0009_botadmin_user.py
									
									
									
									
									
										Normal file
									
								
							@ -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."""
 | 
			
		||||
 | 
			
		||||
from __future__ import unicode_literals
 | 
			
		||||
 | 
			
		||||
import logging
 | 
			
		||||
import re
 | 
			
		||||
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
from django.db import models
 | 
			
		||||
from django.utils import timezone
 | 
			
		||||
 | 
			
		||||
@ -23,7 +26,7 @@ class Alias(models.Model):
 | 
			
		||||
    def __unicode__(self):
 | 
			
		||||
        """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):
 | 
			
		||||
        command = None
 | 
			
		||||
@ -38,11 +41,12 @@ class BotAdmin(models.Model):
 | 
			
		||||
    """Configure admins, which can do things through the bot that others can't."""
 | 
			
		||||
 | 
			
		||||
    nickmask = models.CharField(max_length=200, unique=True)
 | 
			
		||||
    user = models.ForeignKey(settings.AUTH_USER_MODEL)
 | 
			
		||||
 | 
			
		||||
    def __unicode__(self):
 | 
			
		||||
        """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):
 | 
			
		||||
@ -59,7 +63,7 @@ class IrcChannel(models.Model):
 | 
			
		||||
    def __unicode__(self):
 | 
			
		||||
        """String representation."""
 | 
			
		||||
 | 
			
		||||
        return u"{0:s}".format(self.name)
 | 
			
		||||
        return "{0:s}".format(self.name)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class IrcPlugin(models.Model):
 | 
			
		||||
@ -75,4 +79,4 @@ class IrcPlugin(models.Model):
 | 
			
		||||
    def __unicode__(self):
 | 
			
		||||
        """String representation."""
 | 
			
		||||
 | 
			
		||||
        return u"{0:s}".format(self.path)
 | 
			
		||||
        return "{0:s}".format(self.path)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user