def _MakePromises(self):
        config_dict = self.services.config.GetProjectConfigs(
            self.mr.cnxn, self.query_project_ids)
        self.harmonized_config = tracker_bizobj.HarmonizeConfigs(
            list(config_dict.values()))

        self.canned_query = savedqueries_helpers.SavedQueryIDToCond(
            self.mr.cnxn, self.services.features, self.mr.can)

        self.canned_query, warnings = searchpipeline.ReplaceKeywordsWithUserIDs(
            self.me_user_ids, self.canned_query)
        self.mr.warnings.extend(warnings)
        self.user_query, warnings = searchpipeline.ReplaceKeywordsWithUserIDs(
            self.me_user_ids, self.mr.query)
        self.mr.warnings.extend(warnings)
        logging.debug('Searching query: %s %s', self.canned_query,
                      self.user_query)

        slice_term = ('Issue.shard = %s', [self.mr.shard_id])

        sd = sorting.ComputeSortDirectives(self.harmonized_config,
                                           self.mr.group_by_spec,
                                           self.mr.sort_spec)

        self.result_iids_promise = framework_helpers.Promise(
            _GetQueryResultIIDs, self.mr.cnxn, self.services,
            self.canned_query, self.user_query, self.query_project_ids,
            self.harmonized_config, sd, slice_term, self.mr.shard_id,
            self.mr.invalidation_timestep)
  def testHarmonizeConfigs(self):
    c1 = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
    harmonized = tracker_bizobj.HarmonizeConfigs([c1])
    self.assertListEqual(
        [stat.status for stat in c1.well_known_statuses],
        [stat.status for stat in harmonized.well_known_statuses])
    self.assertListEqual(
        [lab.label for lab in c1.well_known_labels],
        [lab.label for lab in harmonized.well_known_labels])
    self.assertEqual('', harmonized.default_sort_spec)

    c2 = tracker_bizobj.MakeDefaultProjectIssueConfig(678)
    tracker_bizobj.SetConfigStatuses(c2, [
        ('Unconfirmed', '', True, False),
        ('New', '', True, True),
        ('Accepted', '', True, False),
        ('Begun', '', True, False),
        ('Fixed', '', False, False),
        ('Obsolete', '', False, False)])
    tracker_bizobj.SetConfigLabels(c2, [
        ('Pri-0', '', False),
        ('Priority-High', '', True),
        ('Pri-1', '', False),
        ('Priority-Medium', '', True),
        ('Pri-2', '', False),
        ('Priority-Low', '', True),
        ('Pri-3', '', False),
        ('Pri-4', '', False)])
    c2.default_sort_spec = 'Pri -status'

    harmonized = tracker_bizobj.HarmonizeConfigs([c1, c2])
    result_statuses = [stat.status
                       for stat in harmonized.well_known_statuses]
    result_labels = [lab.label
                     for lab in harmonized.well_known_labels]
    self.assertListEqual(
        ['Unconfirmed', 'New', 'Accepted', 'Begun', 'Started', 'Fixed',
         'Obsolete', 'Verified', 'Invalid', 'Duplicate', 'WontFix', 'Done'],
        result_statuses)
    self.assertListEqual(
        ['Pri-0', 'Type-Defect', 'Type-Enhancement', 'Type-Task',
         'Type-Other', 'Priority-Critical', 'Priority-High',
         'Pri-1', 'Priority-Medium', 'Pri-2', 'Priority-Low', 'Pri-3',
         'Pri-4'],
        result_labels[:result_labels.index('OpSys-All')])
    self.assertEqual('Pri -status', harmonized.default_sort_spec.strip())
