diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-31 00:09:38 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-31 00:09:38 +0300 |
commit | dd8c199e989482245c58ee49b5f7169bdd9073eb (patch) | |
tree | f70b1255763d003e855f9ea3dd73a6c14e2010ff /app/models | |
parent | cd99e8611a6df11975c227517892606440ad3ff6 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/abuse_report.rb | 4 | ||||
-rw-r--r-- | app/models/analytics/usage_trends/measurement.rb | 4 | ||||
-rw-r--r-- | app/models/application_record.rb | 6 | ||||
-rw-r--r-- | app/models/application_setting_implementation.rb | 16 | ||||
-rw-r--r-- | app/models/audit_event.rb | 8 | ||||
-rw-r--r-- | app/models/award_emoji.rb | 4 | ||||
-rw-r--r-- | app/models/board.rb | 2 | ||||
-rw-r--r-- | app/models/ci/application_record.rb | 2 | ||||
-rw-r--r-- | app/models/ci/bridge.rb | 4 | ||||
-rw-r--r-- | app/models/ci/build.rb | 28 | ||||
-rw-r--r-- | app/models/ci/build_metadata.rb | 2 | ||||
-rw-r--r-- | app/models/ci/build_runner_session.rb | 4 | ||||
-rw-r--r-- | app/models/ci/build_trace_chunk.rb | 8 | ||||
-rw-r--r-- | app/models/ci/deleted_object.rb | 2 | ||||
-rw-r--r-- | app/models/clusters/applications/cert_manager.rb | 129 | ||||
-rw-r--r-- | app/models/clusters/cluster.rb | 2 | ||||
-rw-r--r-- | app/models/ml/experiment.rb | 6 |
17 files changed, 53 insertions, 178 deletions
diff --git a/app/models/abuse_report.rb b/app/models/abuse_report.rb index be9d49ab4e2..dbcdfa5e946 100644 --- a/app/models/abuse_report.rb +++ b/app/models/abuse_report.rb @@ -72,9 +72,9 @@ class AbuseReport < ApplicationRecord end def notify - return unless self.persisted? + return unless persisted? - AbuseReportMailer.notify(self.id).deliver_later + AbuseReportMailer.notify(id).deliver_later end private diff --git a/app/models/analytics/usage_trends/measurement.rb b/app/models/analytics/usage_trends/measurement.rb index c1245d8dce7..ddadaf78c8f 100644 --- a/app/models/analytics/usage_trends/measurement.rb +++ b/app/models/analytics/usage_trends/measurement.rb @@ -24,8 +24,8 @@ module Analytics scope :order_by_latest, -> { order(recorded_at: :desc) } scope :with_identifier, ->(identifier) { where(identifier: identifier) } - scope :recorded_after, ->(date) { where(self.model.arel_table[:recorded_at].gteq(date)) if date.present? } - scope :recorded_before, ->(date) { where(self.model.arel_table[:recorded_at].lteq(date)) if date.present? } + scope :recorded_after, ->(date) { where(model.arel_table[:recorded_at].gteq(date)) if date.present? } + scope :recorded_before, ->(date) { where(model.arel_table[:recorded_at].lteq(date)) if date.present? } def self.identifier_query_mapping { diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 198a3653cd3..291375f647c 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -36,7 +36,7 @@ class ApplicationRecord < ActiveRecord::Base end def self.pluck_primary_key - where(nil).pluck(self.primary_key) + where(nil).pluck(primary_key) end def self.safe_ensure_unique(retries: 0) @@ -95,7 +95,7 @@ class ApplicationRecord < ActiveRecord::Base end def self.underscore - Gitlab::SafeRequestStore.fetch("model:#{self}:underscore") { self.to_s.underscore } + Gitlab::SafeRequestStore.fetch("model:#{self}:underscore") { to_s.underscore } end def self.where_exists(query) @@ -111,7 +111,7 @@ class ApplicationRecord < ActiveRecord::Base end def self.cached_column_list - self.column_names.map { |column_name| self.arel_table[column_name] } + column_names.map { |column_name| arel_table[column_name] } end def self.default_select_columns diff --git a/app/models/application_setting_implementation.rb b/app/models/application_setting_implementation.rb index f13b2143cd3..db2c053d12c 100644 --- a/app/models/application_setting_implementation.rb +++ b/app/models/application_setting_implementation.rb @@ -303,11 +303,11 @@ module ApplicationSettingImplementation end def domain_allowlist_raw - array_to_string(self.domain_allowlist) + array_to_string(domain_allowlist) end def domain_denylist_raw - array_to_string(self.domain_denylist) + array_to_string(domain_denylist) end def domain_allowlist_raw=(values) @@ -323,7 +323,7 @@ module ApplicationSettingImplementation end def outbound_local_requests_allowlist_raw - array_to_string(self.outbound_local_requests_whitelist) + array_to_string(outbound_local_requests_whitelist) end def outbound_local_requests_allowlist_raw=(values) @@ -356,7 +356,7 @@ module ApplicationSettingImplementation end def protected_paths_raw - array_to_string(self.protected_paths) + array_to_string(protected_paths) end def protected_paths_raw=(values) @@ -364,7 +364,7 @@ module ApplicationSettingImplementation end def notes_create_limit_allowlist_raw - array_to_string(self.notes_create_limit_allowlist) + array_to_string(notes_create_limit_allowlist) end def notes_create_limit_allowlist_raw=(values) @@ -372,7 +372,7 @@ module ApplicationSettingImplementation end def users_get_by_id_limit_allowlist_raw - array_to_string(self.users_get_by_id_limit_allowlist) + array_to_string(users_get_by_id_limit_allowlist) end def users_get_by_id_limit_allowlist_raw=(values) @@ -536,7 +536,7 @@ module ApplicationSettingImplementation def set_max_key_restriction!(key_type) attr_name = "#{key_type}_key_restriction" - current = self.attributes[attr_name].to_i + current = attributes[attr_name].to_i return if current == KeyRestrictionValidator::FORBIDDEN @@ -549,7 +549,7 @@ module ApplicationSettingImplementation [min_size, current].max end - self.assign_attributes({ attr_name => new_value }) + assign_attributes({ attr_name => new_value }) end def separate_allowlists(string_array) diff --git a/app/models/audit_event.rb b/app/models/audit_event.rb index 5cc87be388f..0c75f6e8b0b 100644 --- a/app/models/audit_event.rb +++ b/app/models/audit_event.rb @@ -55,7 +55,7 @@ class AuditEvent < ApplicationRecord end def initialize_details - return unless self.has_attribute?(:details) + return unless has_attribute?(:details) self.details = {} if details&.nil? end @@ -82,7 +82,7 @@ class AuditEvent < ApplicationRecord def as_json(options = {}) super(options).tap do |json| - json['ip_address'] = self.ip_address.to_s + json['ip_address'] = ip_address.to_s end end @@ -114,10 +114,10 @@ class AuditEvent < ApplicationRecord def parallel_persist PARALLEL_PERSISTENCE_COLUMNS.each do |name| - original = self[name] || self.details[name] + original = self[name] || details[name] next unless original - self[name] = self.details[name] = original + self[name] = details[name] = original end end diff --git a/app/models/award_emoji.rb b/app/models/award_emoji.rb index f41f0a8be84..dbc5c7a584e 100644 --- a/app/models/award_emoji.rb +++ b/app/models/award_emoji.rb @@ -55,11 +55,11 @@ class AwardEmoji < ApplicationRecord end def downvote? - self.name == DOWNVOTE_NAME + name == DOWNVOTE_NAME end def upvote? - self.name == UPVOTE_NAME + name == UPVOTE_NAME end def url diff --git a/app/models/board.rb b/app/models/board.rb index 8a7330e7320..2181b2f0545 100644 --- a/app/models/board.rb +++ b/app/models/board.rb @@ -18,7 +18,7 @@ class Board < ApplicationRecord # Sort by case-insensitive name, then ascending ids. This ensures that we will always # get the same list/first board no matter how many other boards are named the same scope :order_by_name_asc, -> { order(arel_table[:name].lower.asc).order(id: :asc) } - scope :first_board, -> { where(id: self.order_by_name_asc.limit(1).select(:id)) } + scope :first_board, -> { where(id: order_by_name_asc.limit(1).select(:id)) } def project_needed? !group diff --git a/app/models/ci/application_record.rb b/app/models/ci/application_record.rb index ea7b1104e36..52f02bfb2fd 100644 --- a/app/models/ci/application_record.rb +++ b/app/models/ci/application_record.rb @@ -13,7 +13,7 @@ module Ci end def self.model_name - @model_name ||= ActiveModel::Name.new(self, nil, self.name.demodulize) + @model_name ||= ActiveModel::Name.new(self, nil, name.demodulize) end end end diff --git a/app/models/ci/bridge.rb b/app/models/ci/bridge.rb index 54daff7dbda..697f06fbffd 100644 --- a/app/models/ci/bridge.rb +++ b/app/models/ci/bridge.rb @@ -80,9 +80,9 @@ module Ci def inherit_status_from_downstream!(pipeline) case pipeline.status when 'success' - self.success! + success! when 'failed', 'canceled', 'skipped' - self.drop! + drop! else false end diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index ec3aa9d70be..214880f5833 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -386,21 +386,21 @@ module Ci def detailed_status(current_user) Gitlab::Ci::Status::Build::Factory - .new(self.present, current_user) + .new(present, current_user) .fabricate! end def other_manual_actions - pipeline.manual_actions.reject { |action| action.name == self.name } + pipeline.manual_actions.reject { |action| action.name == name } end def other_scheduled_actions - pipeline.scheduled_actions.reject { |action| action.name == self.name } + pipeline.scheduled_actions.reject { |action| action.name == name } end def pages_generator? Gitlab.config.pages.enabled && - self.name == 'pages' + name == 'pages' end def runnable? @@ -456,7 +456,7 @@ module Ci end def retries_count - pipeline.builds.retried.where(name: self.name).count + pipeline.builds.retried.where(name: name).count end override :all_met_to_become_pending? @@ -529,19 +529,19 @@ module Ci end def deployment_job? - has_environment_keyword? && self.environment_action == 'start' + has_environment_keyword? && environment_action == 'start' end def stops_environment? - has_environment_keyword? && self.environment_action == 'stop' + has_environment_keyword? && environment_action == 'stop' end def environment_action - self.options.fetch(:environment, {}).fetch(:action, 'start') if self.options + options.fetch(:environment, {}).fetch(:action, 'start') if options end def environment_tier_from_options - self.options.dig(:environment, :deployment_tier) if self.options + options.dig(:environment, :deployment_tier) if options end def environment_tier @@ -831,7 +831,7 @@ module Ci end def erased? - !self.erased_at.nil? + !erased_at.nil? end def artifacts_expired? @@ -864,8 +864,8 @@ module Ci end def keep_artifacts! - self.update(artifacts_expire_at: nil) - self.job_artifacts.update_all(expire_at: nil) + update(artifacts_expire_at: nil) + job_artifacts.update_all(expire_at: nil) end def artifacts_file_for_type(type) @@ -1096,11 +1096,11 @@ module Ci # without actually loading data. # def all_queuing_entries - ::Ci::PendingBuild.where(build_id: self.id) + ::Ci::PendingBuild.where(build_id: id) end def all_runtime_metadata - ::Ci::RunningBuild.where(build_id: self.id) + ::Ci::RunningBuild.where(build_id: id) end def shared_runner_build? diff --git a/app/models/ci/build_metadata.rb b/app/models/ci/build_metadata.rb index 5c8ac2adb8d..b294afd405d 100644 --- a/app/models/ci/build_metadata.rb +++ b/app/models/ci/build_metadata.rb @@ -68,7 +68,7 @@ module Ci private def set_build_project - self.project_id ||= self.build.project_id + self.project_id ||= build.project_id end def timeout_with_highest_precedence diff --git a/app/models/ci/build_runner_session.rb b/app/models/ci/build_runner_session.rb index 20c0b04e228..5773b6132be 100644 --- a/app/models/ci/build_runner_session.rb +++ b/app/models/ci/build_runner_session.rb @@ -20,7 +20,7 @@ module Ci validates :url, public_url: { schemes: %w(https) } def terminal_specification - wss_url = Gitlab::UrlHelpers.as_wss(Addressable::URI.escape(self.url)) + wss_url = Gitlab::UrlHelpers.as_wss(Addressable::URI.escape(url)) return {} unless wss_url.present? parsed_wss_url = URI.parse(wss_url) @@ -33,7 +33,7 @@ module Ci port = port.presence || DEFAULT_PORT_NAME service = service.presence || DEFAULT_SERVICE_NAME - parsed_url = URI.parse(Addressable::URI.escape(self.url)) + parsed_url = URI.parse(Addressable::URI.escape(url)) parsed_url.path += "/proxy/#{service}/#{port}/#{path}" subprotocols = subprotocols.presence || ::Ci::BuildRunnerSession::TERMINAL_SUBPROTOCOL diff --git a/app/models/ci/build_trace_chunk.rb b/app/models/ci/build_trace_chunk.rb index c5f6e54c336..541a8b5bffa 100644 --- a/app/models/ci/build_trace_chunk.rb +++ b/app/models/ci/build_trace_chunk.rb @@ -108,7 +108,7 @@ module Ci raise ArgumentError, 'Offset is out of range' if offset > size || offset < 0 return if offset == size # Skip the following process as it doesn't affect anything - self.append(+"", offset) + append(+"", offset) end def append(new_data, offset) @@ -166,7 +166,7 @@ module Ci raise FailedToPersistDataError, 'Modifed build trace chunk detected' if has_changes_to_save? self.class.with_read_consistency(build) do - self.reset.then(&:unsafe_persist_data!) + reset.then(&:unsafe_persist_data!) end end rescue FailedToObtainLockError @@ -205,9 +205,9 @@ module Ci end def <=>(other) - return unless self.build_id == other.build_id + return unless build_id == other.build_id - self.chunk_index <=> other.chunk_index + chunk_index <=> other.chunk_index end protected diff --git a/app/models/ci/deleted_object.rb b/app/models/ci/deleted_object.rb index d36646aba66..2b5452c803a 100644 --- a/app/models/ci/deleted_object.rb +++ b/app/models/ci/deleted_object.rb @@ -21,7 +21,7 @@ module Ci accumulator << record if record[:store_dir] && record[:file] end - self.insert_all(attributes) if attributes.any? + insert_all(attributes) if attributes.any? end def delete_file_from_storage diff --git a/app/models/clusters/applications/cert_manager.rb b/app/models/clusters/applications/cert_manager.rb deleted file mode 100644 index 11f84940c38..00000000000 --- a/app/models/clusters/applications/cert_manager.rb +++ /dev/null @@ -1,129 +0,0 @@ -# frozen_string_literal: true - -module Clusters - module Applications - # DEPRECATED for removal in %14.0 - # See https://gitlab.com/groups/gitlab-org/-/epics/4280 - class CertManager < ApplicationRecord - VERSION = 'v0.10.1' - CRD_VERSION = '0.10' - - self.table_name = 'clusters_applications_cert_managers' - - include ::Clusters::Concerns::ApplicationCore - include ::Clusters::Concerns::ApplicationStatus - include ::Clusters::Concerns::ApplicationVersion - include ::Clusters::Concerns::ApplicationData - - attribute :version, default: VERSION - after_initialize :set_default_email, if: :new_record? - - validates :email, presence: true - - def chart - 'certmanager/cert-manager' - end - - def repository - 'https://charts.jetstack.io' - end - - def install_command - helm_command_module::InstallCommand.new( - name: 'certmanager', - repository: repository, - version: VERSION, - rbac: cluster.platform_kubernetes_rbac?, - chart: chart, - files: files.merge(cluster_issuer_file), - preinstall: pre_install_script, - postinstall: post_install_script - ) - end - - def uninstall_command - helm_command_module::DeleteCommand.new( - name: 'certmanager', - rbac: cluster.platform_kubernetes_rbac?, - files: files, - postdelete: post_delete_script - ) - end - - private - - def set_default_email - self.email ||= self.cluster&.user&.email - end - - def pre_install_script - [ - apply_file("https://raw.githubusercontent.com/jetstack/cert-manager/release-#{CRD_VERSION}/deploy/manifests/00-crds.yaml"), - "kubectl label --overwrite namespace #{Gitlab::Kubernetes::Helm::NAMESPACE} certmanager.k8s.io/disable-validation=true" - ] - end - - def post_install_script - [retry_command(apply_file('/data/helm/certmanager/config/cluster_issuer.yaml'))] - end - - def retry_command(command) - Gitlab::Kubernetes::PodCmd.retry_command(command, times: 90) - end - - def post_delete_script - [ - delete_private_key, - delete_crd('certificates.certmanager.k8s.io'), - delete_crd('certificaterequests.certmanager.k8s.io'), - delete_crd('challenges.certmanager.k8s.io'), - delete_crd('clusterissuers.certmanager.k8s.io'), - delete_crd('issuers.certmanager.k8s.io'), - delete_crd('orders.certmanager.k8s.io') - ].compact - end - - def private_key_name - @private_key_name ||= cluster_issuer_content.dig('spec', 'acme', 'privateKeySecretRef', 'name') - end - - def delete_private_key - return unless private_key_name.present? - - args = %W(secret -n #{Gitlab::Kubernetes::Helm::NAMESPACE} #{private_key_name} --ignore-not-found) - - Gitlab::Kubernetes::KubectlCmd.delete(*args) - end - - def delete_crd(definition) - Gitlab::Kubernetes::KubectlCmd.delete("crd", definition, "--ignore-not-found") - end - - def apply_file(filename) - Gitlab::Kubernetes::KubectlCmd.apply_file(filename) - end - - def cluster_issuer_file - { - 'cluster_issuer.yaml': cluster_issuer_yaml_content - } - end - - def cluster_issuer_yaml_content - YAML.dump(cluster_issuer_content.deep_merge(cluster_issue_overlay)) - end - - def cluster_issuer_content - YAML.safe_load(File.read(cluster_issuer_file_path)) - end - - def cluster_issue_overlay - { "spec" => { "acme" => { "email" => self.email } } } - end - - def cluster_issuer_file_path - Rails.root.join('vendor', 'cert_manager', 'cluster_issuer.yaml') - end - end - end -end diff --git a/app/models/clusters/cluster.rb b/app/models/clusters/cluster.rb index 55dbaf9c6b7..a35ea6ddb46 100644 --- a/app/models/clusters/cluster.rb +++ b/app/models/clusters/cluster.rb @@ -14,7 +14,6 @@ module Clusters APPLICATIONS = { Clusters::Applications::Helm.application_name => Clusters::Applications::Helm, Clusters::Applications::Ingress.application_name => Clusters::Applications::Ingress, - Clusters::Applications::CertManager.application_name => Clusters::Applications::CertManager, Clusters::Applications::Crossplane.application_name => Clusters::Applications::Crossplane, Clusters::Applications::Prometheus.application_name => Clusters::Applications::Prometheus, Clusters::Applications::Runner.application_name => Clusters::Applications::Runner, @@ -57,7 +56,6 @@ module Clusters has_one_cluster_application :helm has_one_cluster_application :ingress - has_one_cluster_application :cert_manager has_one_cluster_application :crossplane has_one_cluster_application :prometheus has_one_cluster_application :runner diff --git a/app/models/ml/experiment.rb b/app/models/ml/experiment.rb index 0a326b0e005..7bb80a170c5 100644 --- a/app/models/ml/experiment.rb +++ b/app/models/ml/experiment.rb @@ -12,6 +12,12 @@ module Ml has_many :candidates, class_name: 'Ml::Candidate' has_many :metadata, class_name: 'Ml::ExperimentMetadata' + scope :with_candidate_count, -> { + left_outer_joins(:candidates) + .select("ml_experiments.*, count(ml_candidates.id) as candidate_count") + .group(:id) + } + has_internal_id :iid, scope: :project class << self |