Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #843 from akatsoulas/1091468
Browse files Browse the repository at this point in the history
[fix bug 1091468] Resolve action item if there is no assignee.
  • Loading branch information
johngian committed Oct 30, 2014
2 parents 13c065d + fdd5399 commit ccff645
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models


class Migration(SchemaMigration):

def forwards(self, orm):
# Removing unique constraint on 'ActionItem', fields ['name', 'object_id', 'user']
db.delete_unique(u'dashboard_actionitem', ['name', 'object_id', 'user_id'])


def backwards(self, orm):
# Adding unique constraint on 'ActionItem', fields ['name', 'object_id', 'user']
db.create_unique(u'dashboard_actionitem', ['name', 'object_id', 'user_id'])


models = {
u'auth.group': {
'Meta': {'object_name': 'Group'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
u'auth.permission': {
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
u'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
u'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
u'dashboard.actionitem': {
'Meta': {'ordering': "['-due_date', '-updated_on', '-created_on']", 'object_name': 'ActionItem'},
'completed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
'created_on': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'due_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'object_id': ('django.db.models.fields.PositiveIntegerField', [], {}),
'priority': ('django.db.models.fields.IntegerField', [], {}),
'resolved': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'updated_on': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'action_items_assigned'", 'to': u"orm['auth.User']"})
}
}

complete_apps = ['dashboard']
4 changes: 2 additions & 2 deletions remo/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def get_absolute_url(self):

class Meta:
ordering = ['-due_date', '-updated_on', '-created_on']
unique_together = ('name', 'user', 'object_id')

def __unicode__(self):
return self.name
Expand All @@ -62,7 +61,8 @@ def create(instance, **kwargs):
action_items = ActionItem.objects.filter(content_type=action_model,
object_id=instance.id,
name=item.name,
user=item.user)
user=item.user,
resolved=False)
if not action_items.exists():
data = {
'content_object': instance,
Expand Down
26 changes: 26 additions & 0 deletions remo/dashboard/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,32 @@ def test_council_reviewer_removed(self):
ok_(item.completed)
ok_(item.resolved)

def test_remove_assignee(self):
model = ContentType.objects.get_for_model(Bug)
items = ActionItem.objects.filter(content_type=model)

ok_(not items.exists())

mentor = UserFactory.create(groups=['Rep', 'Mentor'])
UserFactory.create(groups=['Rep'], userprofile__mentor=mentor)

bug = BugFactory.create(pending_mentor_validation=True,
assigned_to=mentor)

items = ActionItem.objects.filter(content_type=model)
eq_(items.count(), 1)
eq_(items[0].name, 'Waiting mentor validation')
eq_(items[0].user, mentor)
eq_(items[0].priority, ActionItem.BLOCKER)

bug.assigned_to = None
bug.save()

items = ActionItem.objects.filter(content_type=model)
for item in items:
ok_(item.resolved)
ok_(not item.completed)


class VotingActionItems(RemoTestCase):
def test_vote_action_item(self):
Expand Down
52 changes: 22 additions & 30 deletions remo/remozilla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get_action_items(self):
return []

action_items = []
names = [
actions = [
(ADD_RECEIPTS_ACTION, 'waiting_receipts', ActionItem.NORMAL),
(ADD_REPORT_ACTION, 'waiting_report', ActionItem.NORMAL),
(ADD_PHOTOS_ACTION, 'waiting_photos', ActionItem.NORMAL),
Expand All @@ -87,7 +87,7 @@ def get_action_items(self):
'council_member_assigned', ActionItem.BLOCKER)
]

for action_name, attr, priority in names:
for action_name, attr, priority in actions:
if getattr(self, attr, None):
action_item = Item(action_name, self.assigned_to,
priority, None)
Expand Down Expand Up @@ -115,39 +115,31 @@ def get_action_items(self):
return action_items

def save(self, *args, **kwargs):
# Avoid circular dependency
from remo.base.helpers import user_is_rep

# Update action items
action_model = ContentType.objects.get_for_model(self)
if self.pk:
names = [ADD_RECEIPTS_ACTION, ADD_REPORT_ACTION,
ADD_PHOTOS_ACTION, ADD_REPORTS_PHOTOS_ACTION,
REVIEW_BUDGET_REQUEST_ACTION]

current_bug = Bug.objects.get(id=self.pk)
action_items = ActionItem.objects.filter(content_type=action_model,
object_id=self.pk)

if current_bug.assigned_to != self.assigned_to:
items = action_items.filter(name__in=names)
items.update(user=self.assigned_to)

try:
current_mentor = current_bug.assigned_to
new_mentor = self.assigned_to
except AttributeError:
current_mentor = None
new_mentor = None

if current_mentor != new_mentor:
action_name = WAITING_MENTOR_VALIDATION_ACTION
items = action_items.filter(name=action_name)
items.update(user=new_mentor)
if (not self.assigned_to or not user_is_rep(self.assigned_to) or
self.status == 'RESOLVED'):
items = ActionItem.objects.filter(content_type=action_model,
object_id=self.pk)
items.update(resolved=True)
else:
actions = [ADD_RECEIPTS_ACTION, ADD_REPORT_ACTION,
ADD_PHOTOS_ACTION, ADD_REPORTS_PHOTOS_ACTION,
REVIEW_BUDGET_REQUEST_ACTION]

super(Bug, self).save(*args, **kwargs)
current_bug = Bug.objects.get(id=self.pk)
action_items = ActionItem.objects.filter(
content_type=action_model, object_id=self.pk)

if current_bug.assigned_to != self.assigned_to:
items = action_items.filter(name__in=actions)
items.update(user=self.assigned_to)

if self.status == 'RESOLVED':
items = ActionItem.objects.filter(content_type=action_model,
object_id=self.pk)
items.update(resolved=True)
super(Bug, self).save(*args, **kwargs)

class Meta:
ordering = ['-bug_last_change_time']
Expand Down

0 comments on commit ccff645

Please sign in to comment.