From cfdb0c12805f4cb0c7b1f2aec5b09ded3000ee0d Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Thu, 11 Jun 2015 11:26:25 +0200 Subject: [PATCH] Adding new membership to timelines only if necessary --- ...lear_unnecessary_new_membership_entries.py | 36 +++++++++++++++++++ taiga/timeline/signals.py | 4 ++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 taiga/timeline/management/commands/clear_unnecessary_new_membership_entries.py diff --git a/taiga/timeline/management/commands/clear_unnecessary_new_membership_entries.py b/taiga/timeline/management/commands/clear_unnecessary_new_membership_entries.py new file mode 100644 index 00000000..2fde9a8d --- /dev/null +++ b/taiga/timeline/management/commands/clear_unnecessary_new_membership_entries.py @@ -0,0 +1,36 @@ +# Copyright (C) 2014 Andrey Antukh +# Copyright (C) 2014 Jesús Espino +# Copyright (C) 2014 David Barragán +# 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 . +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() diff --git a/taiga/timeline/signals.py b/taiga/timeline/signals.py index a90ce867..549e54ed 100644 --- a/taiga/timeline/signals.py +++ b/taiga/timeline/signals.py @@ -103,7 +103,9 @@ def on_new_history_entry(sender, instance, created, **kwargs): def create_membership_push_to_timeline(sender, instance, **kwargs): # 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") #Updating existing membership