Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ci/build.rb8
-rw-r--r--app/models/namespace.rb2
-rw-r--r--app/models/namespace_onboarding_action.rb36
-rw-r--r--app/models/onboarding_progress.rb65
4 files changed, 68 insertions, 43 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index efe5789e49a..e9128252eb2 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -389,12 +389,8 @@ module Ci
end
after_transition any => [:skipped, :canceled] do |build, transition|
- if Feature.enabled?(:cd_skipped_deployment_status, build.project)
- if transition.to_name == :skipped
- build.deployment&.skip
- else
- build.deployment&.cancel
- end
+ if transition.to_name == :skipped
+ build.deployment&.skip
else
build.deployment&.cancel
end
diff --git a/app/models/namespace.rb b/app/models/namespace.rb
index 02ea8948419..6f7b377ee52 100644
--- a/app/models/namespace.rb
+++ b/app/models/namespace.rb
@@ -28,7 +28,7 @@ class Namespace < ApplicationRecord
has_many :runner_namespaces, inverse_of: :namespace, class_name: 'Ci::RunnerNamespace'
has_many :runners, through: :runner_namespaces, source: :runner, class_name: 'Ci::Runner'
- has_many :namespace_onboarding_actions
+ has_one :onboarding_progress
# This should _not_ be `inverse_of: :namespace`, because that would also set
# `user.namespace` when this user creates a group with themselves as `owner`.
diff --git a/app/models/namespace_onboarding_action.rb b/app/models/namespace_onboarding_action.rb
deleted file mode 100644
index 2b0d6cad02d..00000000000
--- a/app/models/namespace_onboarding_action.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-# frozen_string_literal: true
-
-class NamespaceOnboardingAction < ApplicationRecord
- belongs_to :namespace, optional: false
-
- validates :action, presence: true
-
- ACTIONS = {
- subscription_created: 1,
- git_write: 2,
- merge_request_created: 3,
- git_read: 4,
- pipeline_created: 5,
- user_added: 6
- }.freeze
-
- # The monitoring window prevents the recording of a namespace_onboarding_action if a namespace is created before this
- # time span. We are not interested in older namspaces, because the purpose of this table is to monitor and act on the
- # progress of newly created namespaces or namespaces that already have at least one recorded action.
- MONITORING_WINDOW = 90.days
-
- enum action: ACTIONS
-
- class << self
- def completed?(namespace, action)
- where(namespace: namespace, action: action).exists?
- end
-
- def create_action(namespace, action)
- return unless namespace.root?
- return if namespace.created_at < MONITORING_WINDOW.ago && !namespace.namespace_onboarding_actions.exists?
-
- NamespaceOnboardingAction.safe_find_or_create_by(namespace: namespace, action: action)
- end
- end
-end
diff --git a/app/models/onboarding_progress.rb b/app/models/onboarding_progress.rb
new file mode 100644
index 00000000000..419bbd595e9
--- /dev/null
+++ b/app/models/onboarding_progress.rb
@@ -0,0 +1,65 @@
+# frozen_string_literal: true
+
+class OnboardingProgress < ApplicationRecord
+ belongs_to :namespace, optional: false
+
+ validate :namespace_is_root_namespace
+
+ ACTIONS = [
+ :git_pull,
+ :git_write,
+ :merge_request_created,
+ :pipeline_created,
+ :user_added,
+ :trial_started,
+ :subscription_created,
+ :required_mr_approvals_enabled,
+ :code_owners_enabled,
+ :scoped_label_created,
+ :security_scan_enabled,
+ :issue_auto_closed,
+ :repository_imported,
+ :repository_mirrored
+ ].freeze
+
+ class << self
+ def onboard(namespace)
+ return unless root_namespace?(namespace)
+
+ safe_find_or_create_by(namespace: namespace)
+ end
+
+ def register(namespace, action)
+ return unless root_namespace?(namespace) && ACTIONS.include?(action)
+
+ action_column = column_name(action)
+ onboarding_progress = find_by(namespace: namespace, action_column => nil)
+ onboarding_progress&.update!(action_column => Time.current)
+ end
+
+ def completed?(namespace, action)
+ return unless root_namespace?(namespace) && ACTIONS.include?(action)
+
+ action_column = column_name(action)
+ where(namespace: namespace).where.not(action_column => nil).exists?
+ end
+
+ private
+
+ def column_name(action)
+ :"#{action}_at"
+ end
+
+ def root_namespace?(namespace)
+ namespace && namespace.root?
+ end
+ end
+
+ private
+
+ def namespace_is_root_namespace
+ return unless namespace
+
+ errors.add(:namespace, _('must be a root namespace')) if namespace.has_parent?
+ end
+end