Exemplo n.º 1
0
def convert_approval_comment(issue, comment, mar, services, granted_perms):
    perms = permissions.UpdateIssuePermissions(mar.perms,
                                               mar.project,
                                               issue,
                                               mar.auth.effective_ids,
                                               granted_perms=granted_perms)
    commenter = services.user.GetUser(mar.cnxn, comment.user_id)
    can_delete = permissions.CanDeleteComment(comment, commenter,
                                              mar.auth.user_id, perms)

    return api_pb2_v1.ApprovalCommentWrapper(
        attachments=[convert_attachment(a) for a in comment.attachments],
        author=convert_person(comment.user_id,
                              mar.cnxn,
                              services,
                              trap_exception=True),
        canDelete=can_delete,
        content=comment.content,
        deletedBy=convert_person(comment.deleted_by,
                                 mar.cnxn,
                                 services,
                                 trap_exception=True),
        id=comment.sequence,
        published=datetime.datetime.fromtimestamp(comment.timestamp),
        approvalUpdates=convert_approval_amendments(comment.amendments, mar,
                                                    services),
        kind='monorail#approvalComment',
        is_description=comment.is_description)
Exemplo n.º 2
0
def ConvertComment(issue, comment, config, users_by_id, comment_reporters,
                   description_nums, user_id, perms):
    """Convert a protorpc IssueComment to a protoc Comment."""
    commenter = users_by_id[comment.user_id]

    can_delete = permissions.CanDeleteComment(comment, commenter, user_id,
                                              perms)
    can_flag, is_flagged = permissions.CanFlagComment(comment, commenter,
                                                      comment_reporters,
                                                      user_id, perms)
    can_view = permissions.CanViewComment(comment, commenter, user_id, perms)
    can_view_inbound_message = permissions.CanViewInboundMessage(
        comment, user_id, perms)

    is_deleted = bool(comment.deleted_by or is_flagged or commenter.banned)

    result = issue_objects_pb2.Comment(project_name=issue.project_name,
                                       local_id=issue.local_id,
                                       sequence_num=comment.sequence,
                                       is_deleted=is_deleted,
                                       can_delete=can_delete,
                                       is_spam=is_flagged,
                                       can_flag=can_flag,
                                       timestamp=comment.timestamp)

    if can_view:
        result.commenter.CopyFrom(
            ConvertUserRef(comment.user_id, None, users_by_id))
        result.content = comment.content
        if comment.inbound_message and can_view_inbound_message:
            result.inbound_message = comment.inbound_message
        result.amendments.extend([
            ConvertAmendment(amend, users_by_id)
            for amend in comment.amendments
        ])
        result.attachments.extend([
            ConvertAttachment(attach, issue.project_name)
            for attach in comment.attachments
        ])

    if comment.id in description_nums:
        result.description_num = description_nums[comment.id]

    fd = tracker_bizobj.FindFieldDefByID(comment.approval_id, config)
    if fd:
        result.approval_ref.field_name = fd.field_name

    return result
Exemplo n.º 3
0
    def __init__(self,
                 project_name,
                 comment_pb,
                 users_by_id,
                 autolink,
                 all_referenced_artifacts,
                 mr,
                 issue,
                 effective_ids=None):
        """Get IssueComment PB and make its fields available as attrs.

    Args:
      project_name: Name of the project this issue belongs to.
      comment_pb: Comment protocol buffer.
      users_by_id: dict mapping user_ids to UserViews, including
          the user that entered the comment, and any changed participants.
      autolink: utility object for automatically linking to other
        issues, git revisions, etc.
      all_referenced_artifacts: opaque object with details of referenced
        artifacts that is needed by autolink.
      mr: common information parsed from the HTTP request.
      issue: Issue PB for the issue that this comment is part of.
      effective_ids: optional set of int user IDs for the comment author.
    """
        super(IssueCommentView, self).__init__(comment_pb)

        self.id = comment_pb.id
        self.creator = users_by_id[comment_pb.user_id]

        # TODO(jrobbins): this should be based on the issue project, not the
        # request project for non-project views and cross-project.
        if mr.project:
            self.creator_role = framework_helpers.GetRoleName(
                effective_ids or {self.creator.user_id}, mr.project)
        else:
            self.creator_role = None

        time_tuple = time.localtime(comment_pb.timestamp)
        self.date_string = timestr.FormatAbsoluteDate(
            comment_pb.timestamp, old_format=timestr.MONTH_DAY_YEAR_FMT)
        self.date_relative = timestr.FormatRelativeDate(comment_pb.timestamp)
        self.date_tooltip = time.asctime(time_tuple)
        self.date_yyyymmdd = timestr.FormatAbsoluteDate(
            comment_pb.timestamp,
            recent_format=timestr.MONTH_DAY_YEAR_FMT,
            old_format=timestr.MONTH_DAY_YEAR_FMT)
        self.text_runs = _ParseTextRuns(comment_pb.content)
        if autolink and not comment_pb.deleted_by:
            self.text_runs = autolink.MarkupAutolinks(
                mr, self.text_runs, all_referenced_artifacts)

        self.attachments = [
            AttachmentView(attachment, project_name)
            for attachment in comment_pb.attachments
        ]
        self.amendments = sorted(
            [
                AmendmentView(amendment, users_by_id, mr.project_name)
                for amendment in comment_pb.amendments
            ],
            key=lambda amendment: amendment.field_name.lower())
        # Treat comments from banned users as being deleted.
        self.is_deleted = (comment_pb.deleted_by
                           or (self.creator and self.creator.banned))
        self.can_delete = False

        # TODO(jrobbins): pass through config to get granted permissions.
        perms = permissions.UpdateIssuePermissions(mr.perms, mr.project, issue,
                                                   mr.auth.effective_ids)
        if mr.auth.user_id and mr.project:
            self.can_delete = permissions.CanDeleteComment(
                comment_pb, self.creator, mr.auth.user_id, perms)

        self.visible = permissions.CanViewComment(comment_pb, self.creator,
                                                  mr.auth.user_id, perms)