From 3fb20c942da5afece6f8717a9c3bf878e18b508a Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 18 Feb 2011 16:35:54 -0600 Subject: Remove maintainer relations if user marked inactive These users are being marked inactive because they are no longer developers; thus they should have all of their maintainer relations removed from the database. This is one of two causes of "orphan" package relation objects, the other being pkgbase values that go out of existence. Signed-off-by: Dan McGee --- packages/models.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'packages') diff --git a/packages/models.py b/packages/models.py index bc36f78..0afdee0 100644 --- a/packages/models.py +++ b/packages/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.db.models.signals import post_save from django.contrib.auth.models import User class PackageRelation(models.Model): @@ -46,4 +47,15 @@ class License(models.Model): class Meta: ordering = ['name'] +def remove_inactive_maintainers(sender, instance, created, **kwargs): + # instance is an auth.models.User; we want to remove any existing + # maintainer relations if the user is no longer active + if not instance.is_active: + maint_relations = PackageRelation.objects.filter(user=instance, + type=PackageRelation.MAINTAINER) + maint_relations.delete() + +post_save.connect(remove_inactive_maintainers, sender=User, + dispatch_uid="packages.models") + # vim: set ts=4 sw=4 et: -- cgit v1.2.3-24-g4f1b