debian-mirror-gitlab/app/models/project_setting.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

119 lines
3.3 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
class ProjectSetting < ApplicationRecord
2022-10-11 01:57:18 +05:30
include ::Gitlab::Utils::StrongMemoize
2023-01-13 00:05:48 +05:30
include EachBatch
2022-10-11 01:57:18 +05:30
2022-07-16 23:28:13 +05:30
ALLOWED_TARGET_PLATFORMS = %w(ios osx tvos watchos android).freeze
2022-04-04 11:22:00 +05:30
2020-03-13 15:44:24 +05:30
belongs_to :project, inverse_of: :project_setting
2022-08-13 15:12:31 +05:30
scope :for_projects, ->(projects) { where(project_id: projects) }
2023-07-09 08:55:56 +05:30
attr_encrypted :cube_api_key,
mode: :per_attribute_iv,
key: Settings.attr_encrypted_db_key_base_32,
algorithm: 'aes-256-gcm',
encode: false,
encode_iv: false
attr_encrypted :jitsu_administrator_password,
mode: :per_attribute_iv,
key: Settings.attr_encrypted_db_key_base_32,
algorithm: 'aes-256-gcm',
encode: false,
encode_iv: false
attr_encrypted :product_analytics_clickhouse_connection_string,
mode: :per_attribute_iv,
key: Settings.attr_encrypted_db_key_base_32,
algorithm: 'aes-256-gcm',
encode: false,
encode_iv: false
2020-07-28 23:09:34 +05:30
enum squash_option: {
never: 0,
always: 1,
default_on: 2,
default_off: 3
}, _prefix: 'squash'
2020-03-13 15:44:24 +05:30
self.primary_key = :project_id
2020-07-28 23:09:34 +05:30
2022-04-04 11:22:00 +05:30
validates :merge_commit_template, length: { maximum: Project::MAX_COMMIT_TEMPLATE_LENGTH }
validates :squash_commit_template, length: { maximum: Project::MAX_COMMIT_TEMPLATE_LENGTH }
2023-01-13 00:05:48 +05:30
validates :issue_branch_template, length: { maximum: Issue::MAX_BRANCH_TEMPLATE }
2022-06-21 17:19:12 +05:30
validates :target_platforms, inclusion: { in: ALLOWED_TARGET_PLATFORMS }
2022-11-25 23:54:43 +05:30
validates :suggested_reviewers_enabled, inclusion: { in: [true, false] }
2022-06-21 17:19:12 +05:30
2023-05-27 22:25:52 +05:30
validates :pages_unique_domain,
uniqueness: { if: -> { pages_unique_domain.present? } },
presence: { if: :require_unique_domain? }
2022-06-21 17:19:12 +05:30
validate :validates_mr_default_target_self
2022-04-04 11:22:00 +05:30
2023-09-09 18:01:29 +05:30
validate :pages_unique_domain_availability, if: :pages_unique_domain_changed?
2023-01-13 00:05:48 +05:30
attribute :legacy_open_source_license_available, default: -> do
2022-07-16 23:28:13 +05:30
Feature.enabled?(:legacy_open_source_license_available, type: :ops)
2022-04-04 11:22:00 +05:30
end
2021-12-11 22:18:48 +05:30
2020-07-28 23:09:34 +05:30
def squash_enabled_by_default?
%w[always default_on].include?(squash_option)
end
def squash_readonly?
%w[always never].include?(squash_option)
end
2022-03-02 08:16:31 +05:30
2022-06-21 17:19:12 +05:30
def target_platforms=(val)
super(val&.map(&:to_s)&.sort)
end
2022-03-02 08:16:31 +05:30
2022-07-16 23:28:13 +05:30
def human_squash_option
case squash_option
when 'never' then 'Do not allow'
when 'always' then 'Require'
when 'default_on' then 'Encourage'
when 'default_off' then 'Allow'
end
end
2022-10-11 01:57:18 +05:30
def show_diff_preview_in_email?
if project.group
super && project.group&.show_diff_preview_in_email?
else
!!super
end
end
2023-03-17 16:20:25 +05:30
strong_memoize_attr :show_diff_preview_in_email?
2022-10-11 01:57:18 +05:30
2023-06-20 00:43:36 +05:30
def runner_registration_enabled
Gitlab::CurrentSettings.valid_runner_registrars.include?('project') && read_attribute(:runner_registration_enabled)
end
2022-03-02 08:16:31 +05:30
private
def validates_mr_default_target_self
if mr_default_target_self_changed? && !project.forked?
errors.add :mr_default_target_self, _('This setting is allowed for forked projects only')
end
end
2023-05-27 22:25:52 +05:30
def require_unique_domain?
pages_unique_domain_enabled ||
pages_unique_domain_in_database.present?
end
2023-09-09 18:01:29 +05:30
def pages_unique_domain_availability
host = Gitlab.config.pages&.dig('host')
return if host.blank?
return unless Project.where(path: "#{pages_unique_domain}.#{host}").exists?
errors.add(:pages_unique_domain, s_('ProjectSetting|already in use'))
end
2020-03-13 15:44:24 +05:30
end
2020-04-22 19:07:51 +05:30
2021-06-08 01:23:25 +05:30
ProjectSetting.prepend_mod