diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
commit | 4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch) | |
tree | 5423a1c7516cffe36384133ade12572cf709398d /lib/api/helpers/award_emoji.rb | |
parent | e570267f2f6b326480d284e0164a6464ba4081bc (diff) |
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'lib/api/helpers/award_emoji.rb')
-rw-r--r-- | lib/api/helpers/award_emoji.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/api/helpers/award_emoji.rb b/lib/api/helpers/award_emoji.rb new file mode 100644 index 00000000000..5b659c4dde7 --- /dev/null +++ b/lib/api/helpers/award_emoji.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +module API + module Helpers + module AwardEmoji + def self.awardables + [ + { type: 'issue', resource: :projects, find_by: :iid, feature_category: :issue_tracking }, + { type: 'merge_request', resource: :projects, find_by: :iid, feature_category: :code_review }, + { type: 'snippet', resource: :projects, find_by: :id, feature_category: :snippets } + ] + end + + def self.awardable_id_desc + "The ID of an Issue, Merge Request or Snippet" + end + + # rubocop: disable CodeReuse/ActiveRecord + def awardable + @awardable ||= + begin + if params.include?(:note_id) + note_id = params.delete(:note_id) + + awardable.notes.find(note_id) + elsif params.include?(:issue_iid) + user_project.issues.find_by!(iid: params[:issue_iid]) + elsif params.include?(:merge_request_iid) + user_project.merge_requests.find_by!(iid: params[:merge_request_iid]) + elsif params.include?(:snippet_id) + user_project.snippets.find(params[:snippet_id]) + end + end + end + # rubocop: enable CodeReuse/ActiveRecord + end + end +end + +API::Helpers::AwardEmoji.prepend_mod_with('API::Helpers::AwardEmoji') |