tildetown-admin/ttadmin/users/models.py

47 lines
1.5 KiB
Python
Raw Normal View History

2016-11-30 07:48:02 +00:00
import re
2016-11-20 05:34:38 +00:00
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.contrib.auth.models import User
2016-11-21 07:56:55 +00:00
from django.db.models import TextField, BooleanField, CharField
2016-11-20 05:34:38 +00:00
2016-11-30 07:48:02 +00:00
2016-11-22 05:14:47 +00:00
SSH_TYPE_CHOICES = (
('ssh-rsa', 'ssh-rsa',),
('ssh-dss', 'ssh-dss',),
)
2016-11-20 05:34:38 +00:00
2016-11-30 07:48:02 +00:00
2016-11-20 05:34:38 +00:00
class Townie(User):
"""Both an almost normal Django User as well as an abstraction over a
system user."""
2017-01-13 21:22:52 +00:00
class Meta:
verbose_name = 'Townie'
verbose_name_plural = 'Townies'
2016-11-20 05:34:38 +00:00
pubkey = TextField(blank=False, null=False)
2016-11-21 07:56:55 +00:00
shell = CharField(max_length=50, default="/bin/bash")
reviewed = BooleanField(default=False)
2016-11-30 07:48:02 +00:00
reasons = TextField(blank=True, null=False, default='')
2016-11-21 07:56:55 +00:00
displayname = CharField(max_length=100, blank=False, null=False)
2016-11-22 05:14:47 +00:00
pubkey_type = CharField(max_length=15,
blank=False,
null=False,
choices=SSH_TYPE_CHOICES)
2016-11-20 05:34:38 +00:00
2016-12-01 06:49:06 +00:00
# TODO consider a generic ensure method that syncs this model with the
# system. there will likely be things besides shell that we want to keep
# track of in the DB.
2016-11-20 05:34:38 +00:00
def ensure_shell(self):
"""Runs chsh for the user to set their shell to whatever self.shell
is."""
raise NotImplementedError()
@receiver(post_save, sender=Townie)
def sync_system_state(sender, instance, created, **kwargs):
if created:
print('TODO would create new user on system')
else:
print('TODO would update existing user on system')
return