예제 #1
0
 def testCanonicalizeLabel(self):
   self.assertEqual(None, framework_bizobj.CanonicalizeLabel(None))
   self.assertEqual('FooBar', framework_bizobj.CanonicalizeLabel('Foo  Bar '))
   self.assertEqual('Foo.Bar',
                    framework_bizobj.CanonicalizeLabel('Foo . Bar '))
   self.assertEqual('Foo-Bar',
                    framework_bizobj.CanonicalizeLabel('Foo - Bar '))
예제 #2
0
    def ParsePersonData(self, mr, post_data):
        """Parse the POST data for a project member.

    Args:
      mr: common information parsed from the user's request.
      post_data: dictionary of lists of values for each HTML
          form field.

    Returns:
      A tuple with user_id, role, extra_perms, and notes.
    """
        if not mr.specified_user_id:
            raise exceptions.InputException('Field user_id is missing')

        role = post_data.get('role', '').lower()
        extra_perms = []
        for ep in post_data.getall('extra_perms'):
            perm = framework_bizobj.CanonicalizeLabel(ep)
            # Perms with leading underscores are reserved.
            perm = perm.strip('_')
            if perm:
                extra_perms.append(perm)

        notes = post_data.get('notes', '').strip()
        ac_exclusion = not post_data.get('ac_include', False)
        no_expand = not post_data.get('ac_expand', False)
        return (mr.specified_user_id, role, extra_perms, notes, ac_exclusion,
                no_expand)
예제 #3
0
def SetConfigLabels(project_config, well_known_labels):
    """Internal method to set the well-known labels of a ProjectIssueConfig."""
    project_config.well_known_labels = []
    for label, docstring, deprecated in well_known_labels:
        canonical_label = framework_bizobj.CanonicalizeLabel(label)
        project_config.well_known_labels.append(
            tracker_pb2.LabelDef(label=canonical_label,
                                 label_docstring=docstring,
                                 deprecated=deprecated))
예제 #4
0
def _ParseOneRule(cnxn, predicate, action_type, action_value, user_service,
                  rule_num, error_list):
    """Parse one FilterRule based on the action type."""
    if action_type == 'default_status':
        status = framework_bizobj.CanonicalizeLabel(action_value)
        rule = MakeRule(predicate, default_status=status)

    elif action_type == 'default_owner':
        if action_value:
            try:
                user_id = user_service.LookupUserID(cnxn, action_value)
            except user_svc.NoSuchUserException:
                user_id = framework_constants.NO_USER_SPECIFIED
                error_list.append('Rule %d: No such user: %s' %
                                  (rule_num, action_value))
        else:
            user_id = framework_constants.NO_USER_SPECIFIED
        rule = MakeRule(predicate, default_owner_id=user_id)

    elif action_type == 'add_ccs':
        cc_ids = []
        for email in re.split('[,;\s]+', action_value):
            if not email.strip():
                continue
            try:
                user_id = user_service.LookupUserID(cnxn,
                                                    email.strip(),
                                                    autocreate=True)
                cc_ids.append(user_id)
            except user_svc.NoSuchUserException:
                error_list.append('Rule %d: No such user: %s' %
                                  (rule_num, email.strip()))

        rule = MakeRule(predicate, add_cc_ids=cc_ids)

    elif action_type == 'add_labels':
        add_labels = framework_constants.IDENTIFIER_RE.findall(action_value)
        rule = MakeRule(predicate, add_labels=add_labels)

    elif action_type == 'also_notify':
        add_notify = []
        for addr in re.split('[,;\s]+', action_value):
            if validate.IsValidEmail(addr.strip()):
                add_notify.append(addr.strip())
            else:
                error_list.append('Rule %d: Invalid email address: %s' %
                                  (rule_num, addr.strip()))

        rule = MakeRule(predicate, add_notify=add_notify)

    else:
        logging.info('unexpected action type, probably tampering:%r',
                     action_type)
        raise monorailrequest.InputException()

    return rule
예제 #5
0
def SetConfigStatuses(project_config, well_known_statuses):
    """Internal method to set the well-known statuses of ProjectIssueConfig."""
    project_config.well_known_statuses = []
    for status, docstring, means_open, deprecated in well_known_statuses:
        canonical_status = framework_bizobj.CanonicalizeLabel(status)
        project_config.well_known_statuses.append(
            tracker_pb2.StatusDef(status_docstring=docstring,
                                  status=canonical_status,
                                  means_open=means_open,
                                  deprecated=deprecated))
예제 #6
0
def _StandardizeArtifact(artifact, well_known_artifacts):
  """Attempt to match a user-supplied artifact with standard artifact values.

  Args:
    artifact: User-supplied artifact string.
    well_known_artifacts: List of well known values of the artifact.

  Returns:
    A canonicalized artifact string, that matches a standard project
    value, if found.
  """
  artifact = framework_bizobj.CanonicalizeLabel(artifact)
  for wka in well_known_artifacts:
    if artifact.lower() == wka.lower():
      return wka
  # No match - use user-supplied artifact.
  return artifact