Exemple #3
0
    def __init__(self, mr, services, prof, default_results_per_page):
        self.mr = mr
        self.services = services
        self.profiler = prof
        self.default_results_per_page = default_results_per_page
        self.grid_mode = (mr.mode == 'grid')
        self.grid_limited = False
        self.pagination = None
        self.num_skipped_at_start = 0
        self.total_count = 0

        self.query_projects = []
        if mr.query_project_names:
            consider_projects = services.project.GetProjectsByName(
                mr.cnxn, mr.query_project_names).values()
            self.query_projects = [
                p for p in consider_projects if permissions.UserCanViewProject(
                    mr.auth.user_pb, mr.auth.effective_ids, p)
            ]
        if mr.project_name:
            self.query_projects.append(mr.project)
        self.query_project_ids = sorted(
            [p.project_id for p in self.query_projects])
        self.query_project_names = sorted(
            [p.project_name for p in self.query_projects])

        config_dict = self.services.config.GetProjectConfigs(
            mr.cnxn, self.query_project_ids)
        self.harmonized_config = tracker_bizobj.HarmonizeConfigs(
            config_dict.values())

        # The following fields are filled in as the pipeline progresses.
        # The value None means that we still need to compute that value.
        # A shard_key is a tuple (shard_id, subquery).
        self.users_by_id = {}
        self.nonviewable_iids = {}  # {shard_id: set(iid)}
        self.unfiltered_iids = {
        }  # {shard_key: [iid, ...]} needing perm checks.
        self.filtered_iids = {
        }  # {shard_key: [iid, ...]} already perm checked.
        self.search_limit_reached = {}  # {shard_key: [bool, ...]}.
        self.allowed_iids = []  # Matching iids that user is permitted to view.
        self.allowed_results = None  # results that the user is permitted to view.
        self.visible_results = None  # allowed_results on current pagination page.
        self.error_responses = set()

        error_msg = query2ast.CheckSyntax(self.mr.query,
                                          self.harmonized_config,
                                          warnings=self.mr.warnings)
        if error_msg:
            self.mr.errors.query = error_msg
Exemple #4
0
    def GetGridViewData(self, mr):
        """EZT template values to render a Table View of issues.

    Args:
      mr: commonly used info parsed from the request.

    Returns:
      Dictionary of page data for rendering of the Table View.
    """
        mr.ComputeColSpec(mr.hotlist)
        starred_iid_set = set(
            self.services.issue_star.LookupStarredItemIDs(
                mr.cnxn, mr.auth.user_id))
        issues_list = self.services.issue.GetIssues(
            mr.cnxn,
            [hotlist_issue.issue_id for hotlist_issue in mr.hotlist.items])
        allowed_issues = hotlist_helpers.FilterIssues(mr, issues_list,
                                                      self.services)
        issue_and_hotlist_users = tracker_bizobj.UsersInvolvedInIssues(
            allowed_issues
            or []).union(features_bizobj.UsersInvolvedInHotlists([mr.hotlist]))
        users_by_id = framework_views.MakeAllUserViews(
            mr.cnxn, self.services.user, issue_and_hotlist_users)
        hotlist_issues_project_ids = hotlist_helpers.GetAllProjectsOfIssues(
            [issue for issue in issues_list])
        config_list = hotlist_helpers.GetAllConfigsOfProjects(
            mr.cnxn, hotlist_issues_project_ids, self.services)
        harmonized_config = tracker_bizobj.HarmonizeConfigs(config_list)
        limit = settings.max_issues_in_grid
        grid_limited = len(allowed_issues) > limit
        lower_cols = mr.col_spec.lower().split()
        grid_x = (mr.x or harmonized_config.default_x_attr or '--').lower()
        grid_y = (mr.y or harmonized_config.default_y_attr or '--').lower()
        lower_cols.append(grid_x)
        lower_cols.append(grid_y)
        related_iids = set()
        for issue in allowed_issues:
            if 'blockedon' in lower_cols:
                related_iids.update(issue.blocked_on_iids)
            if 'blocking' in lower_cols:
                related_iids.update(issue.blocking_iids)
            if 'mergedinto' in lower_cols:
                related_iids.add(issue.merged_into)
        related_issues_list = self.services.issue.GetIssues(
            mr.cnxn, list(related_iids))
        related_issues = {
            issue.issue_id: issue
            for issue in related_issues_list
        }

        hotlist_context_dict = {
            hotlist_issue.issue_id: {
                'adder_id': hotlist_issue.adder_id,
                'date_added':
                timestr.FormatRelativeDate(hotlist_issue.date_added),
                'note': hotlist_issue.note
            }
            for hotlist_issue in mr.hotlist.items
        }

        grid_view_data = grid_view_helpers.GetGridViewData(
            mr,
            allowed_issues,
            harmonized_config,
            users_by_id,
            starred_iid_set,
            grid_limited,
            related_issues,
            hotlist_context_dict=hotlist_context_dict)

        url_params = [(name, mr.GetParam(name))
                      for name in framework_helpers.RECOGNIZED_PARAMS]
        # We are passing in None for the project_name in ArtifactPagination
        # because we are not operating under any project.
        grid_view_data.update({
            'pagination':
            paginate.ArtifactPagination(
                allowed_issues,
                mr.GetPositiveIntParam(
                    'num', features_constants.DEFAULT_RESULTS_PER_PAGE),
                mr.GetPositiveIntParam('start'),
                None,
                urls.HOTLIST_ISSUES,
                total_count=len(allowed_issues),
                url_params=url_params)
        })

        return grid_view_data
 def testHarmonizeConfigs_Empty(self):
   harmonized = tracker_bizobj.HarmonizeConfigs([])
   self.CheckDefaultConfig(harmonized)
