예제 #1
0
  def UpdateProjectRoles(
      self, cnxn, project_id, owner_ids, committer_ids, contributor_ids,
      now=None):
    """Store the project's roles in the DB and set cached_content_timestamp."""
    exists = self.project_tbl.SelectValue(
      cnxn, 'project_name', project_id=project_id)
    if not exists:
      raise exceptions.NoSuchProjectException()

    self.UpdateCachedContentTimestamp(cnxn, project_id, now=now)

    self.user2project_tbl.Delete(
        cnxn, project_id=project_id, role_name='owner', commit=False)
    self.user2project_tbl.Delete(
        cnxn, project_id=project_id, role_name='committer', commit=False)
    self.user2project_tbl.Delete(
        cnxn, project_id=project_id, role_name='contributor', commit=False)

    self.user2project_tbl.InsertRows(
        cnxn, ['project_id', 'user_id', 'role_name'],
        [(project_id, user_id, 'owner') for user_id in owner_ids],
        commit=False)
    self.user2project_tbl.InsertRows(
        cnxn, ['project_id', 'user_id', 'role_name'],
        [(project_id, user_id, 'committer')
         for user_id in committer_ids], commit=False)

    self.user2project_tbl.InsertRows(
        cnxn, ['project_id', 'user_id', 'role_name'],
        [(project_id, user_id, 'contributor')
         for user_id in contributor_ids], commit=False)

    cnxn.Commit()
    self.project_2lc.InvalidateKeys(cnxn, [project_id])
예제 #2
0
  def GetProjects(self, cnxn, project_ids, use_cache=True):
    """Load all the Project PBs for the given projects.

    Args:
      cnxn: connection to SQL database.
      project_ids: list of int project IDs
      use_cache: pass False to force database query.

    Returns:
      A dict mapping IDs to the corresponding Project protocol buffers.

    Raises:
      NoSuchProjectException: if any of the projects was not found.
    """
    project_dict, missed_ids = self.project_2lc.GetAll(
        cnxn, project_ids, use_cache=use_cache)

    # Also, update the project name cache.
    self.project_names_to_ids.CacheAll(
        {p.project_name: p.project_id for p in project_dict.values()})

    if missed_ids:
      raise exceptions.NoSuchProjectException()

    return project_dict
예제 #3
0
 def testProcessException(self):
   """Expected exceptions are converted to pRPC codes, expected not."""
   self.CheckExceptionStatus(
       exceptions.NoSuchUserException(), codes.StatusCode.NOT_FOUND)
   self.CheckExceptionStatus(
       exceptions.NoSuchProjectException(), codes.StatusCode.NOT_FOUND)
   self.CheckExceptionStatus(
       exceptions.NoSuchIssueException(), codes.StatusCode.NOT_FOUND)
   self.CheckExceptionStatus(
       exceptions.NoSuchComponentException(), codes.StatusCode.NOT_FOUND)
   self.CheckExceptionStatus(
       permissions.BannedUserException(), codes.StatusCode.PERMISSION_DENIED)
   self.CheckExceptionStatus(
       permissions.PermissionException(), codes.StatusCode.PERMISSION_DENIED)
   self.CheckExceptionStatus(
       exceptions.GroupExistsException(), codes.StatusCode.INVALID_ARGUMENT)
   self.CheckExceptionStatus(
       exceptions.InvalidComponentNameException(),
       codes.StatusCode.INVALID_ARGUMENT)
   self.CheckExceptionStatus(
       ratelimiter.ApiRateLimitExceeded('client_id', 'email'),
       codes.StatusCode.PERMISSION_DENIED)
   self.CheckExceptionStatus(
       features_svc.HotlistAlreadyExists(), codes.StatusCode.INVALID_ARGUMENT)
   self.CheckExceptionStatus(NotImplementedError(), None)
예제 #4
0
    def _LookupProject(self, services):
        """Get information about the current project (if any) from the request.

    Raises:
      NoSuchProjectException if there is no project with that name.
    """
        logging.info('project_name is %r', self.project_name)
        if self.project_name:
            self.project = services.project.GetProjectByName(
                self.cnxn, self.project_name)
            if not self.project:
                raise exceptions.NoSuchProjectException()
