[backport] Adding new membership to timelines only if necessary

remotes/origin/enhancement/email-actions
Alejandro Alonso 2015-06-11 11:26:25 +02:00
parent 538805bd73
commit 412c25faee
2 changed files with 39 additions and 1 deletions

View File

@ -0,0 +1,36 @@
# Copyright (C) 2014 Andrey Antukh <niwi@niwi.be>
# Copyright (C) 2014 Jesús Espino <jespinog@gmail.com>
# Copyright (C) 2014 David Barragán <bameda@dbarragan.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.conf import settings
from django.core.management.base import BaseCommand
from taiga.timeline.models import Timeline
from taiga.projects.models import Project
class Command(BaseCommand):
help = 'Regenerate unnecessary new memberships entry lines'
def handle(self, *args, **options):
debug_enabled = settings.DEBUG
if debug_enabled:
print("Please, execute this script only with DEBUG mode disabled (DEBUG=False)")
return
removing_timeline_ids = []
for t in Timeline.objects.filter(event_type="projects.membership.create").order_by("created"):
print(t.created)
if t.project.owner.id == t.data["user"]["id"]:
removing_timeline_ids.append(t.id)
Timeline.objects.filter(id__in=removing_timeline_ids).delete()

View File

@ -103,7 +103,9 @@ def on_new_history_entry(sender, instance, created, **kwargs):
def create_membership_push_to_timeline(sender, instance, **kwargs): def create_membership_push_to_timeline(sender, instance, **kwargs):
# Creating new membership with associated user # Creating new membership with associated user
if not instance.pk and instance.user: # If the user is the project owner we don't do anything because that info will
# be shown in created project timeline entry
if not instance.pk and instance.user and instance.user != instance.project.owner:
_push_to_timelines(instance.project, instance.user, instance, "create") _push_to_timelines(instance.project, instance.user, instance, "create")
#Updating existing membership #Updating existing membership