Commit 4db04e69 authored by Weblate's avatar Weblate

Merge remote-tracking branch 'origin/master'

parents 7167b8f0 c3e78193
......@@ -31,6 +31,7 @@ Released on ? 2015.
* Added support for translating and importing CSV files.
* Rewritten handling of static files.
* Direct login/registration links to third party service if that's the only one.
* Commit pending changes on account removal.
weblate 2.3
-----------
......
......@@ -41,6 +41,7 @@ from weblate.lang.models import Language
from weblate.trans.util import get_site_url, get_site_domain
from weblate.accounts.avatar import get_user_display
from weblate.trans.util import report_error
from weblate.trans.signals import user_pre_delete
import weblate
from weblate.appsettings import ANONYMOUS_USER_NAME, SITE_TITLE
......@@ -827,6 +828,9 @@ def remove_user(user):
'''
Removes user account.
'''
# Send signal (to commit any pending changes)
user_pre_delete.send(instance=user, sender=user.__class__)
# Change username
user.username = 'deleted-{0}'.format(user.pk)
while User.objects.filter(username=user.username).exists():
......
......@@ -454,19 +454,6 @@ class ViewTest(TestCase):
response = self.client.get(reverse('logout'))
self.assertRedirects(response, reverse('home'))
def test_removal(self):
# Create user
self.get_user()
# Login
self.client.login(username='testuser', password='testpassword')
response = self.client.post(
reverse('remove')
)
self.assertRedirects(response, reverse('home'))
self.assertFalse(
User.objects.filter(username='testuser').exists()
)
def test_password(self):
# Create user
self.get_user()
......@@ -860,3 +847,26 @@ class AvatarTest(ViewTestCase):
)
)
self.assertPNG(response)
class RemoveAcccountTest(ViewTestCase):
def test_removal(self):
response = self.client.post(
reverse('remove')
)
self.assertRedirects(response, reverse('home'))
self.assertFalse(
User.objects.filter(username='testuser').exists()
)
def test_removal_change(self):
response = self.edit_unit(
'Hello, world!\n',
'Nazdar svete!\n'
)
# We should have some change to commit
self.assertTrue(self.subproject.repo_needs_commit())
# Remove account
self.test_removal()
# Changes should be committed
self.assertFalse(self.subproject.repo_needs_commit())
......@@ -39,6 +39,7 @@ from weblate.trans.models.advertisement import Advertisement
from weblate.trans.models.whiteboard import WhiteboardMessage
from weblate.trans.signals import (
vcs_post_push, vcs_post_update, vcs_pre_commit, vcs_post_commit,
user_pre_delete,
)
from weblate.trans.scripts import (
run_post_push_script, run_post_update_script, run_pre_commit_script,
......@@ -224,3 +225,23 @@ def pre_commit(sender, translation, **kwargs):
@receiver(vcs_post_commit)
def post_commit(sender, translation, **kwargs):
run_post_commit_script(translation.subproject, translation.get_filename())
@receiver(user_pre_delete)
def user_commit_pending(sender, instance, **kwargs):
"""Commit pending changes for user on account removal."""
# All user changes
all_changes = Change.objects.last_changes(instance).filter(
user=instance,
)
# Filter where project is active
user_translation_ids = all_changes.values_list(
'translation', flat=True
).distinct()
# Commit changes where user is last author
for translation in Translation.objects.filter(pk__in=user_translation_ids):
last_author = translation.change_set.content()[0].author
if last_author == instance:
translation.commit_pending(None)
......@@ -25,3 +25,4 @@ vcs_post_push = Signal(providing_args=['subproject'])
vcs_post_update = Signal(providing_args=['subproject'])
vcs_pre_commit = Signal(providing_args=['translation'])
vcs_post_commit = Signal(providing_args=['translation'])
user_pre_delete = Signal()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment