kill user processes during rename and send email about it

feature/enhanced-ticket-view
vilmibm 2018-09-05 19:25:00 -07:00
parent 7fc039559e
commit 8be382da87
4 changed files with 43 additions and 9 deletions

View File

@ -10,6 +10,12 @@ def rename_user(old_username, new_username):
"""Given an old and a new username, renames user on disk with usermod.
Raises if the usermod call fails."""
args = [
'pkill',
'-u',
old_username]
subprocess.run(args, check=True)
# Rename user
args = [
'usermod',

View File

@ -6,15 +6,15 @@ from django.conf import settings
logger = logging.getLogger()
FROM='root@tilde.town'
EXTERNAL_FROM='tildetown@protonmail.ch'
def send_email(to, body, subject='a message from tilde.town', frum=FROM,):
def send_email(to, body, subject='a message from tilde.town'):
"""Sends an email using mailgun. Logs on failure."""
response = requests.post(
settings.MAILGUN_URL,
auth=('api', settings.MAILGUN_KEY),
data={
'from': frum,
'from': EXTERNAL_FROM,
'to': to,
'subject': subject,
'text': body

View File

@ -10,7 +10,7 @@ from django.contrib.auth.models import User
from django.db.models import TextField, BooleanField, CharField, ForeignKey
from django.template.loader import get_template
from common.mailing import send_email
from common.mailing import send_email, ADMIN_NAME
from help.models import Ticket
logger = logging.getLogger()
@ -51,16 +51,14 @@ class Townie(User):
def home(self):
return os.path.join('/home', self.username)
def send_welcome_email(self, admin_name='vilmibm'):
def send_welcome_email(self):
welcome_tmpl = get_template('users/welcome_email.txt')
context = {
'username': self.username,
'admin_name': admin_name,
'admin_name': ADMIN_NAME,
}
text = welcome_tmpl.render(context)
from_address = '{}@tilde.town'.format(admin_name)
success = send_email(self.email, text, subject='tilde.town!',
frum=from_address)
success = send_email(self.email, text, subject='tilde.town!')
if not success:
Ticket.objects.create(name='system',
email='root@tilde.town',
@ -167,6 +165,23 @@ class Townie(User):
return
logger.info('Renamed {} to {}'.format(old_username, self.username))
# send user an email
rename_tmpl = get_template('users/rename_email.txt')
context = {
'old_username': old_username,
'new_username': self.username
}
text = rename_tmpl.render(context)
success = send_email(self.email, text, subject='Your tilde.town user has been renamed!')
if not success:
Ticket.objects.create(name='system',
email='root@tilde.town',
issue_type='other',
issue_text='was not able to send rename email to {} ({})'.format(
self.username,
self.email))
class Pubkey(Model):
key_type = CharField(max_length=50,

View File

@ -0,0 +1,13 @@
hi!
you requested a new username on tilde.town. This process required logging you
out and killing any active processes you had running. sorry if this caused any
confusion or inconvenience.
old username: {{old_username}}
new username: {{new_username}}
you'll use this when ssh'ing into the town.
best,
~vilmibm