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 IssueSnapshot(self, mc, request): """Fetch IssueSnapshot counts for charting.""" warnings = [] if not request.timestamp: raise exceptions.InputException('Param `timestamp` required.') if not request.project_name: raise exceptions.InputException('Param `project_name` required.') if request.group_by == 'label' and not request.label_prefix: raise exceptions.InputException('Param `label_prefix` required.') if request.canned_query: canned_query = savedqueries_helpers.SavedQueryIDToCond( mc.cnxn, self.services.features, request.canned_query) # TODO(jrobbins): support linked accounts me_user_ids. canned_query, warnings = searchpipeline.ReplaceKeywordsWithUserIDs( [mc.auth.user_id], canned_query) else: canned_query = None if request.query: query, warnings = searchpipeline.ReplaceKeywordsWithUserIDs( [mc.auth.user_id], request.query) else: query = None with work_env.WorkEnv(mc, self.services) as we: project = we.GetProjectByName(request.project_name) results, unsupported_fields, limit_reached = we.SnapshotCountsQuery( project, request.timestamp, request.group_by, label_prefix=request.label_prefix, query=query, canned_query=canned_query) if request.group_by == 'owner': # Map user ids to emails. snapshot_counts = [ issues_pb2.IssueSnapshotCount( dimension=self.services.user.GetUser(mc.cnxn, key).email, count=result) for key, result in results.iteritems() ] else: snapshot_counts = [ issues_pb2.IssueSnapshotCount(dimension=key, count=result) for key, result in results.items() ] response = issues_pb2.IssueSnapshotResponse() response.snapshot_count.extend(snapshot_counts) response.unsupported_field.extend(unsupported_fields) response.unsupported_field.extend(warnings) response.search_limit_reached = limit_reached return response
def EvaluateSubscriptions( cnxn, issue, users_to_queries, services, config): """Determine subscribers who have subs that match the given issue.""" # Note: unlike filter rule, subscriptions see explicit & derived values. lower_labels = [lab.lower() for lab in tracker_bizobj.GetLabels(issue)] label_set = set(lower_labels) subscribers_to_notify = [] for uid, saved_queries in users_to_queries.items(): for sq in saved_queries: if sq.subscription_mode != 'immediate': continue if issue.project_id not in sq.executes_in_project_ids: continue cond = savedqueries_helpers.SavedQueryToCond(sq) # TODO(jrobbins): Support linked accounts me_user_ids. cond, _warnings = searchpipeline.ReplaceKeywordsWithUserIDs([uid], cond) cond_ast = query2ast.ParseUserQuery( cond, '', query2ast.BUILTIN_ISSUE_FIELDS, config) if filterrules_helpers.EvalPredicate( cnxn, services, cond_ast, issue, label_set, config, tracker_bizobj.GetOwnerId(issue), tracker_bizobj.GetCcIds(issue), tracker_bizobj.GetStatus(issue)): subscribers_to_notify.append(uid) break # Don't bother looking at the user's other saved quereies. return subscribers_to_notify
def testReplaceKeywordsWithUserIDs_Me(self): """Terms like owner:me are replaced with owner:USERID.""" actual, warnings = searchpipeline.ReplaceKeywordsWithUserIDs( [111], 'owner:me') self.assertEqual('owner:111', actual) self.assertEqual([], warnings) actual, warnings = searchpipeline.ReplaceKeywordsWithUserIDs( [111], 'Pri=1 cc:me M=61') self.assertEqual('Pri=1 cc:111 M=61', actual) self.assertEqual([], warnings) actual, warnings = searchpipeline.ReplaceKeywordsWithUserIDs( [], 'Pri=1 reporter:me M=61') self.assertEqual('Pri=1 M=61', actual) self.assertEqual( ['"me" keyword ignored because you are not signed in.'], warnings)
def testReplaceKeywordsWithUserIDs_IsStarred(self): """The term is:starred is replaced with starredby:USERID.""" actual, warnings = searchpipeline.ReplaceKeywordsWithUserIDs( [111], 'is:starred') self.assertEqual('starredby:111', actual) self.assertEqual([], warnings) actual, warnings = searchpipeline.ReplaceKeywordsWithUserIDs( [111], 'Pri=1 is:starred M=61') self.assertEqual('Pri=1 starredby:111 M=61', actual) self.assertEqual([], warnings) actual, warnings = searchpipeline.ReplaceKeywordsWithUserIDs( [], 'Pri=1 is:starred M=61') self.assertEqual('Pri=1 M=61', actual) self.assertEqual( ['"is:starred" ignored because you are not signed in.'], warnings)
def ParsePredicateASTs(rules, config, me_user_ids): """Parse the given rules in QueryAST PBs.""" predicates = [rule.predicate for rule in rules] if me_user_ids: predicates = [ searchpipeline.ReplaceKeywordsWithUserIDs(me_user_ids, pred)[0] for pred in predicates] predicate_asts = [ query2ast.ParseUserQuery(pred, '', query2ast.BUILTIN_ISSUE_FIELDS, config) for pred in predicates] return predicate_asts
def testReplaceKeywordsWithUserIDs_IsStarred_linked(self): """is:starred is replaced by starredby:uid1,uid2 for linked accounts.""" actual, warnings = searchpipeline.ReplaceKeywordsWithUserIDs( [111, 222], 'is:starred') self.assertEqual('starredby:111,222', actual) self.assertEqual([], warnings)
def testReplaceKeywordsWithUserIDs_Me_LinkedAccounts(self): """owner:me is replaced with owner:uid,uid for each linked account.""" actual, warnings = searchpipeline.ReplaceKeywordsWithUserIDs( [111, 222], 'owner:me') self.assertEqual('owner:111,222', actual) self.assertEqual([], warnings)