Example #1
0
def ComputeIssueEntryURL(mr, config):
  """Compute the URL to use for the "New issue" subtab.

  Args:
    mr: commonly used info parsed from the request.
    config: ProjectIssueConfig for the current project.

  Returns:
    A URL string to use.  It will be simply "entry" in the non-customized
    case. Otherewise it will be a fully qualified URL that includes some
    query string parameters.
  """
  if not config.custom_issue_entry_url:
    return '/p/%s/issues/entry' % (mr.project_name)

  base_url = config.custom_issue_entry_url
  sep = '&' if '?' in base_url else '?'
  token = xsrf.GenerateToken(
    mr.auth.user_id, '/p/%s%s%s' % (mr.project_name, urls.ISSUE_ENTRY, '.do'))
  role_name = framework_helpers.GetRoleName(mr.auth.effective_ids, mr.project)

  continue_url = urllib.quote(framework_helpers.FormatAbsoluteURL(
      mr, urls.ISSUE_ENTRY + '.do'))

  return '%s%stoken=%s&role=%s&continue=%s' % (
      base_url, sep, urllib.quote(token),
      urllib.quote(role_name or ''), continue_url)
Example #2
0
    def __init__(self,
                 logged_in_user_id,
                 member_id,
                 user_view,
                 project,
                 project_commitments,
                 effective_ids=None,
                 ac_exclusion=False,
                 no_expand=False,
                 is_group=False):
        """Initialize a MemberView with the given information.

    Args:
      logged_in_user_id: int user ID of the viewing user, or 0 for anon.
      member_id: int user ID of the project member being viewed.
      user_view: UserView object for this member.
      project: Project PB for the currently viewed project.
      project_commitments: ProjectCommitments PB for the currently viewed
          project, or None if commitments are not to be displayed.
      effective_ids: optional set of user IDs for this user, if supplied
          we show the highest role that they have via any group membership.
      ac_exclusion: True when this member should not be in autocomplete.
      no_expand: True for user groups that should not expand when generating
          autocomplete options.
      is_group: True if this user is actually a user group.
    """
        self.viewing_self = ezt.boolean(logged_in_user_id == member_id)

        self.user = user_view
        member_qs_param = user_view.user_id
        self.detail_url = '/p/%s%s?u=%s' % (
            project.project_name, urls.PEOPLE_DETAIL, member_qs_param)
        self.role = framework_helpers.GetRoleName(effective_ids or {member_id},
                                                  project)
        self.extra_perms = permissions.GetExtraPerms(project, member_id)
        self.notes = None
        if project_commitments is not None:
            for commitment in project_commitments.commitments:
                if commitment.member_id == member_id:
                    self.notes = commitment.notes
                    break

        # Attributes needed by table_view_helpers.py
        self.labels = []
        self.derived_labels = []

        self.ac_include = ezt.boolean(not ac_exclusion)
        self.ac_expand = ezt.boolean(not no_expand)

        self.is_group = ezt.boolean(is_group)
        self.is_service_account = ezt.boolean(
            framework_helpers.IsServiceAccount(self.user.email))
Example #3
0
    def UpdateRole(self, cnxn, project, role, member_id):
        """If the user's role was changed, update that in the Project."""
        if not role:
            return  # Role was not in the form data

        if role == framework_helpers.GetRoleName({member_id}, project).lower():
            return  # No change needed

        (owner_ids, committer_ids,
         contributor_ids) = project_helpers.MembersWithGivenIDs(
             project, {member_id}, role)

        self.services.project.UpdateProjectRoles(cnxn, project.project_id,
                                                 owner_ids, committer_ids,
                                                 contributor_ids)
    def testGetRoleName(self):
        proj = project_pb2.Project()
        proj.owner_ids.append(111)
        proj.committer_ids.append(222)
        proj.contributor_ids.append(333)

        self.assertEquals(None, framework_helpers.GetRoleName(set(), proj))

        self.assertEquals('Owner', framework_helpers.GetRoleName({111}, proj))
        self.assertEquals('Committer',
                          framework_helpers.GetRoleName({222}, proj))
        self.assertEquals('Contributor',
                          framework_helpers.GetRoleName({333}, proj))

        self.assertEquals('Owner',
                          framework_helpers.GetRoleName({111, 222, 999}, proj))
        self.assertEquals('Committer',
                          framework_helpers.GetRoleName({222, 333, 999}, proj))
        self.assertEquals('Contributor',
                          framework_helpers.GetRoleName({333, 999}, proj))
  def testGetRoleName(self):
    proj = project_pb2.Project()
    proj.owner_ids.append(111L)
    proj.committer_ids.append(222L)
    proj.contributor_ids.append(333L)

    self.assertEquals(None, framework_helpers.GetRoleName(set(), proj))

    self.assertEquals(
        'Owner', framework_helpers.GetRoleName({111L}, proj))
    self.assertEquals(
        'Committer', framework_helpers.GetRoleName({222L}, proj))
    self.assertEquals(
        'Contributor', framework_helpers.GetRoleName({333L}, proj))

    self.assertEquals(
        'Owner',
        framework_helpers.GetRoleName({111L, 222L, 999L}, proj))
    self.assertEquals(
        'Committer',
        framework_helpers.GetRoleName({222L, 333L, 999L}, proj))
    self.assertEquals(
        'Contributor',
        framework_helpers.GetRoleName({333L, 999L}, proj))
Example #6
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)