summaryrefslogtreecommitdiff
path: root/app/finders
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-08 00:09:30 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-08 00:09:30 +0000
commit060c842402c00f830a810702600cbe39dfa6cf62 (patch)
tree743bd65ac0c1d4d6518ae8cdd4af5718ec7fb890 /app/finders
parent6867eff1f997a881cd3ea64109f7ba2d4b42fde4 (diff)
downloadgitlab-ce-060c842402c00f830a810702600cbe39dfa6cf62.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/finders')
-rw-r--r--app/finders/environments_finder.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/finders/environments_finder.rb b/app/finders/environments_finder.rb
index 32942c46208..32ca1a42db7 100644
--- a/app/finders/environments_finder.rb
+++ b/app/finders/environments_finder.rb
@@ -3,6 +3,8 @@
class EnvironmentsFinder
attr_reader :project, :current_user, :params
+ InvalidStatesError = Class.new(StandardError)
+
def initialize(project, current_user, params = {})
@project, @current_user, @params = project, current_user, params
end
@@ -45,6 +47,9 @@ class EnvironmentsFinder
environments = by_name(environments)
environments = by_search(environments)
+ # Raises InvalidStatesError if params[:states] contains invalid states.
+ environments = by_states(environments)
+
environments
end
@@ -91,4 +96,27 @@ class EnvironmentsFinder
environments
end
end
+
+ def by_states(environments)
+ if params[:states].present?
+ environments_with_states(environments)
+ else
+ environments
+ end
+ end
+
+ def environments_with_states(environments)
+ # Convert to array of strings
+ states = Array(params[:states]).map(&:to_s)
+
+ raise InvalidStatesError, _('Requested states are invalid') unless valid_states?(states)
+
+ environments.with_states(states)
+ end
+
+ def valid_states?(states)
+ valid_states = Environment.valid_states.map(&:to_s)
+
+ (states - valid_states).empty?
+ end
end