예제 #5
0
def issue_global_ids(project_local_id_pairs, project_id, mar, services):
    """Find global issues ids given <project_name>:<issue_local_id> pairs."""

    result = []
    for pair in project_local_id_pairs:
        issue_project_id = None
        local_id = None
        if ':' in pair:
            pair_ary = pair.split(':')
            project_name = pair_ary[0]
            local_id = int(pair_ary[1])
            project = services.project.GetProjectByName(mar.cnxn, project_name)
            if not project:
                raise exceptions.NoSuchProjectException(
                    'Project %s does not exist' % project_name)
            issue_project_id = project.project_id
        else:
            issue_project_id = project_id
            local_id = int(pair)
        result.append(
            services.issue.LookupIssueID(mar.cnxn, issue_project_id, local_id))

    return result
예제 #6
0
def IngestIssueRefs(cnxn, issue_refs, services):
    """Look up issue IDs for the specified issues."""
    project_names = set(ref.project_name for ref in issue_refs)
    project_names_to_id = services.project.LookupProjectIDs(
        cnxn, project_names)
    project_local_id_pairs = []
    for ref in issue_refs:
        if ref.ext_identifier:
            # TODO(jeffcarp): For external tracker refs, once we have the classes
            # set up, validate that the tracker for this specific ref is supported
            # and store the external ref in the issue properly.
            if '/' not in ref.ext_identifier:
                raise exceptions.InvalidExternalIssueReference()
            continue
        if ref.project_name in project_names_to_id:
            pair = (project_names_to_id[ref.project_name], ref.local_id)
            project_local_id_pairs.append(pair)
        else:
            raise exceptions.NoSuchProjectException()
    issue_ids, misses = services.issue.LookupIssueIDs(cnxn,
                                                      project_local_id_pairs)
    if misses:
        raise exceptions.NoSuchIssueException()
    return issue_ids
예제 #7
0
  def UpdateProject(
      self, cnxn, project_id, summary=None, description=None,
      state=None, state_reason=None, access=None, issue_notify_address=None,
      attachment_bytes_used=None, attachment_quota=None, moved_to=None,
      process_inbound_email=None, only_owners_remove_restrictions=None,
      read_only_reason=None, cached_content_timestamp=None,
      only_owners_see_contributors=None, delete_time=None,
      recent_activity=None, revision_url_format=None, home_page=None,
      docs_url=None, source_url=None, logo_gcs_id=None, logo_file_name=None):
    """Update the DB with the given project information."""
    exists = self.project_tbl.SelectValue(
      cnxn, 'project_name', project_id=project_id)
    if not exists:
      raise exceptions.NoSuchProjectException()

    delta = {}
    if summary is not None:
      delta['summary'] = summary
    if description is not None:
      delta['description'] = description
    if state is not None:
      delta['state'] = str(state).lower()
    if state is not None:
      delta['state_reason'] = state_reason
    if access is not None:
      delta['access'] = str(access).lower()
    if read_only_reason is not None:
      delta['read_only_reason'] = read_only_reason
    if issue_notify_address is not None:
      delta['issue_notify_address'] = issue_notify_address
    if attachment_bytes_used is not None:
      delta['attachment_bytes_used'] = attachment_bytes_used
    if attachment_quota is not None:
      delta['attachment_quota'] = attachment_quota
    if moved_to is not None:
      delta['moved_to'] = moved_to
    if process_inbound_email is not None:
      delta['process_inbound_email'] = process_inbound_email
    if only_owners_remove_restrictions is not None:
      delta['only_owners_remove_restrictions'] = (
          only_owners_remove_restrictions)
    if only_owners_see_contributors is not None:
      delta['only_owners_see_contributors'] = only_owners_see_contributors
    if delete_time is not None:
      delta['delete_time'] = delete_time
    if recent_activity is not None:
      delta['recent_activity_timestamp'] = recent_activity
    if revision_url_format is not None:
      delta['revision_url_format'] = revision_url_format
    if home_page is not None:
      delta['home_page'] = home_page
    if docs_url is not None:
      delta['docs_url'] = docs_url
    if source_url is not None:
      delta['source_url'] = source_url
    if logo_gcs_id is not None:
      delta['logo_gcs_id'] = logo_gcs_id
    if logo_file_name is not None:
      delta['logo_file_name'] = logo_file_name
    if cached_content_timestamp is not None:
      delta['cached_content_timestamp'] = cached_content_timestamp
    self.project_tbl.Update(cnxn, delta, project_id=project_id)
    self.project_2lc.InvalidateKeys(cnxn, [project_id])