summaryrefslogtreecommitdiff
path: root/app/graphql/mutations/award_emojis/remove.rb
diff options
context:
space:
mode:
authorLuke Duncalfe <lduncalfe@eml.cc>2019-06-21 16:45:27 +1200
committerLuke Duncalfe <lduncalfe@eml.cc>2019-06-28 12:03:33 +1200
commit4b9b2a43d02fc5154f780ade7fe76c02420fff15 (patch)
tree6ada662de1b913c6d265a554d5702c8a68788fae /app/graphql/mutations/award_emojis/remove.rb
parent62a40c5170cbecfc77dcb5fc97a23f3e93898a53 (diff)
downloadgitlab-ce-4b9b2a43d02fc5154f780ade7fe76c02420fff15.tar.gz
GraphQL mutations for add, remove and toggle emoji62826-graphql-emoji-mutations
Adding new `AddAwardEmoji`, `RemoveAwardEmoji` and `ToggleAwardEmoji` GraphQL mutations. Adding new `#authorized_find_with_pre_checks!` and (unused, but for completeness `#authorized_find_with_post_checks!`) authorization methods. These allow us to perform an authorized find, and run our own additional checks before or after the authorization runs. https://gitlab.com/gitlab-org/gitlab-ce/issues/62826
Diffstat (limited to 'app/graphql/mutations/award_emojis/remove.rb')
-rw-r--r--app/graphql/mutations/award_emojis/remove.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/app/graphql/mutations/award_emojis/remove.rb b/app/graphql/mutations/award_emojis/remove.rb
new file mode 100644
index 00000000000..3ba85e445b8
--- /dev/null
+++ b/app/graphql/mutations/award_emojis/remove.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Mutations
+ module AwardEmojis
+ class Remove < Base
+ graphql_name 'RemoveAwardEmoji'
+
+ def resolve(args)
+ awardable = authorized_find!(id: args[:awardable_id])
+
+ check_object_is_awardable!(awardable)
+
+ # TODO this check can be removed once AwardEmoji services are available.
+ # See https://gitlab.com/gitlab-org/gitlab-ce/issues/63372 and
+ # https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/29782
+ unless awardable.awarded_emoji?(args[:name], current_user)
+ raise Gitlab::Graphql::Errors::ResourceNotAvailable,
+ 'You have not awarded emoji of type name to the awardable'
+ end
+
+ # TODO this will be handled by AwardEmoji::DestroyService
+ # See https://gitlab.com/gitlab-org/gitlab-ce/issues/63372 and
+ # https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/29782
+ awardable.remove_award_emoji(args[:name], current_user)
+
+ {
+ # Mutation response is always a `nil` award_emoji
+ errors: []
+ }
+ end
+ end
+ end
+end