Commit f5f26f0b authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Add None / Any options to reaction filter in issues / MRs API

parent 31733b6f
...@@ -244,15 +244,6 @@ class IssuableFinder ...@@ -244,15 +244,6 @@ class IssuableFinder
params[:assignee_username].present? params[:assignee_username].present?
end end
def filter_by_no_assignee?
# Assignee_id takes precedence over assignee_username
[NONE, FILTER_NONE].include?(params[:assignee_id].to_s.downcase) || params[:assignee_username].to_s == NONE
end
def filter_by_any_assignee?
params[:assignee_id].to_s.downcase == FILTER_ANY
end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def assignee def assignee
return @assignee if defined?(@assignee) return @assignee if defined?(@assignee)
...@@ -418,6 +409,15 @@ class IssuableFinder ...@@ -418,6 +409,15 @@ class IssuableFinder
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def filter_by_no_assignee?
# Assignee_id takes precedence over assignee_username
[NONE, FILTER_NONE].include?(params[:assignee_id].to_s.downcase) || params[:assignee_username].to_s == NONE
end
def filter_by_any_assignee?
params[:assignee_id].to_s.downcase == FILTER_ANY
end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def by_author(items) def by_author(items)
if author if author
...@@ -480,12 +480,26 @@ class IssuableFinder ...@@ -480,12 +480,26 @@ class IssuableFinder
def by_my_reaction_emoji(items) def by_my_reaction_emoji(items)
if params[:my_reaction_emoji].present? && current_user if params[:my_reaction_emoji].present? && current_user
if filter_by_no_reaction?
items = items.not_awarded(current_user)
elsif filter_by_any_reaction?
items = items.awarded_any(current_user)
else
items = items.awarded(current_user, params[:my_reaction_emoji]) items = items.awarded(current_user, params[:my_reaction_emoji])
end end
end
items items
end end
def filter_by_no_reaction?
params[:my_reaction_emoji].to_s.downcase == FILTER_NONE
end
def filter_by_any_reaction?
params[:my_reaction_emoji].to_s.downcase == FILTER_ANY
end
def label_names def label_names
if labels? if labels?
params[:label_name].is_a?(String) ? params[:label_name].split(',') : params[:label_name] params[:label_name].is_a?(String) ? params[:label_name].split(',') : params[:label_name]
......
...@@ -28,6 +28,34 @@ module Awardable ...@@ -28,6 +28,34 @@ module Awardable
where(sql, user_id: user.id, name: name, awardable_type: self.name) where(sql, user_id: user.id, name: name, awardable_type: self.name)
end end
def awarded_any(user)
sql = <<~EOL
EXISTS (
SELECT TRUE
FROM award_emoji
WHERE user_id = :user_id AND
awardable_type = :awardable_type AND
awardable_id = #{self.arel_table.name}.id
)
EOL
where(sql, user_id: user.id, awardable_type: self.name)
end
def not_awarded(user)
sql = <<~EOL
NOT EXISTS (
SELECT TRUE
FROM award_emoji
WHERE user_id = :user_id AND
awardable_type = :awardable_type AND
awardable_id = #{self.arel_table.name}.id
)
EOL
where(sql, user_id: user.id, awardable_type: self.name)
end
def order_upvotes_desc def order_upvotes_desc
order_votes_desc(AwardEmoji::UPVOTE_NAME) order_votes_desc(AwardEmoji::UPVOTE_NAME)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment