diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-09 03:09:39 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-09 03:09:39 +0300 |
commit | bc692af9882a4eb5b4b4ca6df682375f3a21cb44 (patch) | |
tree | 8613106463a2cbfda58230a90505cc8ed661af55 /app | |
parent | 66108e3b34cdba3eab53e07fdde76f799c0edc9b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/models/ci/freeze_period.rb | 16 | ||||
-rw-r--r-- | app/models/project.rb | 1 | ||||
-rw-r--r-- | app/services/ci/compare_accessibility_reports_service.rb | 17 | ||||
-rw-r--r-- | app/validators/cron_freeze_period_timezone_validator.rb | 13 | ||||
-rw-r--r-- | app/validators/cron_validator.rb | 15 |
5 files changed, 57 insertions, 5 deletions
diff --git a/app/models/ci/freeze_period.rb b/app/models/ci/freeze_period.rb new file mode 100644 index 00000000000..3875ab5d41b --- /dev/null +++ b/app/models/ci/freeze_period.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Ci + class FreezePeriod < ApplicationRecord + include StripAttribute + self.table_name = 'ci_freeze_periods' + + belongs_to :project, inverse_of: :freeze_periods + + strip_attributes :freeze_start, :freeze_end + + validates :freeze_start, cron: true, presence: true + validates :freeze_end, cron: true, presence: true + validates :cron_timezone, cron_freeze_period_timezone: true, presence: true + end +end diff --git a/app/models/project.rb b/app/models/project.rb index 9eac01c3c06..d8ccea3e37f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -302,6 +302,7 @@ class Project < ApplicationRecord has_many :project_deploy_tokens has_many :deploy_tokens, through: :project_deploy_tokens has_many :resource_groups, class_name: 'Ci::ResourceGroup', inverse_of: :project + has_many :freeze_periods, class_name: 'Ci::FreezePeriod', inverse_of: :project has_one :auto_devops, class_name: 'ProjectAutoDevops', inverse_of: :project, autosave: true has_many :custom_attributes, class_name: 'ProjectCustomAttribute' diff --git a/app/services/ci/compare_accessibility_reports_service.rb b/app/services/ci/compare_accessibility_reports_service.rb new file mode 100644 index 00000000000..efb38d39d98 --- /dev/null +++ b/app/services/ci/compare_accessibility_reports_service.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Ci + class CompareAccessibilityReportsService < CompareReportsBaseService + def comparer_class + Gitlab::Ci::Reports::AccessibilityReportsComparer + end + + def serializer_class + AccessibilityReportsComparerSerializer + end + + def get_report(pipeline) + pipeline&.accessibility_reports + end + end +end diff --git a/app/validators/cron_freeze_period_timezone_validator.rb b/app/validators/cron_freeze_period_timezone_validator.rb new file mode 100644 index 00000000000..143a0262136 --- /dev/null +++ b/app/validators/cron_freeze_period_timezone_validator.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +# CronTimezoneValidator +# +# Custom validator for CronTimezone. +class CronFreezePeriodTimezoneValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + freeze_start_parser = Gitlab::Ci::CronParser.new(record.freeze_start, record.cron_timezone) + freeze_end_parser = Gitlab::Ci::CronParser.new(record.freeze_end, record.cron_timezone) + + record.errors.add(attribute, " is invalid syntax") unless freeze_start_parser.cron_timezone_valid? && freeze_end_parser.cron_timezone_valid? + end +end diff --git a/app/validators/cron_validator.rb b/app/validators/cron_validator.rb index bd48a7a6efb..6f42bdb5f9b 100644 --- a/app/validators/cron_validator.rb +++ b/app/validators/cron_validator.rb @@ -1,11 +1,16 @@ # frozen_string_literal: true -# CronValidator -# -# Custom validator for Cron. class CronValidator < ActiveModel::EachValidator + ATTRIBUTE_WHITELIST = %i[cron freeze_start freeze_end].freeze + + NonWhitelistedAttributeError = Class.new(StandardError) + def validate_each(record, attribute, value) - cron_parser = Gitlab::Ci::CronParser.new(record.cron, record.cron_timezone) - record.errors.add(attribute, " is invalid syntax") unless cron_parser.cron_valid? + if ATTRIBUTE_WHITELIST.include?(attribute) + cron_parser = Gitlab::Ci::CronParser.new(record.public_send(attribute), record.cron_timezone) # rubocop:disable GitlabSecurity/PublicSend + record.errors.add(attribute, " is invalid syntax") unless cron_parser.cron_valid? + else + raise NonWhitelistedAttributeError.new "Non-whitelisted attribute" + end end end |