summaryrefslogtreecommitdiff
path: root/app/models/application_setting.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 10:34:06 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 10:34:06 +0000
commit859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch)
treed7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /app/models/application_setting.rb
parent446d496a6d000c73a304be52587cd9bbc7493136 (diff)
downloadgitlab-ce-859a6fb938bb9ee2a317c46dfa4fcc1af49608f0.tar.gz
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'app/models/application_setting.rb')
-rw-r--r--app/models/application_setting.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb
index 5655ea4d4bf..33c058dab96 100644
--- a/app/models/application_setting.rb
+++ b/app/models/application_setting.rb
@@ -29,6 +29,21 @@ class ApplicationSetting < ApplicationRecord
@repository_storages_weighted_atributes ||= Gitlab.config.repositories.storages.keys.map { |k| "repository_storages_weighted_#{k}".to_sym }.freeze
end
+ def self.kroki_formats_attributes
+ {
+ blockdiag: {
+ label: 'BlockDiag (includes BlockDiag, SeqDiag, ActDiag, NwDiag, PacketDiag and RackDiag)'
+ },
+ bpmn: {
+ label: 'BPMN'
+ },
+ excalidraw: {
+ label: 'Excalidraw'
+ }
+ }
+ end
+
+ store_accessor :kroki_formats, *ApplicationSetting.kroki_formats_attributes.keys, prefix: true
store_accessor :repository_storages_weighted, *Gitlab.config.repositories.storages.keys, prefix: true
# Include here so it can override methods from
@@ -43,6 +58,8 @@ class ApplicationSetting < ApplicationRecord
serialize :domain_allowlist, Array # rubocop:disable Cop/ActiveRecordSerialize
serialize :domain_denylist, Array # rubocop:disable Cop/ActiveRecordSerialize
serialize :repository_storages # rubocop:disable Cop/ActiveRecordSerialize
+ serialize :asset_proxy_allowlist, Array # rubocop:disable Cop/ActiveRecordSerialize
+ # See https://gitlab.com/gitlab-org/gitlab/-/issues/300916
serialize :asset_proxy_whitelist, Array # rubocop:disable Cop/ActiveRecordSerialize
cache_markdown_field :sign_in_text
@@ -52,6 +69,7 @@ class ApplicationSetting < ApplicationRecord
default_value_for :id, 1
default_value_for :repository_storages_weighted, {}
+ default_value_for :kroki_formats, {}
chronic_duration_attr_writer :archive_builds_in_human_readable, :archive_builds_in_seconds
@@ -133,6 +151,8 @@ class ApplicationSetting < ApplicationRecord
validate :validate_kroki_url, if: :kroki_enabled
+ validates :kroki_formats, json_schema: { filename: 'application_setting_kroki_formats' }
+
validates :plantuml_url,
presence: true,
if: :plantuml_enabled
@@ -442,6 +462,13 @@ class ApplicationSetting < ApplicationRecord
presence: true,
numericality: { only_integer: true, greater_than: 0 }
+ validates :notes_create_limit,
+ numericality: { only_integer: true, greater_than_or_equal_to: 0 }
+
+ validates :notes_create_limit_allowlist,
+ length: { maximum: 100, message: N_('is too long (maximum is 100 entries)') },
+ allow_nil: false
+
attr_encrypted :asset_proxy_secret_key,
mode: :per_attribute_iv,
key: Settings.attr_encrypted_db_key_base_truncated,
@@ -523,6 +550,10 @@ class ApplicationSetting < ApplicationRecord
current_without_cache
end
+ def self.find_or_create_without_cache
+ current_without_cache || create_from_defaults
+ end
+
# Due to the frequency with which settings are accessed, it is
# likely that during a backup restore a running GitLab process
# will insert a new `application_settings` row before the
@@ -557,6 +588,25 @@ class ApplicationSetting < ApplicationRecord
end
end
+ kroki_formats_attributes.keys.each do |key|
+ define_method :"kroki_formats_#{key}=" do |value|
+ super(::Gitlab::Utils.to_boolean(value))
+ end
+ end
+
+ def kroki_format_supported?(diagram_type)
+ case diagram_type
+ when 'excalidraw'
+ return kroki_formats_excalidraw
+ when 'bpmn'
+ return kroki_formats_bpmn
+ end
+
+ return kroki_formats_blockdiag if ::Gitlab::Kroki::BLOCKDIAG_FORMATS.include?(diagram_type)
+
+ ::AsciidoctorExtensions::Kroki::SUPPORTED_DIAGRAM_NAMES.include?(diagram_type)
+ end
+
private
def parsed_grafana_url