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:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-08-11 18:10:08 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-11 18:10:08 +0300
commit9dde2726710184f066387d044fce4ae2b3684210 (patch)
tree141da0dfc25da6b1724329a3d5cf2d51c7d45937 /app/services/award_emojis
parent03b5d94c2c145491bd493837ec50a36e5d1d2612 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/award_emojis')
-rw-r--r--app/services/award_emojis/copy_service.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/app/services/award_emojis/copy_service.rb b/app/services/award_emojis/copy_service.rb
new file mode 100644
index 00000000000..2e500d4c697
--- /dev/null
+++ b/app/services/award_emojis/copy_service.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+# This service copies AwardEmoji from one Awardable to another.
+#
+# It expects the calling code to have performed the necessary authorization
+# checks in order to allow the copy to happen.
+module AwardEmojis
+ class CopyService
+ def initialize(from_awardable, to_awardable)
+ raise ArgumentError, 'Awardables must be different' if from_awardable == to_awardable
+
+ @from_awardable = from_awardable
+ @to_awardable = to_awardable
+ end
+
+ def execute
+ from_awardable.award_emoji.find_each do |award|
+ new_award = award.dup
+ new_award.awardable = to_awardable
+ new_award.save!
+ end
+
+ ServiceResponse.success
+ end
+
+ private
+
+ attr_accessor :from_awardable, :to_awardable
+ end
+end