Exemplo n.º 1
0
    def ListHotlistsByUser(self, mc, request):
        """Return the hotlists for the given user."""
        user_id = converters.IngestUserRef(mc.cnxn, request.user,
                                           self.services.user)

        with work_env.WorkEnv(mc, self.services) as we:
            mc.LookupLoggedInUserPerms(None)
            hotlists = we.ListHotlistsByUser(user_id)

        with mc.profiler.Phase('making user views'):
            users_involved = features_bizobj.UsersOwnersOfHotlists(hotlists)
            users_by_id = framework_views.MakeAllUserViews(
                mc.cnxn, self.services.user, users_involved)
            framework_views.RevealAllEmailsToMembers(mc.auth, None,
                                                     users_by_id)

        converted_hotlists = [
            converters.ConvertHotlist(hotlist, users_by_id)
            for hotlist in hotlists
        ]

        result = features_pb2.ListHotlistsByUserResponse(
            hotlists=converted_hotlists)

        return result
Exemplo n.º 2
0
    def PresubmitIssue(self, mc, request):
        """Provide the UI with warnings and suggestions."""
        project, issue, config = self._GetProjectIssueAndConfig(
            mc, request.issue_ref, issue_required=False)

        with mc.profiler.Phase('making user views'):
            try:
                proposed_owner_id = converters.IngestUserRef(
                    mc.cnxn, request.issue_delta.owner_ref, self.services.user)
            except exceptions.NoSuchUserException:
                proposed_owner_id = 0

            users_by_id = framework_views.MakeAllUserViews(
                mc.cnxn, self.services.user, [proposed_owner_id])
            proposed_owner_view = users_by_id[proposed_owner_id]

        with mc.profiler.Phase('Applying IssueDelta'):
            if issue:
                proposed_issue = copy.deepcopy(issue)
            else:
                proposed_issue = tracker_pb2.Issue(
                    owner_id=framework_constants.NO_USER_SPECIFIED,
                    project_id=config.project_id)
            issue_delta = converters.IngestIssueDelta(
                mc.cnxn,
                self.services,
                request.issue_delta,
                config,
                None,
                ignore_missing_objects=True)
            tracker_bizobj.ApplyIssueDelta(mc.cnxn, self.services.issue,
                                           proposed_issue, issue_delta, config)

        with mc.profiler.Phase('applying rules'):
            _, traces = filterrules_helpers.ApplyFilterRules(
                mc.cnxn, self.services, proposed_issue, config)
            logging.info('proposed_issue is now: %r', proposed_issue)
            logging.info('traces are: %r', traces)

        with mc.profiler.Phase('making derived user views'):
            derived_users_by_id = framework_views.MakeAllUserViews(
                mc.cnxn, self.services.user, [proposed_issue.derived_owner_id],
                proposed_issue.derived_cc_ids)
            framework_views.RevealAllEmailsToMembers(mc.auth, project,
                                                     derived_users_by_id)

        with mc.profiler.Phase('pair derived values with rule explanations'):
            (derived_labels, derived_owners, derived_ccs, warnings,
             errors) = (tracker_helpers.PairDerivedValuesWithRuleExplanations(
                 proposed_issue, traces, derived_users_by_id))

        result = issues_pb2.PresubmitIssueResponse(
            owner_availability=proposed_owner_view.avail_message_short,
            owner_availability_state=proposed_owner_view.avail_state,
            derived_labels=converters.ConvertValueAndWhyList(derived_labels),
            derived_owners=converters.ConvertValueAndWhyList(derived_owners),
            derived_ccs=converters.ConvertValueAndWhyList(derived_ccs),
            warnings=converters.ConvertValueAndWhyList(warnings),
            errors=converters.ConvertValueAndWhyList(errors))
        return result
Exemplo n.º 3
0
 def _SignedInOrSpecifiedUser(self, mc, request):
     """If request specifies a user, return it.  Otherwise signed-in user."""
     user_id = mc.auth.user_id
     if request.HasField('user_ref'):
         user_id = converters.IngestUserRef(mc.cnxn, request.user_ref,
                                            self.services.user)
     return user_id
Exemplo n.º 4
0
    def GetUserStarCount(self, mc, request):
        """Return the star count for a given user."""
        user_id = converters.IngestUserRef(mc.cnxn, request.user_ref,
                                           self.services.user)

        with work_env.WorkEnv(mc, self.services) as we:
            star_count = we.GetUserStarCount(user_id)

        result = users_pb2.GetUserStarCountResponse(star_count=star_count)
        return result
