summaryrefslogtreecommitdiff
path: root/app/finders/concerns
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2021-01-20 13:34:23 -0600
committerRobert Speicher <rspeicher@gmail.com>2021-01-20 13:34:23 -0600
commit6438df3a1e0fb944485cebf07976160184697d72 (patch)
tree00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /app/finders/concerns
parent42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff)
downloadgitlab-ce-6438df3a1e0fb944485cebf07976160184697d72.tar.gz
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'app/finders/concerns')
-rw-r--r--app/finders/concerns/finder_methods.rb2
-rw-r--r--app/finders/concerns/packages/finder_helper.rb29
-rw-r--r--app/finders/concerns/time_frame_filter.rb2
3 files changed, 31 insertions, 2 deletions
diff --git a/app/finders/concerns/finder_methods.rb b/app/finders/concerns/finder_methods.rb
index 622cbcf4928..193b52b1694 100644
--- a/app/finders/concerns/finder_methods.rb
+++ b/app/finders/concerns/finder_methods.rb
@@ -22,7 +22,7 @@ module FinderMethods
def raise_not_found_unless_authorized(result)
result = if_authorized(result)
- raise ActiveRecord::RecordNotFound.new("Couldn't find #{model}") unless result
+ raise(ActiveRecord::RecordNotFound, "Couldn't find #{model}") unless result
result
end
diff --git a/app/finders/concerns/packages/finder_helper.rb b/app/finders/concerns/packages/finder_helper.rb
new file mode 100644
index 00000000000..524e7aa7ff9
--- /dev/null
+++ b/app/finders/concerns/packages/finder_helper.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+module Packages
+ module FinderHelper
+ extend ActiveSupport::Concern
+
+ private
+
+ def packages_visible_to_user(user, within_group:)
+ return ::Packages::Package.none unless within_group
+ return ::Packages::Package.none unless Ability.allowed?(user, :read_package, within_group)
+
+ projects = projects_visible_to_reporters(user, within_group.self_and_descendants.select(:id))
+ ::Packages::Package.for_projects(projects.select(:id))
+ end
+
+ def projects_visible_to_user(user, within_group:)
+ return ::Project.none unless within_group
+ return ::Project.none unless Ability.allowed?(user, :read_package, within_group)
+
+ projects_visible_to_reporters(user, within_group.self_and_descendants.select(:id))
+ end
+
+ def projects_visible_to_reporters(user, namespace_ids)
+ ::Project.in_namespace(namespace_ids)
+ .public_or_visible_to_user(user, ::Gitlab::Access::REPORTER)
+ end
+ end
+end
diff --git a/app/finders/concerns/time_frame_filter.rb b/app/finders/concerns/time_frame_filter.rb
index d1ebed730f6..7412bea340e 100644
--- a/app/finders/concerns/time_frame_filter.rb
+++ b/app/finders/concerns/time_frame_filter.rb
@@ -2,7 +2,7 @@
module TimeFrameFilter
def by_timeframe(items)
- return items unless params[:start_date] && params[:start_date]
+ return items unless params[:start_date] && params[:end_date]
start_date = params[:start_date].to_date
end_date = params[:end_date].to_date