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:
authorHeinrich Lee Yu <hleeyu@gmail.com>2018-10-27 05:52:06 +0300
committerHeinrich Lee Yu <hleeyu@gmail.com>2018-11-01 02:45:36 +0300
commitf5f26f0bf7b2a2fc178e60a472731f8cfa540d75 (patch)
tree102ecf8b30d7e846299991b4ea330f712534c2e8 /app/models/concerns/awardable.rb
parent31733b6fc5a9ba4443a5dd279e787e2fd8e31c6d (diff)
Add None / Any options to reaction filter in issues / MRs API
Diffstat (limited to 'app/models/concerns/awardable.rb')
-rw-r--r--app/models/concerns/awardable.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/models/concerns/awardable.rb b/app/models/concerns/awardable.rb
index 6f29c92d176..25b14eb110c 100644
--- a/app/models/concerns/awardable.rb
+++ b/app/models/concerns/awardable.rb
@@ -28,6 +28,34 @@ module Awardable
where(sql, user_id: user.id, name: name, awardable_type: self.name)
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
order_votes_desc(AwardEmoji::UPVOTE_NAME)
end