diff options
Diffstat (limited to 'app/models/integrations')
-rw-r--r-- | app/models/integrations/base_chat_notification.rb | 5 | ||||
-rw-r--r-- | app/models/integrations/base_issue_tracker.rb | 13 | ||||
-rw-r--r-- | app/models/integrations/base_third_party_wiki.rb | 39 | ||||
-rw-r--r-- | app/models/integrations/buildkite.rb | 4 | ||||
-rw-r--r-- | app/models/integrations/confluence.rb | 15 | ||||
-rw-r--r-- | app/models/integrations/emails_on_push.rb | 4 | ||||
-rw-r--r-- | app/models/integrations/field.rb | 6 | ||||
-rw-r--r-- | app/models/integrations/jira.rb | 25 | ||||
-rw-r--r-- | app/models/integrations/pipelines_email.rb | 5 | ||||
-rw-r--r-- | app/models/integrations/prometheus.rb | 6 | ||||
-rw-r--r-- | app/models/integrations/shimo.rb | 17 |
11 files changed, 75 insertions, 64 deletions
diff --git a/app/models/integrations/base_chat_notification.rb b/app/models/integrations/base_chat_notification.rb index d5b6357cb66..54bd595892f 100644 --- a/app/models/integrations/base_chat_notification.rb +++ b/app/models/integrations/base_chat_notification.rb @@ -35,8 +35,9 @@ module Integrations validates :labels_to_be_notified_behavior, inclusion: { in: LABEL_NOTIFICATION_BEHAVIOURS }, allow_blank: true def initialize_properties - if properties.nil? - self.properties = {} + super + + if properties.empty? self.notify_only_broken_pipelines = true self.branches_to_be_notified = "default" self.labels_to_be_notified_behavior = MATCH_ANY_LABEL diff --git a/app/models/integrations/base_issue_tracker.rb b/app/models/integrations/base_issue_tracker.rb index 458d0199e7a..bffe87c21ee 100644 --- a/app/models/integrations/base_issue_tracker.rb +++ b/app/models/integrations/base_issue_tracker.rb @@ -25,12 +25,15 @@ module Integrations def handle_properties # this has been moved from initialize_properties and should be improved # as part of https://gitlab.com/gitlab-org/gitlab/issues/29404 - return unless properties + return unless properties.present? + + safe_keys = data_fields.attributes.keys.grep_v(/encrypted/) - %w[id service_id created_at] @legacy_properties_data = properties.dup - data_values = properties.slice!('title', 'description') + + data_values = properties.slice(*safe_keys) data_values.reject! { |key| data_fields.changed.include?(key) } - data_values.slice!(*data_fields.attributes.keys) + data_fields.assign_attributes(data_values) if data_values.present? self.properties = {} @@ -68,10 +71,6 @@ module Integrations issue_url(iid) end - def initialize_properties - {} - end - # Initialize with default properties values def set_default_data return unless issues_tracker.present? diff --git a/app/models/integrations/base_third_party_wiki.rb b/app/models/integrations/base_third_party_wiki.rb new file mode 100644 index 00000000000..24f5bec93cf --- /dev/null +++ b/app/models/integrations/base_third_party_wiki.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +module Integrations + class BaseThirdPartyWiki < Integration + default_value_for :category, 'third_party_wiki' + + validate :only_one_third_party_wiki, if: :activated?, on: :manual_change + + after_commit :cache_project_has_integration + + def self.supported_events + %w() + end + + private + + def only_one_third_party_wiki + return unless project_level? + + if project.integrations.third_party_wikis.id_not_in(id).any? + errors.add(:base, _('Another third-party wiki is already in use. '\ + 'Only one third-party wiki integration can be active at a time')) + end + end + + def cache_project_has_integration + return unless project && !project.destroyed? + + project_setting = project.project_setting + + project_setting.public_send("#{project_settings_cache_key}=", active?) # rubocop:disable GitlabSecurity/PublicSend + project_setting.save! + end + + def project_settings_cache_key + "has_#{self.class.to_param}" + end + end +end diff --git a/app/models/integrations/buildkite.rb b/app/models/integrations/buildkite.rb index 90593d78a5d..b816f90ef52 100644 --- a/app/models/integrations/buildkite.rb +++ b/app/models/integrations/buildkite.rb @@ -27,12 +27,12 @@ module Integrations end # Since SSL verification will always be enabled for Buildkite, - # we no longer needs to store the boolean. + # we no longer need to store the boolean. # This is a stub method to work with deprecated API param. # TODO: remove enable_ssl_verification after 14.0 # https://gitlab.com/gitlab-org/gitlab/-/issues/222808 def enable_ssl_verification=(_value) - self.properties.delete('enable_ssl_verification') # Remove unused key + self.properties = properties.except('enable_ssl_verification') # Remove unused key end override :hook_url diff --git a/app/models/integrations/confluence.rb b/app/models/integrations/confluence.rb index 65adce7a8d6..4e1d1993d02 100644 --- a/app/models/integrations/confluence.rb +++ b/app/models/integrations/confluence.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Integrations - class Confluence < Integration + class Confluence < BaseThirdPartyWiki VALID_SCHEME_MATCH = %r{\Ahttps?\Z}.freeze VALID_HOST_MATCH = %r{\A.+\.atlassian\.net\Z}.freeze VALID_PATH_MATCH = %r{\A/wiki(/|\Z)}.freeze @@ -11,16 +11,10 @@ module Integrations validates :confluence_url, presence: true, if: :activated? validate :validate_confluence_url_is_cloud, if: :activated? - after_commit :cache_project_has_confluence - def self.to_param 'confluence' end - def self.supported_events - %w() - end - def title s_('ConfluenceService|Confluence Workspace') end @@ -80,12 +74,5 @@ module Integrations rescue URI::InvalidURIError false end - - def cache_project_has_confluence - return unless project && !project.destroyed? - - project.project_setting.save! unless project.project_setting.persisted? - project.project_setting.update_column(:has_confluence, active?) - end end end diff --git a/app/models/integrations/emails_on_push.rb b/app/models/integrations/emails_on_push.rb index a9cd67550dc..ab458bb2c27 100644 --- a/app/models/integrations/emails_on_push.rb +++ b/app/models/integrations/emails_on_push.rb @@ -13,9 +13,7 @@ module Integrations validate :number_of_recipients_within_limit, if: :validate_recipients? def self.valid_recipients(recipients) - recipients.split.select do |recipient| - recipient.include?('@') - end.uniq(&:downcase) + recipients.split.grep(Devise.email_regexp).uniq(&:downcase) end def title diff --git a/app/models/integrations/field.rb b/app/models/integrations/field.rb index 49ab97677db..f00c4236a92 100644 --- a/app/models/integrations/field.rb +++ b/app/models/integrations/field.rb @@ -2,7 +2,7 @@ module Integrations class Field - SENSITIVE_NAME = %r/token|key|password|passphrase|secret/.freeze + SECRET_NAME = %r/token|key|password|passphrase|secret/.freeze ATTRIBUTES = %i[ section type placeholder required choices value checkbox_label @@ -17,7 +17,7 @@ module Integrations def initialize(name:, type: 'text', api_only: false, **attributes) @name = name.to_s.freeze - attributes[:type] = SENSITIVE_NAME.match?(@name) ? 'password' : type + attributes[:type] = SECRET_NAME.match?(@name) ? 'password' : type attributes[:api_only] = api_only @attributes = attributes.freeze end @@ -31,7 +31,7 @@ module Integrations value end - def sensitive? + def secret? @attributes[:type] == 'password' end diff --git a/app/models/integrations/jira.rb b/app/models/integrations/jira.rb index 74ece57000f..a800b9e5baa 100644 --- a/app/models/integrations/jira.rb +++ b/app/models/integrations/jira.rb @@ -94,10 +94,6 @@ module Integrations !!URI(url).hostname&.end_with?(JIRA_CLOUD_HOST) end - def initialize_properties - {} - end - def data_fields jira_tracker_data || self.build_jira_tracker_data end @@ -106,7 +102,7 @@ module Integrations return unless reset_password? data_fields.password = nil - properties.delete('password') if properties + self.properties = properties.except('password') end def set_default_data @@ -143,7 +139,7 @@ module Integrations end def help - jira_doc_link_start = '<a href="%{url}">'.html_safe % { url: help_page_url('integration/jira/index.html') } + jira_doc_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: help_page_path('integration/jira/index') } s_("JiraService|You must configure Jira before enabling this integration. %{jira_doc_link_start}Learn more.%{link_end}") % { jira_doc_link_start: jira_doc_link_start, link_end: '</a>'.html_safe } end @@ -160,8 +156,6 @@ module Integrations end def sections - jira_issues_link_start = '<a href="%{url}">'.html_safe % { url: help_page_url('integration/jira/issues.html') } - sections = [ { type: SECTION_TYPE_CONNECTION, @@ -180,7 +174,7 @@ module Integrations sections.push({ type: SECTION_TYPE_JIRA_ISSUES, title: _('Issues'), - description: s_('JiraService|Work on Jira issues without leaving GitLab. Add a Jira menu to access a read-only list of your Jira issues. %{jira_issues_link_start}Learn more.%{link_end}') % { jira_issues_link_start: jira_issues_link_start, link_end: '</a>'.html_safe } + description: jira_issues_section_description }) end @@ -610,6 +604,19 @@ module Integrations data_fields.deployment_server! end end + + def jira_issues_section_description + jira_issues_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: help_page_path('integration/jira/issues') } + description = s_('JiraService|Work on Jira issues without leaving GitLab. Add a Jira menu to access a read-only list of your Jira issues. %{jira_issues_link_start}Learn more.%{link_end}') % { jira_issues_link_start: jira_issues_link_start, link_end: '</a>'.html_safe } + + if project&.issues_enabled? + gitlab_issues_link_start = '<a href="%{url}">'.html_safe % { url: edit_project_path(project, anchor: 'js-shared-permissions') } + description += '<br><br>'.html_safe + description += s_("JiraService|Displaying Jira issues while leaving GitLab issues also enabled might be confusing. Consider %{gitlab_issues_link_start}disabling GitLab issues%{link_end} if they won't otherwise be used.") % { gitlab_issues_link_start: gitlab_issues_link_start, link_end: '</a>'.html_safe } + end + + description + end end end diff --git a/app/models/integrations/pipelines_email.rb b/app/models/integrations/pipelines_email.rb index 6dc41958daa..f15482dc2e1 100644 --- a/app/models/integrations/pipelines_email.rb +++ b/app/models/integrations/pipelines_email.rb @@ -12,8 +12,9 @@ module Integrations validate :number_of_recipients_within_limit, if: :validate_recipients? def initialize_properties - if properties.nil? - self.properties = {} + super + + if properties.blank? self.notify_only_broken_pipelines = true self.branches_to_be_notified = "default" elsif !self.notify_only_default_branch.nil? diff --git a/app/models/integrations/prometheus.rb b/app/models/integrations/prometheus.rb index 2e275dab91b..d6aafe45ae9 100644 --- a/app/models/integrations/prometheus.rb +++ b/app/models/integrations/prometheus.rb @@ -32,12 +32,6 @@ module Integrations scope :preload_project, -> { preload(:project) } scope :with_clusters_with_cilium, -> { joins(project: [:clusters]).merge(Clusters::Cluster.with_available_cilium) } - def initialize_properties - if properties.nil? - self.properties = {} - end - end - def show_active_box? false end diff --git a/app/models/integrations/shimo.rb b/app/models/integrations/shimo.rb index 0e1023bb7a7..dd25a0bc558 100644 --- a/app/models/integrations/shimo.rb +++ b/app/models/integrations/shimo.rb @@ -1,12 +1,10 @@ # frozen_string_literal: true module Integrations - class Shimo < Integration + class Shimo < BaseThirdPartyWiki prop_accessor :external_wiki_url validates :external_wiki_url, presence: true, public_url: true, if: :activated? - after_commit :cache_project_has_shimo - def render? return false unless Feature.enabled?(:shimo_integration, project) @@ -33,10 +31,6 @@ module Integrations nil end - def self.supported_events - %w() - end - def fields [ { @@ -47,14 +41,5 @@ module Integrations } ] end - - private - - def cache_project_has_shimo - return unless project && !project.destroyed? - - project.project_setting.save! unless project.project_setting.persisted? - project.project_setting.update_column(:has_shimo, activated?) - end end end |