Пример #1
0
  def _get_parent_obj(self):
    """Get parent object specified"""
    from ggrc.models.object_document import Documentable
    from ggrc.models import all_models
    if 'id' not in self._parent_obj:
      raise exceptions.ValidationError('"id" is mandatory for parent_obj')
    if 'type' not in self._parent_obj:
      raise exceptions.ValidationError(
          '"type" is mandatory for parent_obj')
    parent_type = self._parent_obj['type']
    parent_model = getattr(all_models, parent_type, None)
    if parent_model is None:
      raise exceptions.ValidationError(
          'Type "{}" not found.'.format(parent_type)
      )
    if not issubclass(parent_model, Documentable):
      raise exceptions.ValidationError(
          'Type "{}" is not Documentable.'.format(parent_type)
      )

    parent_id = self._parent_obj['id']
    obj = referenced_objects.get(parent_type, parent_id)

    if not obj:
      raise ValueError(
          'Parent object not found: {type} {id}'.format(type=parent_type,
                                                        id=parent_id))
    return obj
Пример #2
0
def _validate_issue_tracker_info(info):
  """Validates that component ID and hotlist ID are integers."""
  component_id = info.get('component_id')
  if component_id:
    try:
      int(component_id)
    except (TypeError, ValueError):
      raise exceptions.ValidationError('Component ID must be a number.')

  hotlist_id = info.get('hotlist_id')
  if hotlist_id:
    try:
      int(hotlist_id)
    except (TypeError, ValueError):
      raise exceptions.ValidationError('Hotlist ID must be a number.')
Пример #3
0
    def validate_review_status(self, _, value):
        """Add explicit non-nullable validation."""
        if value is None:
            raise exceptions.ValidationError(
                "Review status for the object is not specified")

        return value
Пример #4
0
def _normalize_issue_tracker_info(info):
  """Insures that component ID and hotlist ID are integers."""
  # TODO(anushovan): remove data type casting once integration service
  #   supports strings for following properties.
  component_id = info.get('component_id')
  if component_id:
    try:
      info['component_id'] = int(component_id)
    except (TypeError, ValueError):
      raise exceptions.ValidationError('Component ID must be a number.')

  hotlist_id = info.get('hotlist_id')
  if hotlist_id:
    try:
      info['hotlist_id'] = int(hotlist_id)
    except (TypeError, ValueError):
      raise exceptions.ValidationError('Hotlist ID must be a number.')
    def validate_cad_id(self, _, value):
        """Validates external CAD id."""
        # pylint: disable=no-self-use
        if value is None:
            raise exceptions.ValidationError(
                "id for the CAD is not specified.")

        return value
Пример #6
0
 def process_bind_param(self, value, dialect):
     if value is None or isinstance(value, basestring):
         pass
     else:
         value = utils.as_json(value)
         if len(value.encode('utf-8')) > self.MAX_TEXT_LENGTH:
             raise exceptions.ValidationError("Log record content too long")
     return value
Пример #7
0
 def validate_slug(self, _, value):
   """Validates slug for presence of forbidden symbols"""
   # pylint: disable=no-self-use
   if value and "*" in value:
     raise exceptions.ValidationError(
         "Field 'Code' contains unsupported symbol '*'"
     )
   return value
Пример #8
0
 def _check_single_audit_restriction(self, src, dst):
     """Fail if dst (Issue) is already mapped to an Audit."""
     # src, dst are ordered since they come from self.queue
     if (src.type, dst.type) == ("Audit", "Issue"):
         if "Audit" in (r.type for r in self.related(dst)):
             raise exceptions.ValidationError(
                 "This request will result in automapping that will map "
                 "Issue#{issue.id} to multiple Audits.".format(issue=dst))