Exemple #6
0
def CreateHotlistTableData(mr, hotlist_issues, profiler, services):
    """Creates the table data for the hotlistissues table."""
    with profiler.Phase('getting stars'):
        starred_iid_set = set(
            services.issue_star.LookupStarredItemIDs(mr.cnxn, mr.auth.user_id))

    with profiler.Phase('Computing col_spec'):
        mr.ComputeColSpec(mr.hotlist)

    issues_list = services.issue.GetIssues(
        mr.cnxn, [hotlist_issue.issue_id for hotlist_issue in hotlist_issues])
    with profiler.Phase('Getting config'):
        hotlist_issues_project_ids = GetAllProjectsOfIssues(
            [issue for issue in issues_list])
        is_cross_project = len(hotlist_issues_project_ids) > 1
        config_list = GetAllConfigsOfProjects(mr.cnxn,
                                              hotlist_issues_project_ids,
                                              services)
        harmonized_config = tracker_bizobj.HarmonizeConfigs(config_list)

    (sorted_issues, hotlist_issues_context,
     issues_users_by_id) = GetSortedHotlistIssues(mr, hotlist_issues,
                                                  issues_list,
                                                  harmonized_config, profiler,
                                                  services)

    with profiler.Phase("getting related issues"):
        related_iids = set()
        results_needing_related = sorted_issues
        lower_cols = mr.col_spec.lower().split()
        for issue in results_needing_related:
            if 'blockedon' in lower_cols:
                related_iids.update(issue.blocked_on_iids)
            if 'blocking' in lower_cols:
                related_iids.update(issue.blocking_iids)
            if 'mergedinto' in lower_cols:
                related_iids.add(issue.merged_into)
        related_issues_list = services.issue.GetIssues(mr.cnxn,
                                                       list(related_iids))
        related_issues = {
            issue.issue_id: issue
            for issue in related_issues_list
        }

    with profiler.Phase('building table'):
        context_for_all_issues = {
            issue.issue_id: hotlist_issues_context[issue.issue_id]
            for issue in sorted_issues
        }

        column_values = table_view_helpers.ExtractUniqueValues(
            mr.col_spec.lower().split(),
            sorted_issues,
            issues_users_by_id,
            harmonized_config,
            related_issues,
            hotlist_context_dict=context_for_all_issues)
        unshown_columns = table_view_helpers.ComputeUnshownColumns(
            sorted_issues, mr.col_spec.split(), harmonized_config,
            features_constants.OTHER_BUILT_IN_COLS)
        pagination = paginate.ArtifactPagination(
            mr, sorted_issues, mr.num,
            GetURLOfHotlist(mr.cnxn, mr.hotlist, services.user),
            len(sorted_issues))

        sort_spec = '%s %s %s' % (mr.group_by_spec, mr.sort_spec,
                                  harmonized_config.default_sort_spec)

        table_data = _MakeTableData(pagination.visible_results,
                                    starred_iid_set,
                                    mr.col_spec.lower().split(),
                                    mr.group_by_spec.lower().split(),
                                    issues_users_by_id,
                                    tablecell.CELL_FACTORIES, related_issues,
                                    harmonized_config, context_for_all_issues,
                                    mr.hotlist_id, sort_spec)

    table_related_dict = {
        'column_values': column_values,
        'unshown_columns': unshown_columns,
        'pagination': pagination,
        'is_cross_project': is_cross_project
    }
    return table_data, table_related_dict