Exemplo n.º 5
0
    def StarUser(self, mc, request):
        """Star a given user."""
        user_id = converters.IngestUserRef(mc.cnxn, request.user_ref,
                                           self.services.user)

        with work_env.WorkEnv(mc, self.services) as we:
            we.StarUser(user_id, request.starred)
            star_count = we.GetUserStarCount(user_id)

        result = users_pb2.StarUserResponse(star_count=star_count)
        return result
Exemplo n.º 6
0
    def GetMemberships(self, mc, request):
        """Return the user groups for the given user visible to the requester."""
        user_id = converters.IngestUserRef(mc.cnxn, request.user_ref,
                                           self.services.user)

        with work_env.WorkEnv(mc, self.services) as we:
            group_ids = we.GetMemberships(user_id)

        with mc.profiler.Phase('converting to response objects'):
            groups_by_id = framework_views.MakeAllUserViews(
                mc.cnxn, self.services.user, group_ids)
            group_refs = converters.ConvertUserRefs(group_ids, [],
                                                    groups_by_id, True)

            return users_pb2.GetMembershipsResponse(group_refs=group_refs)
Exemplo n.º 7
0
    def ListActivities(self, mc, request):
        """Return issue activities by a specified user in a response proto."""
        converted_user = converters.IngestUserRef(mc.cnxn, request.user_ref,
                                                  self.services.user)
        user = self.services.user.GetUser(mc.cnxn, converted_user)
        comments = self.services.issue.GetIssueActivity(
            mc.cnxn, user_ids={request.user_ref.user_id})
        issues = self.services.issue.GetIssues(mc.cnxn,
                                               {c.issue_id
                                                for c in comments})
        project_dict = tracker_helpers.GetAllIssueProjects(
            mc.cnxn, issues, self.services.project)
        config_dict = self.services.config.GetProjectConfigs(
            mc.cnxn, list(project_dict.keys()))
        allowed_issues = tracker_helpers.FilterOutNonViewableIssues(
            mc.auth.effective_ids, user, project_dict, config_dict, issues)
        issue_dict = {issue.issue_id: issue for issue in allowed_issues}
        comments = [c for c in comments if c.issue_id in issue_dict]

        users_by_id = framework_views.MakeAllUserViews(
            mc.cnxn, self.services.user, [request.user_ref.user_id],
            tracker_bizobj.UsersInvolvedInCommentList(comments))
        for project in project_dict.values():
            framework_views.RevealAllEmailsToMembers(mc.auth, project,
                                                     users_by_id)

        issues_by_project = {}
        for issue in allowed_issues:
            issues_by_project.setdefault(issue.project_id, []).append(issue)

        # A dictionary {issue_id: perms} of the PermissionSet for the current user
        # on each of the issues.
        issue_perms_dict = {}
        # A dictionary {comment_id: [reporter_id]} of users who have reported the
        # comment as spam.
        comment_reporters = {}
        for project_id, project_issues in issues_by_project.items():
            mc.LookupLoggedInUserPerms(project_dict[project_id])
            issue_perms_dict.update({
                issue.issue_id: permissions.UpdateIssuePermissions(
                    mc.perms,
                    project_dict[issue.project_id],
                    issue,
                    mc.auth.effective_ids,
                    config=config_dict[issue.project_id])
                for issue in project_issues
            })

            with work_env.WorkEnv(mc, self.services) as we:
                project_issue_reporters = we.LookupIssuesFlaggers(
                    project_issues)
                for _, issue_comment_reporters in project_issue_reporters.values(
                ):
                    comment_reporters.update(issue_comment_reporters)

        with mc.profiler.Phase('converting to response objects'):
            converted_comments = []
            for c in comments:
                issue = issue_dict.get(c.issue_id)
                issue_perms = issue_perms_dict.get(c.issue_id)
                result = converters.ConvertComment(
                    issue, c, config_dict.get(issue.project_id), users_by_id,
                    comment_reporters.get(c.id, []),
                    {c.id: 1} if c.is_description else {}, mc.auth.user_id,
                    issue_perms)
                converted_comments.append(result)
            converted_issues = [
                issue_objects_pb2.IssueSummary(project_name=issue.project_name,
                                               local_id=issue.local_id,
                                               summary=issue.summary)
                for issue in allowed_issues
            ]
            response = issues_pb2.ListActivitiesResponse(
                comments=converted_comments, issue_summaries=converted_issues)

        return response