def ConvertAmendment(amendment, users_by_id): """Convert a protorpc Amendment to a protoc Amendment.""" field_name = tracker_bizobj.GetAmendmentFieldName(amendment) new_value = tracker_bizobj.AmendmentString(amendment, users_by_id) result = issue_objects_pb2.Amendment(field_name=field_name, new_or_delta_value=new_value, old_value=amendment.oldvalue) return result
def __init__(self, amendment, users_by_id, project_name): """Get the info from the PB and put it into easily accessible attrs. Args: amendment: Amendment part of an IssueComment protocol buffer. users_by_id: dict mapping user_ids to UserViews. project_name: Name of the project the issue/comment/amendment is in. """ # TODO(jrobbins): take field-level restrictions into account. # Including the case where user is not allowed to see any amendments. self.field_name = tracker_bizobj.GetAmendmentFieldName(amendment) self.newvalue = tracker_bizobj.AmendmentString(amendment, users_by_id) self.values = tracker_bizobj.AmendmentLinks(amendment, users_by_id, project_name)
def SendIssueBulkChangeNotification(issue_ids, hostport, old_owner_ids, comment_text, commenter_id, amendments, send_email, users_by_id): """Create a task to follow up on an issue blocked_on change.""" amendment_lines = [] for up in amendments: line = ' %s: %s' % (tracker_bizobj.GetAmendmentFieldName(up), tracker_bizobj.AmendmentString(up, users_by_id)) if line not in amendment_lines: amendment_lines.append(line) params = dict(issue_ids=','.join(str(iid) for iid in issue_ids), commenter_id=commenter_id, hostport=hostport, send_email=int(send_email), old_owner_ids=','.join(str(uid) for uid in old_owner_ids), comment_text=comment_text, amendments='\n'.join(amendment_lines)) logging.info('adding bulk task with params %r', params) taskqueue.add(url=urls.NOTIFY_BULK_CHANGE_TASK + '.do', params=params)
def testGetAmendmentFieldName_Builtin(self): amendment = tracker_bizobj.MakeAmendment( tracker_pb2.FieldID.SUMMARY, 'It broke', [], []) self.assertEqual('Summary', tracker_bizobj.GetAmendmentFieldName(amendment))
def testGetAmendmentFieldName_Custom(self): amendment = tracker_bizobj.MakeAmendment( tracker_pb2.FieldID.CUSTOM, None, [222L, 333L], [111L], 'Rabbit') self.assertEqual('Rabbit', tracker_bizobj.GetAmendmentFieldName(amendment))