Class: Katello::Validators::ContentViewErratumFilterRuleValidator
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- Katello::Validators::ContentViewErratumFilterRuleValidator
- Defined in:
- app/lib/katello/validators/content_view_erratum_filter_rule_validator.rb
Instance Method Summary collapse
- #_check_date_range(record) ⇒ Object
- #_check_single_date_range(record) ⇒ Object
- #_check_types(record) ⇒ Object
- #validate(record) ⇒ Object
Instance Method Details
#_check_date_range(record) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/lib/katello/validators/content_view_erratum_filter_rule_validator.rb', line 43 def _check_date_range(record) start_date_int = record.start_date.to_time.to_i unless record.start_date.blank? end_date_int = record.end_date.to_time.to_i unless record.end_date.blank? if start_date_int && (!start_date_int.is_a?(Integer) || !record.start_date.is_a?(String)) record.errors[:base] << _("The erratum filter rule start date is in an invalid format or type.") end if end_date_int && (!end_date_int.is_a?(Integer) || !record.end_date.is_a?(String)) record.errors[:base] << _("The erratum filter rule end date is in an invalid format or type.") end if start_date_int && end_date_int && !(start_date_int <= end_date_int) record.errors[:base] << _("Invalid date range. The erratum filter rule start date must come before the end date") end end |
#_check_single_date_range(record) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/lib/katello/validators/content_view_erratum_filter_rule_validator.rb', line 26 def _check_single_date_range(record) if record.start_date || record.end_date || !record.types.empty? if !record.filter.erratum_rules.empty? && !record.filter.erratum_rules.any? { |rule| rule.id == record.id } invalid_parameters = _("May not add a type or date range rule to a filter that has existing rules.") record.errors[:base] << invalid_parameters end else if record.filter_has_date_or_type_rule? invalid_parameters = _("May not add an id rule to a filter that has an existing type or date range rule.") record.errors[:base] << invalid_parameters end end end |
#_check_types(record) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/lib/katello/validators/content_view_erratum_filter_rule_validator.rb', line 59 def _check_types(record) if record.types.is_a?(Array) invalid_types = record.types.collect(&:to_s) - ContentViewErratumFilter::ERRATA_TYPES.keys unless invalid_types.empty? record.errors[:base] << _("Invalid erratum types %{invalid_types} provided. Erratum type can be any of %{valid_types}") % { :invalid_types => invalid_types.join(","), :valid_types => ContentViewErratumFilter::ERRATA_TYPES.keys.join(",")} end else record.errors[:base] << _("The erratum type must be an array. Invalid value provided") end end |
#validate(record) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/lib/katello/validators/content_view_erratum_filter_rule_validator.rb', line 4 def validate(record) if record.errata_id.blank? && record.start_date.blank? && record.end_date.blank? && record.types.blank? invalid_parameters = _("Invalid erratum filter rule specified, Must specify at least one of the following:" \ " 'errata_id', 'start_date', 'end_date' or 'types'") record.errors[:base] << invalid_parameters return end if !record.errata_id.blank? && (!record.start_date.blank? || !record.end_date.blank? || !record.types.blank?) invalid_parameters = _("Invalid erratum filter rule specified, 'errata_id' cannot be specified in the" \ " same tuple as 'start_date', 'end_date' or 'types'") record.errors[:base] << invalid_parameters return end _check_single_date_range(record) _check_date_range(record) _check_types(record) end |