summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-07-06 00:13:01 +0900
committerShinya Maeda <shinya@gitlab.com>2017-07-06 16:34:20 +0900
commit0fa8f4d45da1312b8461864b47ecc80780423519 (patch)
treebe1fa1c9dfa0e9a624092ec0a4a898e0856f6945
parent4eeae7fd8654869c54c7fa0481dc8bf73e5a2d9b (diff)
downloadgitlab-ce-0fa8f4d45da1312b8461864b47ecc80780423519.tar.gz
secret_variables_for: rails readability versino
-rw-r--r--app/models/group.rb16
1 files changed, 5 insertions, 11 deletions
diff --git a/app/models/group.rb b/app/models/group.rb
index 7a608974177..3939d712c94 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -250,17 +250,11 @@ class Group < Namespace
end
def secret_variables_for(ref, project)
- list_of_ids = ([self] + ancestors).map { |l| l.id }
-
- order = list_of_ids.map.with_index do |id, index|
- "WHEN #{id} THEN #{index}"
- end.join("\n")
-
- variables = Ci::GroupVariable
- .where("group_id IN (#{list_of_ids.join(", ")})")
- .order("CASE group_id #{order} END DESC")
-
- project.protected_for?(ref) ? variables : variables.unprotected
+ list_of_ids = [self] + ancestors
+ variables = Ci::GroupVariable.where(group: list_of_ids)
+ variables = variables.unprotected unless project.protected_for?(ref)
+ variables = variables.group_by(&:group_id)
+ list_of_ids.reverse.map { |group| variables[group.id] }.compact.flatten
end
protected