Exemple #7
0
def CreateHotlistTableData(mr, hotlist_issues, services):
    """Creates the table data for the hotlistissues table."""
    with mr.profiler.Phase('getting stars'):
        starred_iid_set = set(
            services.issue_star.LookupStarredItemIDs(mr.cnxn, mr.auth.user_id))

    with mr.profiler.Phase('Computing col_spec'):
        mr.ComputeColSpec(mr.hotlist)

    issues_list = services.issue.GetIssues(
        mr.cnxn, [hotlist_issue.issue_id for hotlist_issue in hotlist_issues])
    with mr.profiler.Phase('Getting config'):
        hotlist_issues_project_ids = GetAllProjectsOfIssues(
            [issue for issue in issues_list])
        is_cross_project = len(hotlist_issues_project_ids) > 1
        config_list = GetAllConfigsOfProjects(mr.cnxn,
                                              hotlist_issues_project_ids,
                                              services)
        harmonized_config = tracker_bizobj.HarmonizeConfigs(config_list)

    (sorted_issues, hotlist_issues_context,
     issues_users_by_id) = GetSortedHotlistIssues(mr, hotlist_issues,
                                                  issues_list,
                                                  harmonized_config, services)

    with mr.profiler.Phase("getting related issues"):
        related_iids = set()
        results_needing_related = sorted_issues
        lower_cols = mr.col_spec.lower().split()
        for issue in results_needing_related:
            if 'blockedon' in lower_cols:
                related_iids.update(issue.blocked_on_iids)
            if 'blocking' in lower_cols:
                related_iids.update(issue.blocking_iids)
            if 'mergedinto' in lower_cols:
                related_iids.add(issue.merged_into)
        related_issues_list = services.issue.GetIssues(mr.cnxn,
                                                       list(related_iids))
        related_issues = {
            issue.issue_id: issue
            for issue in related_issues_list
        }

    with mr.profiler.Phase('filtering unviewable issues'):
        viewable_iids_set = {
            issue.issue_id
            for issue in tracker_helpers.GetAllowedIssues(
                mr, [related_issues.values()], services)[0]
        }

    with mr.profiler.Phase('building table'):
        context_for_all_issues = {
            issue.issue_id: hotlist_issues_context[issue.issue_id]
            for issue in sorted_issues
        }

        column_values = table_view_helpers.ExtractUniqueValues(
            mr.col_spec.lower().split(),
            sorted_issues,
            issues_users_by_id,
            harmonized_config,
            related_issues,
            hotlist_context_dict=context_for_all_issues)
        unshown_columns = table_view_helpers.ComputeUnshownColumns(
            sorted_issues, mr.col_spec.split(), harmonized_config,
            features_constants.OTHER_BUILT_IN_COLS)
        url_params = [(name, mr.GetParam(name))
                      for name in framework_helpers.RECOGNIZED_PARAMS]
        # We are passing in None for the project_name because we are not operating
        # under any project.
        pagination = paginate.ArtifactPagination(
            sorted_issues,
            mr.num,
            mr.GetPositiveIntParam('start'),
            None,
            GetURLOfHotlist(mr.cnxn, mr.hotlist, services.user),
            total_count=len(sorted_issues),
            url_params=url_params)

        sort_spec = '%s %s %s' % (mr.group_by_spec, mr.sort_spec,
                                  harmonized_config.default_sort_spec)

        table_data = _MakeTableData(
            pagination.visible_results, starred_iid_set,
            mr.col_spec.lower().split(),
            mr.group_by_spec.lower().split(), issues_users_by_id,
            tablecell.CELL_FACTORIES, related_issues, viewable_iids_set,
            harmonized_config, context_for_all_issues, mr.hotlist_id,
            sort_spec)

    table_related_dict = {
        'column_values': column_values,
        'unshown_columns': unshown_columns,
        'pagination': pagination,
        'is_cross_project': is_cross_project
    }
    return table_data, table_related_dict