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/finders/issuables')
-rw-r--r--app/finders/issuables/author_filter.rb41
-rw-r--r--app/finders/issuables/base_filter.rb36
2 files changed, 77 insertions, 0 deletions
diff --git a/app/finders/issuables/author_filter.rb b/app/finders/issuables/author_filter.rb
new file mode 100644
index 00000000000..ce68dbafb95
--- /dev/null
+++ b/app/finders/issuables/author_filter.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+module Issuables
+ class AuthorFilter < BaseFilter
+ def filter
+ filtered = by_author(issuables)
+ filtered = by_author_union(filtered)
+ by_negated_author(filtered)
+ end
+
+ private
+
+ def by_author(issuables)
+ if params[:author_id].present?
+ issuables.authored(params[:author_id])
+ elsif params[:author_username].present?
+ issuables.authored(User.by_username(params[:author_username]))
+ else
+ issuables
+ end
+ end
+
+ def by_author_union(issuables)
+ return issuables unless or_filters_enabled? && or_params&.fetch(:author_username).present?
+
+ issuables.authored(User.by_username(or_params[:author_username]))
+ end
+
+ def by_negated_author(issuables)
+ return issuables unless not_filters_enabled? && not_params.present?
+
+ if not_params[:author_id].present?
+ issuables.not_authored(not_params[:author_id])
+ elsif not_params[:author_username].present?
+ issuables.not_authored(User.by_username(not_params[:author_username]))
+ else
+ issuables
+ end
+ end
+ end
+end
diff --git a/app/finders/issuables/base_filter.rb b/app/finders/issuables/base_filter.rb
new file mode 100644
index 00000000000..641ae2568cc
--- /dev/null
+++ b/app/finders/issuables/base_filter.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+module Issuables
+ class BaseFilter
+ attr_reader :issuables, :params
+
+ def initialize(issuables, params:, or_filters_enabled: false, not_filters_enabled: false)
+ @issuables = issuables
+ @params = params
+ @or_filters_enabled = or_filters_enabled
+ @not_filters_enabled = not_filters_enabled
+ end
+
+ def filter
+ raise NotImplementedError
+ end
+
+ private
+
+ def or_params
+ params[:or]
+ end
+
+ def not_params
+ params[:not]
+ end
+
+ def or_filters_enabled?
+ @or_filters_enabled
+ end
+
+ def not_filters_enabled?
+ @not_filters_enabled
+ end
+ end
+end