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/onboarding_progress.rb')
-rw-r--r--app/models/onboarding_progress.rb26
1 files changed, 24 insertions, 2 deletions
diff --git a/app/models/onboarding_progress.rb b/app/models/onboarding_progress.rb
index 419bbd595e9..8a444f8934e 100644
--- a/app/models/onboarding_progress.rb
+++ b/app/models/onboarding_progress.rb
@@ -22,6 +22,24 @@ class OnboardingProgress < ApplicationRecord
:repository_mirrored
].freeze
+ scope :incomplete_actions, -> (actions) do
+ Array.wrap(actions).inject(self) { |scope, action| scope.where(column_name(action) => nil) }
+ end
+
+ scope :completed_actions, -> (actions) do
+ Array.wrap(actions).inject(self) { |scope, action| scope.where.not(column_name(action) => nil) }
+ end
+
+ scope :completed_actions_with_latest_in_range, -> (actions, range) do
+ actions = Array(actions)
+ if actions.size == 1
+ where(column_name(actions[0]) => range)
+ else
+ action_columns = actions.map { |action| arel_table[column_name(action)] }
+ completed_actions(actions).where(Arel::Nodes::NamedFunction.new('GREATEST', action_columns).between(range))
+ end
+ end
+
class << self
def onboard(namespace)
return unless root_namespace?(namespace)
@@ -29,6 +47,10 @@ class OnboardingProgress < ApplicationRecord
safe_find_or_create_by(namespace: namespace)
end
+ def onboarding?(namespace)
+ where(namespace: namespace).any?
+ end
+
def register(namespace, action)
return unless root_namespace?(namespace) && ACTIONS.include?(action)
@@ -44,12 +66,12 @@ class OnboardingProgress < ApplicationRecord
where(namespace: namespace).where.not(action_column => nil).exists?
end
- private
-
def column_name(action)
:"#{action}_at"
end
+ private
+
def root_namespace?(namespace)
namespace && namespace.root?
end