diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 1eec1648..f880d485 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-17 17:55+0100\n" +"POT-Creation-Date: 2019-03-19 17:16+0100\n" "PO-Revision-Date: 2016-07-18\n" "Last-Translator: Skia \n" "Language-Team: AE info \n" @@ -4615,6 +4615,15 @@ msgstr "Supprimer tous les messages forum d'un utilisateur" msgid "Delete messages" msgstr "Supprimer les messages" +#: rootplace/templates/rootplace/delete_user_messages.jinja:14 +msgid "" +"If you have trouble using this utility (timeout error, 500 error), try using " +"the command line utility. Use ./manage.py delete_all_forum_user_messages ID." +msgstr "" +"Si vous avez des soucis en utilisant cet utilitaire (connexion expirée, " +"erreur 500), essayez en utilisant l'utilitaire en ligne de commande. " +"Utilisez ./manage.py delete_user_messages ID." + #: rootplace/templates/rootplace/merge.jinja:8 msgid "Merge two users" msgstr "Fusionner deux utilisateurs" @@ -4623,15 +4632,15 @@ msgstr "Fusionner deux utilisateurs" msgid "Merge" msgstr "Fusion" -#: rootplace/views.py:93 +#: rootplace/views.py:110 msgid "User that will be kept" msgstr "Utilisateur qui sera conservé" -#: rootplace/views.py:96 +#: rootplace/views.py:113 msgid "User that will be deleted" msgstr "Utilisateur qui sera supprimé" -#: rootplace/views.py:102 +#: rootplace/views.py:119 msgid "User to be selected" msgstr "Utilisateur à sélectionner" diff --git a/rootplace/management/__init__.py b/rootplace/management/__init__.py new file mode 100644 index 00000000..6492635a --- /dev/null +++ b/rootplace/management/__init__.py @@ -0,0 +1,23 @@ +# -*- coding:utf-8 -* +# +# Copyright 2016,2017 +# - Sli +# +# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM, +# http://ae.utbm.fr. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License a published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple +# Place - Suite 330, Boston, MA 02111-1307, USA. +# +# diff --git a/rootplace/management/commands/__init__.py b/rootplace/management/commands/__init__.py new file mode 100644 index 00000000..6492635a --- /dev/null +++ b/rootplace/management/commands/__init__.py @@ -0,0 +1,23 @@ +# -*- coding:utf-8 -* +# +# Copyright 2016,2017 +# - Sli +# +# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM, +# http://ae.utbm.fr. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License a published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple +# Place - Suite 330, Boston, MA 02111-1307, USA. +# +# diff --git a/rootplace/management/commands/delete_all_forum_user_messages.py b/rootplace/management/commands/delete_all_forum_user_messages.py new file mode 100644 index 00000000..3d6b4a22 --- /dev/null +++ b/rootplace/management/commands/delete_all_forum_user_messages.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# -*- coding:utf-8 -* +# +# Copyright 2017 +# - Sli +# +# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM, +# http://ae.utbm.fr. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License a published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple +# Place - Suite 330, Boston, MA 02111-1307, USA. +# +# + +from django.core.management.base import BaseCommand + +from core.models import User +from rootplace.views import delete_all_forum_user_messages + + +class Command(BaseCommand): + """ + Delete all forum messages from a user + """ + + help = "Delete all user's forum message" + + def add_arguments(self, parser): + parser.add_argument("user_id", type=int) + + def handle(self, *args, **options): + + user = User.objects.filter(id=options["user_id"]).first() + + if user is None: + print("User with ID %s not found" % (options["user_id"],)) + exit(1) + + confirm = input( + "User selected: %s\nDo you really want to delete all message from this user ? [y/N] " + % (user,) + ) + + if not confirm.lower().startswith("y"): + print("Operation aborted") + exit(1) + + delete_all_forum_user_messages(user, User.objects.get(id=0), True) diff --git a/rootplace/templates/rootplace/delete_user_messages.jinja b/rootplace/templates/rootplace/delete_user_messages.jinja index ce3c88ef..01866d6e 100644 --- a/rootplace/templates/rootplace/delete_user_messages.jinja +++ b/rootplace/templates/rootplace/delete_user_messages.jinja @@ -11,4 +11,5 @@ {{ form.as_p() }}

+

{% trans %}If you have trouble using this utility (timeout error, 500 error), try using the command line utility. Use ./manage.py delete_all_forum_user_messages ID.{% endtrans %}

{% endblock %} \ No newline at end of file diff --git a/rootplace/views.py b/rootplace/views.py index 0c52526c..70dce63e 100644 --- a/rootplace/views.py +++ b/rootplace/views.py @@ -25,7 +25,7 @@ from django.utils.translation import ugettext as _ from django.views.generic.edit import FormView -from django.core.urlresolvers import reverse, reverse_lazy +from django.core.urlresolvers import reverse from django import forms from django.core.exceptions import PermissionDenied @@ -33,6 +33,7 @@ from ajax_select.fields import AutoCompleteSelectField from core.models import User from counter.models import Customer + from forum.models import ForumMessageMeta @@ -88,6 +89,22 @@ def merge_users(u1, u2): return u1 +def delete_all_forum_user_messages(user, moderator, verbose=False): + """ + Create a ForumMessageMeta that says a forum + message is deleted on every forum message of an user + user: the user to delete messages from + moderator: the one marked as the moderator + """ + for message in user.forum_messages.all(): + if message.is_deleted(): + continue + + if verbose: + print(message) + ForumMessageMeta(message=message, user=moderator, action="DELETE").save() + + class MergeForm(forms.Form): user1 = AutoCompleteSelectField( "users", label=_("User that will be kept"), help_text=None, required=True @@ -127,6 +144,7 @@ class DeleteAllForumUserMessagesView(FormView): """ Delete all forum messages from an user Messages are soft deleted and are still visible from admins + GUI frontend to the dedicated command """ template_name = "rootplace/delete_user_messages.jinja" @@ -142,10 +160,7 @@ class DeleteAllForumUserMessagesView(FormView): def form_valid(self, form): self.user = form.cleaned_data["user"] - for message in self.user.forum_messages.all(): - ForumMessageMeta( - message=message, user=self.request.user, action="DELETE" - ).save() + delete_all_forum_user_messages(self.user, self.request.user) return super(DeleteAllForumUserMessagesView, self).form_valid(form) def get_success_url(self):