diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-15 03:07:30 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-15 03:07:30 +0300 |
commit | 34e729c8b959f9b639f51b9be494d84d118afeea (patch) | |
tree | 15d04ebdfc6a217b9953fc31524a18da72f955df /app | |
parent | f91842906eee49350acfe7ba95d60ccd459039de (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/graphql/mutations/saved_replies/base.rb | 8 | ||||
-rw-r--r-- | app/graphql/mutations/saved_replies/update.rb | 31 | ||||
-rw-r--r-- | app/graphql/types/mutation_type.rb | 1 | ||||
-rw-r--r-- | app/policies/user_policy.rb | 1 | ||||
-rw-r--r-- | app/services/users/saved_replies/update_service.rb | 26 |
5 files changed, 67 insertions, 0 deletions
diff --git a/app/graphql/mutations/saved_replies/base.rb b/app/graphql/mutations/saved_replies/base.rb index bc9723b76f7..468263b0f9d 100644 --- a/app/graphql/mutations/saved_replies/base.rb +++ b/app/graphql/mutations/saved_replies/base.rb @@ -26,6 +26,14 @@ module Mutations def feature_enabled? Feature.enabled?(:saved_replies, current_user, default_enabled: :yaml) end + + def find_object(id) + # TODO: remove this line when the compatibility layer is removed + # See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883 + id = ::Types::GlobalIDType[::Users::SavedReply].coerce_isolated_input(id) + + GitlabSchema.find_by_gid(id) + end end end end diff --git a/app/graphql/mutations/saved_replies/update.rb b/app/graphql/mutations/saved_replies/update.rb new file mode 100644 index 00000000000..bacc6ceb39e --- /dev/null +++ b/app/graphql/mutations/saved_replies/update.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module Mutations + module SavedReplies + class Update < Base + graphql_name 'SavedReplyUpdate' + + authorize :update_saved_replies + + argument :id, Types::GlobalIDType[::Users::SavedReply], + required: true, + description: copy_field_description(Types::SavedReplyType, :id) + + argument :name, GraphQL::Types::String, + required: true, + description: copy_field_description(Types::SavedReplyType, :name) + + argument :content, GraphQL::Types::String, + required: true, + description: copy_field_description(Types::SavedReplyType, :content) + + def resolve(id:, name:, content:) + raise Gitlab::Graphql::Errors::ResourceNotAvailable, 'Feature disabled' unless feature_enabled? + + saved_reply = authorized_find!(id) + result = ::Users::SavedReplies::UpdateService.new(current_user: current_user, saved_reply: saved_reply, name: name, content: content).execute + present_result(result) + end + end + end +end diff --git a/app/graphql/types/mutation_type.rb b/app/graphql/types/mutation_type.rb index 812104e0fd3..e6072820eea 100644 --- a/app/graphql/types/mutation_type.rb +++ b/app/graphql/types/mutation_type.rb @@ -130,6 +130,7 @@ module Types mount_mutation Mutations::WorkItems::Delete mount_mutation Mutations::WorkItems::Update mount_mutation Mutations::SavedReplies::Create + mount_mutation Mutations::SavedReplies::Update end end diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb index 115325803a1..de99cbffb6f 100644 --- a/app/policies/user_policy.rb +++ b/app/policies/user_policy.rb @@ -24,6 +24,7 @@ class UserPolicy < BasePolicy enable :update_user enable :update_user_status enable :create_saved_replies + enable :update_saved_replies enable :read_user_personal_access_tokens enable :read_group_count enable :read_user_groups diff --git a/app/services/users/saved_replies/update_service.rb b/app/services/users/saved_replies/update_service.rb new file mode 100644 index 00000000000..ab0a3eaf87d --- /dev/null +++ b/app/services/users/saved_replies/update_service.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module Users + module SavedReplies + class UpdateService + def initialize(current_user:, saved_reply:, name:, content:) + @current_user = current_user + @saved_reply = saved_reply + @name = name + @content = content + end + + def execute + if saved_reply.update(name: name, content: content) + ServiceResponse.success(payload: { saved_reply: saved_reply.reset }) + else + ServiceResponse.error(message: saved_reply.errors.full_messages) + end + end + + private + + attr_reader :current_user, :saved_reply, :name, :content + end + end +end |