Пример #9
0
    def validate_review_status_display_name(self, _, value):
        """Add explicit non-nullable validation."""
        # pylint: disable=no-self-use

        if value is None:
            raise exceptions.ValidationError(
                "Review status display for the object is not specified")

        return value
    def component_id(self, value):
        """Validate and set 'component_id'."""
        if not value:
            return

        try:
            self._component_id = int(value)
        except (TypeError, ValueError):
            raise exceptions.ValidationError("Component ID must be a number.")
    def hotlist_id(self, value):
        """Validate and set 'hotlist_id'."""
        if not value:
            return

        try:
            self._hotlist_id = int(value)
        except (TypeError, ValueError):
            raise exceptions.ValidationError("Hotlist ID must be a number.")
Пример #12
0
 def validate_acl(self):
     """Reviewer is mandatory Role"""
     super(Review, self).validate_acl()
     review_global_roles = role.get_ac_roles_data_for("Review").values()
     mandatory_role_ids = {acr[0] for acr in review_global_roles if acr[3]}
     passed_acr_ids = {acl.ac_role_id for acl in self.access_control_list}
     missed_mandatory_roles = mandatory_role_ids - passed_acr_ids
     if missed_mandatory_roles:
         raise exceptions.ValidationError("{} roles are mandatory".format(
             ",".join(missed_mandatory_roles)))
Пример #13
0
 def validate_kind(self, key, kind):
     """Returns correct option, otherwise rises an error"""
     if kind is None:
         kind = self.URL
     if kind not in self.VALID_EVIDENCE_KINDS:
         raise exceptions.ValidationError(
             "Invalid value for attribute {attr}. "
             "Expected options are `{url}`, `{file}`".format(
                 attr=key, url=self.URL, file=self.FILE))
     return kind
    def issue_severity(self, value):
        """Validate and set issue severity."""
        if not value:
            return

        if value not in self.AVAILABLE_SEVERITIES:
            raise exceptions.ValidationError(
                "Invalid severity value: {}. Valid severity values: '{}'".
                format(value, ", ".join(self.AVAILABLE_SEVERITIES)))
        self._issue_severity = value
Пример #15
0
  def issue_priority(self, value):
    """Validate and set issue priority."""
    if not value:
      return

    if value not in constants.AVAILABLE_PRIORITIES:
      raise exceptions.ValidationError(
          "Invalid priority value: {}. Valid priority values: '{}'"
          .format(value, ", ".join(constants.AVAILABLE_PRIORITIES))
      )
    self._issue_priority = value
Пример #16
0
    def _get_parent_obj(self):
        """Get parent object specified"""
        if 'id' not in self._parent_obj:
            raise exceptions.ValidationError(
                '"id" is mandatory for parent_obj')
        if 'type' not in self._parent_obj:
            raise exceptions.ValidationError(
                '"type" is mandatory for parent_obj')
        if self._parent_obj['type'] not in self._allowed_parents:
            raise exceptions.ValidationError('Allowed types are: {}.'.format(
                ', '.join(self._allowed_parents)))

        parent_type = self._parent_obj['type']
        parent_id = self._parent_obj['id']
        obj = referenced_objects.get(parent_type, parent_id)

        if not obj:
            raise ValueError('Parent object not found: {type} {id}'.format(
                type=parent_type, id=parent_id))
        return obj
Пример #17
0
def _handle_new_audit_issue_mapping(audit, issue):
  """Set audit_id and context_id on issue if allowed else fail."""
  if not issue.allow_map_to_audit:
    raise exceptions.ValidationError(
        "Issue#{issue.id} can't be mapped to Audit#{audit.id}: already mapped "
        "to Audit#{mapped_audit_id}"
        .format(issue=issue, audit=audit,
                mapped_audit_id=issue.audit_id or issue.audit.id))

  issue.audit = audit
  issue.context = audit.context
