Exemplo n.º 1
0
    def CreateHotlist(self,
                      cnxn,
                      name,
                      summary,
                      description,
                      owner_ids,
                      editor_ids,
                      issue_ids=None,
                      is_private=None,
                      default_col_spec=None,
                      ts=None):
        """Create and store a Hotlist with the given attributes.

    Args:
      cnxn: connection to SQL database.
      name: a valid hotlist name.
      summary: one-line explanation of the hotlist.
      description: one-page explanation of the hotlist.
      owner_ids: a list of user IDs for the hotlist owners.
      editor_ids: a list of user IDs for the hotlist editors.
      issue_ids: a list of issue IDs for the hotlist issues.
      is_private: True if the hotlist can only be viewed by owners and editors.
      default_col_spec: the default columns that show in list view.
      ts: a timestamp for when this hotlist was created.

    Returns:
      The int id of the new hotlist.

    Raises:
      HotlistAlreadyExists: if any of the owners already own a hotlist with
        the same name.
      UnownedHotlistException: if owner_ids is empty.
    """
        assert framework_bizobj.IsValidHotlistName(name)
        if self.LookupHotlistIDs(cnxn, [name], owner_ids):
            raise HotlistAlreadyExists()

        if not owner_ids:  # Should never happen.
            logging.error('Attempt to create unowned Hotlist: name:%r', name)
            raise UnownedHotlistException()
        hotlist_item_fields = [(issue_id, rank * 100, owner_ids[0], ts, '')
                               for rank, issue_id in enumerate(issue_ids or [])
                               ]
        if default_col_spec is None:
            default_col_spec = features_constants.DEFAULT_COL_SPEC
        hotlist = features_pb2.MakeHotlist(
            name,
            hotlist_item_fields=hotlist_item_fields,
            summary=summary,
            description=description,
            is_private=is_private,
            owner_ids=owner_ids,
            editor_ids=editor_ids,
            default_col_spec=default_col_spec)
        hotlist.hotlist_id = self._InsertHotlist(cnxn, hotlist)
        return hotlist
Exemplo n.º 2
0
    def _DeserializeHotlists(self, hotlist_rows, issue_rows, role_rows):
        """Convert database rows into a dictionary of Hotlist PB keyed by ID.

    Args:
      hotlist_rows: a list of hotlist rows from HOTLIST_TABLE_NAME.
      issue_rows: a list of issue rows from HOTLIST2ISSUE_TABLE_NAME,
        ordered by rank DESC, issue_id.
      role_rows: a list of role rows from HOTLIST2USER_TABLE_NAME

    Returns:
      a dict mapping hotlist_id to hotlist PB"""
        hotlist_dict = {}

        for hotlist_row in hotlist_rows:
            (hotlist_id, hotlist_name, summary, description, is_private,
             default_col_spec) = hotlist_row
            hotlist = features_pb2.MakeHotlist(
                hotlist_name,
                hotlist_id=hotlist_id,
                summary=summary,
                description=description,
                is_private=bool(is_private),
                default_col_spec=default_col_spec)
            hotlist_dict[hotlist_id] = hotlist

        for (hotlist_id, issue_id, rank, adder_id, added, note) in issue_rows:
            hotlist = hotlist_dict.get(hotlist_id)
            if hotlist:
                hotlist.items.append(
                    features_pb2.MakeHotlistItem(issue_id=issue_id,
                                                 rank=rank,
                                                 adder_id=adder_id,
                                                 date_added=added,
                                                 note=note))
            else:
                logging.warn('hotlist %d not found', hotlist_id)

        for (hotlist_id, user_id, role_name) in role_rows:
            hotlist = hotlist_dict.get(hotlist_id)
            if not hotlist:
                logging.warn('hotlist %d not found', hotlist_id)
            elif role_name == 'owner':
                hotlist.owner_ids.append(user_id)
            elif role_name == 'editor':
                hotlist.editor_ids.append(user_id)
            elif role_name == 'follower':
                hotlist.follower_ids.append(user_id)
            else:
                logging.info('unknown role name %s', role_name)

        return hotlist_dict
Exemplo n.º 3
0
 def testMakeHotlist_Everything(self):
     ts = 20011111111111
     hotlist = features_pb2.MakeHotlist('summer-issues',
                                        [(1000, 1, 444, ts, ''),
                                         (1001, 2, 333, ts, ''),
                                         (1009, None, None, ts, '')],
                                        description='desc')
     self.assertEqual('summer-issues', hotlist.name)
     self.assertEqual([
         features_pb2.MakeHotlistItem(
             1000, rank=1, adder_id=444, date_added=ts, note=''),
         features_pb2.MakeHotlistItem(
             1001, rank=2, adder_id=333, date_added=ts, note=''),
         features_pb2.MakeHotlistItem(1009, date_added=ts, note=''),
     ], hotlist.items)
     self.assertEqual('desc', hotlist.description)
Exemplo n.º 4
0
 def testMakeHotlist_Defaults(self):
     hotlist = features_pb2.MakeHotlist('summer-issues')
     self.assertEqual('summer-issues', hotlist.name)
     self.assertEqual([], hotlist.items)