diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-12 18:09:37 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-12 18:09:37 +0300 |
commit | 2c89e169769ead722394a79ed67fcd08e96863dd (patch) | |
tree | 0dadb576846c484475b895f75fab41f71cdb952e /app/models | |
parent | bd497e352ebd279536ae11855871162e82a3f88c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/container_repository.rb | 6 | ||||
-rw-r--r-- | app/models/project.rb | 5 | ||||
-rw-r--r-- | app/models/project_services/alerts_service.rb | 78 | ||||
-rw-r--r-- | app/models/project_services/alerts_service_data.rb | 14 |
4 files changed, 102 insertions, 1 deletions
diff --git a/app/models/container_repository.rb b/app/models/container_repository.rb index 152aa7b3218..fcbfda8fbc2 100644 --- a/app/models/container_repository.rb +++ b/app/models/container_repository.rb @@ -77,7 +77,11 @@ class ContainerRepository < ApplicationRecord end def delete_tag_by_digest(digest) - client.delete_repository_tag(self.path, digest) + client.delete_repository_tag_by_digest(self.path, digest) + end + + def delete_tag_by_name(name) + client.delete_repository_tag_by_name(self.path, name) end def self.build_from_path(path) diff --git a/app/models/project.rb b/app/models/project.rb index 44701ef792a..b2ac9c99ab6 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -138,6 +138,7 @@ class Project < ApplicationRecord has_many :boards # Project services + has_one :alerts_service has_one :campfire_service has_one :discord_service has_one :drone_ci_service @@ -2330,6 +2331,10 @@ class Project < ApplicationRecord protected_branches.limit(limit) end + def alerts_service_activated? + false + end + private def closest_namespace_setting(name) diff --git a/app/models/project_services/alerts_service.rb b/app/models/project_services/alerts_service.rb new file mode 100644 index 00000000000..2f7902d9617 --- /dev/null +++ b/app/models/project_services/alerts_service.rb @@ -0,0 +1,78 @@ +# frozen_string_literal: true + +require 'securerandom' + +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? + + def url + 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 + _('Receive alerts on GitLab from any source') + end + + def detailed_description + description + end + + def self.to_param + 'alerts' + end + + def self.supported_events + %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 +end diff --git a/app/models/project_services/alerts_service_data.rb b/app/models/project_services/alerts_service_data.rb new file mode 100644 index 00000000000..5a52ed83455 --- /dev/null +++ b/app/models/project_services/alerts_service_data.rb @@ -0,0 +1,14 @@ +# 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' +end |