Пример #18
0
    def _get_parent_obj(self):
        """Get parent object specified"""
        if "id" not in self._parent_obj:
            raise exceptions.ValidationError(
                "'id' is mandatory for parent_obj")
        if "type" not in self._parent_obj:
            raise exceptions.ValidationError(
                "'type' is mandatory for parent_obj")
        if self._parent_obj["type"] not in self._allowed_parents:
            raise exceptions.ValidationError("Allowed types are: {}.".format(
                ", ".join(self._allowed_parents)))

        parent_type = self._parent_obj["type"]
        parent_id = self._parent_obj["id"]
        obj = referenced_objects.get(parent_type, parent_id)

        if not obj:
            raise ValueError("Parent object not found: {type} {id}".format(
                type=parent_type, id=parent_id))
        return obj
Пример #19
0
    def _get_documentable_obj(self):
        """Get documentable object specified"""
        if 'id' not in self._documentable_obj:
            raise exceptions.ValidationError('"id" is mandatory'
                                             ' for documentable_obj')
        if 'type' not in self._documentable_obj:
            raise exceptions.ValidationError(
                '"type" is mandatory for documentable_obj')
        if self._documentable_obj['type'] not in self._allowed_documentables:
            raise exceptions.ValidationError('Allowed types are: {}.'.format(
                ', '.join(self._allowed_documentables)))

        doc_type = self._documentable_obj['type']
        doc_id = self._documentable_obj['id']
        obj = referenced_objects.get(doc_type, doc_id)

        if not obj:
            raise ValueError(
                'Documentable object not found: {type} {id}'.format(
                    type=doc_type, id=doc_id))
        return obj
Пример #20
0
def _handle_del_audit_issue_mapping(audit, issue):
  """Unset audit_id and context_id from issue if allowed else fail."""
  if issue in db.session.deleted:
    # the issue is being removed, no action needed
    return
  if audit not in db.session.deleted and not issue.allow_unmap_from_audit:
    raise exceptions.ValidationError("Issue#{issue.id} can't be unmapped "
                                     "from Audit#{audit.id}: common mappings."
                                     .format(issue=issue, audit=audit))

  issue.audit = None
  issue.context = None
Пример #21
0
 def validate_document_type(self, key, document_type):
     """Returns correct option, otherwise rises an error"""
     if document_type is None:
         document_type = self.URL
     if document_type not in self.VALID_DOCUMENT_TYPES:
         raise exceptions.ValidationError(
             "Invalid value for attribute {attr}. "
             "Expected options are `{url}`, `{attachment}`, `{reference_url}`"
             .format(attr=key,
                     url=self.URL,
                     attachment=self.ATTACHMENT,
                     reference_url=self.REFERENCE_URL))
     return document_type
Пример #22
0
 def validate_document_type(self, key, document_type):
     """Returns correct option, otherwise rises an error"""
     if document_type is None:
         document_type = self.URL
     if document_type not in [self.URL, self.ATTACHMENT]:
         raise exceptions.ValidationError(
             "Invalid value for attribute {attr}. "
             "Expected options are `{url}`, `{attachment}`.".format(
                 attr=key,
                 url=self.URL,
                 attachment=self.ATTACHMENT,
             ))
     return document_type
Пример #23
0
 def validate_slug(self, _, value):
     """Validates slug for presence of forbidden symbols"""
     # pylint: disable=no-self-use
     if value:
         new_value = value.strip()
         if new_value != value:
             logger.warning(
                 "Slug \"%s\" contains unsupported leading or trailing "
                 "whitespace. Slug will be trimmed.", value)
             value = new_value
     if value and "*" in value:
         raise exceptions.ValidationError(
             "Field 'Code' contains unsupported symbol '*'")
     return value
Пример #24
0
 def validate_email(self, _, email):
   """Email property validator."""
   if not Person.is_valid_email(email):
     message = "Email address '{}' is invalid. Valid email must be provided"
     raise exceptions.ValidationError(message.format(email))
   return email
Пример #25
0
 def process_bind_param(self, value, dialect):
     value = pickle.dumps(value)
     if len(value) > self.MAX_BINARY_LENGTH:
         raise exceptions.ValidationError("Log record content too long")
     return value
Пример #26
0
 def validate_name(self, _, name):
   """Name property validator."""
   if not name:
     raise exceptions.ValidationError("Name is empty")
   return name