diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-15 06:10:30 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-15 06:10:30 +0300 |
commit | c9bdf919932b7285ef9920bdac955459340da8fe (patch) | |
tree | c133d05b5cb003de0c6bb2234afb884f6882ccd9 /app | |
parent | 8b75948934667904196aba319aedda25b00f06ff (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/snippets/components/snippet_header.vue | 7 | ||||
-rw-r--r-- | app/graphql/queries/snippet/snippet.query.graphql | 5 | ||||
-rw-r--r-- | app/helpers/application_helper.rb | 4 | ||||
-rw-r--r-- | app/helpers/tab_helper.rb | 3 | ||||
-rw-r--r-- | app/models/project.rb | 5 | ||||
-rw-r--r-- | app/models/project_services/alerts_service.rb | 84 | ||||
-rw-r--r-- | app/models/project_services/alerts_service_data.rb | 18 | ||||
-rw-r--r-- | app/models/service.rb | 1 | ||||
-rw-r--r-- | app/services/alert_management/sync_alert_service_data_service.rb | 56 | ||||
-rw-r--r-- | app/views/projects/services/alerts/_help.html.haml | 1 | ||||
-rw-r--r-- | app/views/projects/services/alerts/_top.html.haml | 8 |
11 files changed, 29 insertions, 163 deletions
diff --git a/app/assets/javascripts/snippets/components/snippet_header.vue b/app/assets/javascripts/snippets/components/snippet_header.vue index e65e55f6595..5ba62908b43 100644 --- a/app/assets/javascripts/snippets/components/snippet_header.vue +++ b/app/assets/javascripts/snippets/components/snippet_header.vue @@ -200,6 +200,13 @@ export default { <gl-avatar :size="24" :src="snippet.author.avatarUrl" /> <span class="bold">{{ snippet.author.name }}</span> </a> + <gl-emoji + v-if="snippet.author.status" + v-gl-tooltip + class="gl-vertical-align-baseline font-size-inherit gl-mr-1" + :title="snippet.author.status.message" + :data-name="snippet.author.status.emoji" + /> </template> </gl-sprintf> </div> diff --git a/app/graphql/queries/snippet/snippet.query.graphql b/app/graphql/queries/snippet/snippet.query.graphql index 2205dc26642..ebfc135c51c 100644 --- a/app/graphql/queries/snippet/snippet.query.graphql +++ b/app/graphql/queries/snippet/snippet.query.graphql @@ -59,6 +59,11 @@ query GetSnippetQuery($ids: [SnippetID!]) { name username webUrl + status { + __typename + emoji + message + } } } } diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f2a9a927ded..2a1652cf2ba 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -44,7 +44,7 @@ module ApplicationHelper # current_controller?('gitlab/application') # => false def current_controller?(*args) args.any? do |v| - v.to_s.downcase == controller.controller_name || v.to_s.downcase == controller.controller_path + Gitlab::Utils.safe_downcase!(v.to_s) == controller.controller_name || Gitlab::Utils.safe_downcase!(v.to_s) == controller.controller_path end end @@ -59,7 +59,7 @@ module ApplicationHelper # current_action?(:create) # => false # current_action?(:new, :create) # => true def current_action?(*args) - args.any? { |v| v.to_s.downcase == action_name } + args.any? { |v| Gitlab::Utils.safe_downcase!(v.to_s) == action_name } end def admin_section? diff --git a/app/helpers/tab_helper.rb b/app/helpers/tab_helper.rb index 6fbe2642056..e81986d4453 100644 --- a/app/helpers/tab_helper.rb +++ b/app/helpers/tab_helper.rb @@ -72,7 +72,8 @@ module TabHelper # Add our custom class into the html_options, which may or may not exist # and which may or may not already have a :class key o = options.delete(:html_options) || {} - o[:class] = [*o[:class], klass].join(' ').strip + o[:class] = [*o[:class], klass].join(' ') + o[:class].strip! if block_given? content_tag(:li, capture(&block), o) diff --git a/app/models/project.rb b/app/models/project.rb index b03dcde9f3f..0905815cec2 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -147,7 +147,6 @@ class Project < ApplicationRecord has_many :boards # Project services - has_one :alerts_service has_one :campfire_service has_one :datadog_service has_one :discord_service @@ -1357,9 +1356,9 @@ class Project < ApplicationRecord end def disabled_services - return ['datadog'] unless Feature.enabled?(:datadog_ci_integration, self) + return %w(datadog alerts) unless Feature.enabled?(:datadog_ci_integration, self) - [] + %w(alerts) end def find_or_initialize_service(name) diff --git a/app/models/project_services/alerts_service.rb b/app/models/project_services/alerts_service.rb index 58d507971ca..4afce0dfe95 100644 --- a/app/models/project_services/alerts_service.rb +++ b/app/models/project_services/alerts_service.rb @@ -1,54 +1,10 @@ # frozen_string_literal: true -require 'securerandom' - +# This service is scheduled for removal. All records must +# be deleted before the class can be removed. +# https://gitlab.com/groups/gitlab-org/-/epics/5056 class AlertsService < Service - has_one :data, class_name: 'AlertsServiceData', autosave: true, - inverse_of: :service, foreign_key: :service_id - - attribute :token, :string - delegate :token, :token=, :token_changed?, :token_was, to: :data - - validates :token, presence: true, if: :activated? - - before_validation :prevent_token_assignment - before_validation :ensure_token, if: :activated? - - after_save :update_http_integration - - def url - return if instance? || template? - - url_helpers.project_alerts_notify_url(project, format: :json) - end - - def json_fields - super + %w(token) - end - - def editable? - false - end - - def show_active_box? - false - end - - def can_test? - false - end - - def title - _('Alerts endpoint') - end - - def description - _('Authorize external services to send alerts to GitLab') - end - - def detailed_description - description - end + before_save :prevent_save def self.to_param 'alerts' @@ -58,33 +14,15 @@ class AlertsService < Service %w() end - def data - super || build_data - end - private - def prevent_token_assignment - self.token = token_was if token.present? && token_changed? - end - - def ensure_token - self.token = generate_token if token.blank? - end - - def generate_token - SecureRandom.hex - end - - def url_helpers - Gitlab::Routing.url_helpers - end - - def update_http_integration - return unless project_id && type == 'AlertsService' + def prevent_save + errors.add(:base, _('Alerts endpoint is deprecated and should not be created or modified. Use HTTP Integrations instead.')) + log_error('Prevented attempt to save or update deprecated AlertsService') - AlertManagement::SyncAlertServiceDataService # rubocop: disable CodeReuse/ServiceClass - .new(self) - .execute + # Stops execution of callbacks and database operation while + # preserving expectations of #save (will not raise) & #save! (raises) + # https://guides.rubyonrails.org/active_record_callbacks.html#halting-execution + throw :abort # rubocop:disable Cop/BanCatchThrow end end diff --git a/app/models/project_services/alerts_service_data.rb b/app/models/project_services/alerts_service_data.rb deleted file mode 100644 index 827a4ef613a..00000000000 --- a/app/models/project_services/alerts_service_data.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -require 'securerandom' - -class AlertsServiceData < ApplicationRecord - belongs_to :service, class_name: 'AlertsService' - - validates :service, presence: true - - attr_encrypted :token, - mode: :per_attribute_iv, - key: Settings.attr_encrypted_db_key_base_truncated, - algorithm: 'aes-256-gcm' - - def token_changed? - attribute_changed?(:token) - end -end diff --git a/app/models/service.rb b/app/models/service.rb index 9f17279d0a3..e5626462dd3 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -19,7 +19,6 @@ class Service < ApplicationRecord PROJECT_SPECIFIC_SERVICE_NAMES = %w[ jenkins - alerts ].freeze # Fake services to help with local development. diff --git a/app/services/alert_management/sync_alert_service_data_service.rb b/app/services/alert_management/sync_alert_service_data_service.rb deleted file mode 100644 index 1ba197065c5..00000000000 --- a/app/services/alert_management/sync_alert_service_data_service.rb +++ /dev/null @@ -1,56 +0,0 @@ -# frozen_string_literal: true - -module AlertManagement - class SyncAlertServiceDataService - # @param alert_service [AlertsService] - def initialize(alert_service) - @alert_service = alert_service - end - - def execute - http_integration = find_http_integration - - result = if http_integration - update_integration_data(http_integration) - else - create_integration - end - - result ? ServiceResponse.success : ServiceResponse.error(message: 'Update failed') - end - - private - - attr_reader :alert_service - - def find_http_integration - AlertManagement::HttpIntegrationsFinder.new( - alert_service.project, - endpoint_identifier: ::AlertManagement::HttpIntegration::LEGACY_IDENTIFIER - ) - .execute - .first - end - - def create_integration - new_integration = AlertManagement::HttpIntegration.create( - project_id: alert_service.project_id, - name: 'HTTP endpoint', - endpoint_identifier: AlertManagement::HttpIntegration::LEGACY_IDENTIFIER, - active: alert_service.active, - encrypted_token: alert_service.data.encrypted_token, - encrypted_token_iv: alert_service.data.encrypted_token_iv - ) - - new_integration.persisted? - end - - def update_integration_data(http_integration) - http_integration.update( - active: alert_service.active, - encrypted_token: alert_service.data.encrypted_token, - encrypted_token_iv: alert_service.data.encrypted_token_iv - ) - end - end -end diff --git a/app/views/projects/services/alerts/_help.html.haml b/app/views/projects/services/alerts/_help.html.haml deleted file mode 100644 index 7abd198bea5..00000000000 --- a/app/views/projects/services/alerts/_help.html.haml +++ /dev/null @@ -1 +0,0 @@ -.js-alerts-service-settings{ data: alerts_settings_data(disabled: true) } diff --git a/app/views/projects/services/alerts/_top.html.haml b/app/views/projects/services/alerts/_top.html.haml deleted file mode 100644 index e3bcb6bd3a0..00000000000 --- a/app/views/projects/services/alerts/_top.html.haml +++ /dev/null @@ -1,8 +0,0 @@ -.row - .col-lg-12 - .gl-alert.gl-alert-info{ role: 'alert' } - = sprite_icon('information-o', css_class: 'gl-icon gl-alert-icon gl-alert-icon-no-title') - .gl-alert-body - = _('You can now manage alert endpoint configuration in the Alerts section on the Operations settings page. Fields on this page have been deprecated.') - .gl-alert-actions - = link_to _('Visit settings page'), project_settings_operations_path(@project, anchor: 'js-alert-management-settings'), class: 'btn gl-alert-action btn-info new-gl-button' |