implement user welcome emails
emails trigger when they're marked as reviewedpull/5/head
parent
1a111be0d5
commit
ba05ec340c
|
@ -10,8 +10,16 @@ admin.site.unregister(Group)
|
||||||
class PubkeyInline(admin.TabularInline):
|
class PubkeyInline(admin.TabularInline):
|
||||||
model = Pubkey
|
model = Pubkey
|
||||||
|
|
||||||
|
def bulk_review(madmin, req, qs):
|
||||||
|
for townie in qs:
|
||||||
|
townie.reviewed = True
|
||||||
|
townie.save()
|
||||||
|
|
||||||
|
bulk_review.short_description = 'mark selected townies as reviewed'
|
||||||
|
|
||||||
@admin.register(Townie)
|
@admin.register(Townie)
|
||||||
class TownieAdmin(admin.ModelAdmin):
|
class TownieAdmin(admin.ModelAdmin):
|
||||||
inlines = [PubkeyInline]
|
inlines = [PubkeyInline]
|
||||||
list_display = ('reviewed', 'username', 'email')
|
list_display = ('reviewed', 'username', 'email')
|
||||||
ordering = ('reviewed',)
|
ordering = ('reviewed',)
|
||||||
|
actions = (bulk_review,)
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from django.db.models import Model
|
from django.db.models import Model
|
||||||
from django.db.models.signals import post_save
|
from django.db.models.signals import pre_save
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.db.models import TextField, BooleanField, CharField, ForeignKey
|
from django.db.models import TextField, BooleanField, CharField, ForeignKey
|
||||||
|
from django.template.loader import get_template
|
||||||
|
|
||||||
|
from common.mailing import send_email
|
||||||
|
from help.models import Ticket
|
||||||
|
|
||||||
SSH_TYPE_CHOICES = (
|
SSH_TYPE_CHOICES = (
|
||||||
('ssh-rsa', 'ssh-rsa',),
|
('ssh-rsa', 'ssh-rsa',),
|
||||||
|
@ -24,14 +27,22 @@ class Townie(User):
|
||||||
reasons = TextField(blank=True, null=False, default='')
|
reasons = TextField(blank=True, null=False, default='')
|
||||||
displayname = CharField(max_length=100, blank=False, null=False)
|
displayname = CharField(max_length=100, blank=False, null=False)
|
||||||
|
|
||||||
# TODO consider a generic ensure method that syncs this model with the
|
def send_welcome_email(self, admin_name='vilmibm'):
|
||||||
# system. there will likely be things besides shell that we want to keep
|
welcome_tmpl = get_template('users/welcome_email.txt')
|
||||||
# track of in the DB.
|
context = {
|
||||||
def ensure_shell(self):
|
'username': self.username,
|
||||||
"""Runs chsh for the user to set their shell to whatever self.shell
|
'admin_name': admin_name,
|
||||||
is."""
|
}
|
||||||
raise NotImplementedError()
|
text = welcome_tmpl.render(context)
|
||||||
|
from_address = '{}@tilde.town'.format(admin_name)
|
||||||
|
success = send_email(self.email, text, subject='tilde.town!', frum=from_address)
|
||||||
|
if not success:
|
||||||
|
Ticket.objects.create(name='system',
|
||||||
|
email='root@tilde.town',
|
||||||
|
issue_type='other',
|
||||||
|
issue_text='was not able to send welcome email to {} ({})'.format(
|
||||||
|
self.username,
|
||||||
|
self.email))
|
||||||
|
|
||||||
class Pubkey(Model):
|
class Pubkey(Model):
|
||||||
key_type = CharField(max_length=50,
|
key_type = CharField(max_length=50,
|
||||||
|
@ -43,11 +54,11 @@ class Pubkey(Model):
|
||||||
townie = ForeignKey(Townie)
|
townie = ForeignKey(Townie)
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=Townie)
|
@receiver(pre_save, sender=Townie)
|
||||||
def sync_system_state(sender, instance, created, **kwargs):
|
def on_townie_pre_save(sender, instance, **kwargs):
|
||||||
if created:
|
existing = Townie.objects.filter(username=instance.username)
|
||||||
print('TODO would create new user on system')
|
if not existing: # we're making a new user
|
||||||
else:
|
|
||||||
print('TODO would update existing user on system')
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not existing[0].reviewed and instance.reviewed == True:
|
||||||
|
instance.send_welcome_email()
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
Welcome to tilde.town, ~{{username}}!
|
||||||
|
|
||||||
|
Please take a moment to review our code of conduct: https://tilde.town/~wiki/conduct.html
|
||||||
|
|
||||||
|
and login with:
|
||||||
|
|
||||||
|
ssh -i /path/to/private/key {{username}}@tilde.town
|
||||||
|
|
||||||
|
File a help ticket if you have problems logging in (or other issues): https://cgi.tilde.town/help/tickets
|
||||||
|
|
||||||
|
See you on the server!!
|
||||||
|
|
||||||
|
~{{admin_name}}
|
Loading…
Reference in New Issue