diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /app/graphql/mutations | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) | |
download | gitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'app/graphql/mutations')
42 files changed, 354 insertions, 122 deletions
diff --git a/app/graphql/mutations/alert_management/base.rb b/app/graphql/mutations/alert_management/base.rb index 81d5ee95f06..8c6b4005cf8 100644 --- a/app/graphql/mutations/alert_management/base.rb +++ b/app/graphql/mutations/alert_management/base.rb @@ -11,7 +11,7 @@ module Mutations argument :iid, GraphQL::STRING_TYPE, required: true, - description: "The iid of the alert to mutate" + description: "The IID of the alert to mutate" field :alert, Types::AlertManagement::AlertType, diff --git a/app/graphql/mutations/alert_management/create_alert_issue.rb b/app/graphql/mutations/alert_management/create_alert_issue.rb index 2ddb94700c2..2c128e1b339 100644 --- a/app/graphql/mutations/alert_management/create_alert_issue.rb +++ b/app/graphql/mutations/alert_management/create_alert_issue.rb @@ -10,6 +10,7 @@ module Mutations result = create_alert_issue(alert, current_user) track_usage_event(:incident_management_incident_created, current_user.id) + track_usage_event(:incident_management_alert_create_incident, current_user.id) prepare_response(alert, result) end diff --git a/app/graphql/mutations/alert_management/http_integration/destroy.rb b/app/graphql/mutations/alert_management/http_integration/destroy.rb index 0f478760aab..45d4bd778da 100644 --- a/app/graphql/mutations/alert_management/http_integration/destroy.rb +++ b/app/graphql/mutations/alert_management/http_integration/destroy.rb @@ -8,7 +8,7 @@ module Mutations argument :id, Types::GlobalIDType[::AlertManagement::HttpIntegration], required: true, - description: "The id of the integration to remove" + description: "The ID of the integration to remove" def resolve(id:) integration = authorized_find!(id: id) diff --git a/app/graphql/mutations/alert_management/http_integration/reset_token.rb b/app/graphql/mutations/alert_management/http_integration/reset_token.rb index eefab156825..3938b38260e 100644 --- a/app/graphql/mutations/alert_management/http_integration/reset_token.rb +++ b/app/graphql/mutations/alert_management/http_integration/reset_token.rb @@ -8,7 +8,7 @@ module Mutations argument :id, Types::GlobalIDType[::AlertManagement::HttpIntegration], required: true, - description: "The id of the integration to mutate" + description: "The ID of the integration to mutate" def resolve(id:) integration = authorized_find!(id: id) diff --git a/app/graphql/mutations/alert_management/http_integration/update.rb b/app/graphql/mutations/alert_management/http_integration/update.rb index 309c45b04ac..98e0f7eb14f 100644 --- a/app/graphql/mutations/alert_management/http_integration/update.rb +++ b/app/graphql/mutations/alert_management/http_integration/update.rb @@ -8,7 +8,7 @@ module Mutations argument :id, Types::GlobalIDType[::AlertManagement::HttpIntegration], required: true, - description: "The id of the integration to mutate" + description: "The ID of the integration to mutate" argument :name, GraphQL::STRING_TYPE, required: false, diff --git a/app/graphql/mutations/alert_management/prometheus_integration/reset_token.rb b/app/graphql/mutations/alert_management/prometheus_integration/reset_token.rb index 745ac51f6e3..effecd8364d 100644 --- a/app/graphql/mutations/alert_management/prometheus_integration/reset_token.rb +++ b/app/graphql/mutations/alert_management/prometheus_integration/reset_token.rb @@ -8,7 +8,7 @@ module Mutations argument :id, Types::GlobalIDType[::PrometheusService], required: true, - description: "The id of the integration to mutate" + description: "The ID of the integration to mutate" def resolve(id:) integration = authorized_find!(id: id) diff --git a/app/graphql/mutations/alert_management/prometheus_integration/update.rb b/app/graphql/mutations/alert_management/prometheus_integration/update.rb index 1f0dea119c5..46f4c23b739 100644 --- a/app/graphql/mutations/alert_management/prometheus_integration/update.rb +++ b/app/graphql/mutations/alert_management/prometheus_integration/update.rb @@ -8,7 +8,7 @@ module Mutations argument :id, Types::GlobalIDType[::PrometheusService], required: true, - description: "The id of the integration to mutate" + description: "The ID of the integration to mutate" argument :active, GraphQL::BOOLEAN_TYPE, required: false, diff --git a/app/graphql/mutations/award_emojis/add.rb b/app/graphql/mutations/award_emojis/add.rb index 856fdd5fb14..e7ee2ec4fad 100644 --- a/app/graphql/mutations/award_emojis/add.rb +++ b/app/graphql/mutations/award_emojis/add.rb @@ -8,8 +8,6 @@ module Mutations def resolve(args) awardable = authorized_find!(id: args[:awardable_id]) - check_object_is_awardable!(awardable) - service = ::AwardEmojis::AddService.new(awardable, args[:name], current_user).execute { diff --git a/app/graphql/mutations/award_emojis/base.rb b/app/graphql/mutations/award_emojis/base.rb index df6b883529e..4bd8304c3fc 100644 --- a/app/graphql/mutations/award_emojis/base.rb +++ b/app/graphql/mutations/award_emojis/base.rb @@ -3,12 +3,16 @@ module Mutations module AwardEmojis class Base < BaseMutation + include ::Mutations::FindsByGid + + NOT_EMOJI_AWARDABLE = 'You cannot award emoji to this resource.' + authorize :award_emoji argument :awardable_id, ::Types::GlobalIDType[::Awardable], required: true, - description: 'The global id of the awardable resource' + description: 'The global ID of the awardable resource' argument :name, GraphQL::STRING_TYPE, @@ -22,20 +26,15 @@ module Mutations private + # TODO: remove this method when the compatibility layer is removed + # See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883 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[::Awardable].coerce_isolated_input(id) - GitlabSchema.find_by_gid(id) + super(id: ::Types::GlobalIDType[::Awardable].coerce_isolated_input(id)) end - # Called by mutations methods after performing an authorization check - # of an awardable object. - def check_object_is_awardable!(object) - unless object.is_a?(Awardable) && object.emoji_awardable? - raise Gitlab::Graphql::Errors::ResourceNotAvailable, - 'Cannot award emoji to this resource' - end + def authorize!(object) + super + raise_resource_not_available_error!(NOT_EMOJI_AWARDABLE) unless object.emoji_awardable? end end end diff --git a/app/graphql/mutations/award_emojis/remove.rb b/app/graphql/mutations/award_emojis/remove.rb index c654688c6dc..a9655daeea7 100644 --- a/app/graphql/mutations/award_emojis/remove.rb +++ b/app/graphql/mutations/award_emojis/remove.rb @@ -8,8 +8,6 @@ module Mutations def resolve(args) awardable = authorized_find!(id: args[:awardable_id]) - check_object_is_awardable!(awardable) - service = ::AwardEmojis::DestroyService.new(awardable, args[:name], current_user).execute { diff --git a/app/graphql/mutations/award_emojis/toggle.rb b/app/graphql/mutations/award_emojis/toggle.rb index 679ec7a14ff..e741f972b1b 100644 --- a/app/graphql/mutations/award_emojis/toggle.rb +++ b/app/graphql/mutations/award_emojis/toggle.rb @@ -12,8 +12,6 @@ module Mutations def resolve(args) awardable = authorized_find!(id: args[:awardable_id]) - check_object_is_awardable!(awardable) - service = ::AwardEmojis::ToggleService.new(awardable, args[:name], current_user).execute toggled_on = awardable.awarded_emoji?(args[:name], current_user) diff --git a/app/graphql/mutations/boards/common_mutation_arguments.rb b/app/graphql/mutations/boards/common_mutation_arguments.rb new file mode 100644 index 00000000000..c4f8d299318 --- /dev/null +++ b/app/graphql/mutations/boards/common_mutation_arguments.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Mutations + module Boards + module CommonMutationArguments + extend ActiveSupport::Concern + + included do + argument :name, + GraphQL::STRING_TYPE, + required: false, + description: 'The board name.' + argument :hide_backlog_list, + GraphQL::BOOLEAN_TYPE, + required: false, + description: copy_field_description(Types::BoardType, :hide_backlog_list) + argument :hide_closed_list, + GraphQL::BOOLEAN_TYPE, + required: false, + description: copy_field_description(Types::BoardType, :hide_closed_list) + end + end + end +end diff --git a/app/graphql/mutations/boards/create.rb b/app/graphql/mutations/boards/create.rb index ebbd19930ec..92bce557446 100644 --- a/app/graphql/mutations/boards/create.rb +++ b/app/graphql/mutations/boards/create.rb @@ -7,36 +7,18 @@ module Mutations graphql_name 'CreateBoard' + include Mutations::Boards::CommonMutationArguments + field :board, Types::BoardType, null: true, description: 'The board after mutation.' - argument :name, - GraphQL::STRING_TYPE, - required: false, - description: 'The board name.' - argument :assignee_id, - GraphQL::STRING_TYPE, - required: false, - description: 'The ID of the user to be assigned to the board.' - argument :milestone_id, - Types::GlobalIDType[Milestone], - required: false, - description: 'The ID of the milestone to be assigned to the board.' - argument :weight, - GraphQL::BOOLEAN_TYPE, - required: false, - description: 'The weight of the board.' - argument :label_ids, - [Types::GlobalIDType[Label]], - required: false, - description: 'The IDs of labels to be added to the board.' - authorize :admin_board def resolve(args) board_parent = authorized_resource_parent_find!(args) + response = ::Boards::CreateService.new(board_parent, current_user, args).execute { @@ -47,3 +29,5 @@ module Mutations end end end + +Mutations::Boards::Create.prepend_if_ee('::EE::Mutations::Boards::Create') diff --git a/app/graphql/mutations/boards/lists/create.rb b/app/graphql/mutations/boards/lists/create.rb index 3fe1052315f..f6df63365b2 100644 --- a/app/graphql/mutations/boards/lists/create.rb +++ b/app/graphql/mutations/boards/lists/create.rb @@ -27,30 +27,16 @@ module Mutations board = authorized_find!(id: args[:board_id]) params = create_list_params(args) - authorize_list_type_resource!(board, params) - - list = create_list(board, params) + response = create_list(board, params) { - list: list.valid? ? list : nil, - errors: errors_on_object(list) + list: response.success? ? response.payload[:list] : nil, + errors: response.errors } end private - # Overridden in EE - def authorize_list_type_resource!(board, params) - return unless params[:label_id] - - labels = ::Labels::AvailableLabelsService.new(current_user, board.resource_parent, params) - .filter_labels_ids_in_param(:label_id) - - unless labels.present? - raise Gitlab::Graphql::Errors::ArgumentError, 'Label not found!' - end - end - def create_list(board, params) create_list_service = ::Boards::Lists::CreateService.new(board.resource_parent, current_user, params) diff --git a/app/graphql/mutations/boards/update.rb b/app/graphql/mutations/boards/update.rb new file mode 100644 index 00000000000..5cb434e41fd --- /dev/null +++ b/app/graphql/mutations/boards/update.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +module Mutations + module Boards + class Update < ::Mutations::BaseMutation + graphql_name 'UpdateBoard' + + include Mutations::Boards::CommonMutationArguments + + argument :id, + ::Types::GlobalIDType[::Board], + required: true, + description: 'The board global ID.' + + field :board, + Types::BoardType, + null: true, + description: 'The board after mutation.' + + authorize :admin_board + + def resolve(id:, **args) + board = authorized_find!(id: id) + + ::Boards::UpdateService.new(board.resource_parent, current_user, args).execute(board) + + { + board: board, + errors: errors_on_object(board) + } + 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[::Board].coerce_isolated_input(id) + GitlabSchema.find_by_gid(id) + end + end + end +end + +Mutations::Boards::Update.prepend_if_ee('::EE::Mutations::Boards::Update') diff --git a/app/graphql/mutations/ci/base.rb b/app/graphql/mutations/ci/base.rb index aaece2a3021..0ccee5661b7 100644 --- a/app/graphql/mutations/ci/base.rb +++ b/app/graphql/mutations/ci/base.rb @@ -7,7 +7,7 @@ module Mutations argument :id, PipelineID, required: true, - description: 'The id of the pipeline to mutate' + description: 'The ID of the pipeline to mutate' private diff --git a/app/graphql/mutations/concerns/mutations/finds_by_gid.rb b/app/graphql/mutations/concerns/mutations/finds_by_gid.rb new file mode 100644 index 00000000000..157f87a413d --- /dev/null +++ b/app/graphql/mutations/concerns/mutations/finds_by_gid.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module Mutations + module FindsByGid + def find_object(id:) + GitlabSchema.find_by_gid(id) + end + end +end diff --git a/app/graphql/mutations/container_repositories/destroy.rb b/app/graphql/mutations/container_repositories/destroy.rb index 8312193147f..90fba66e7b3 100644 --- a/app/graphql/mutations/container_repositories/destroy.rb +++ b/app/graphql/mutations/container_repositories/destroy.rb @@ -2,9 +2,7 @@ module Mutations module ContainerRepositories - class Destroy < Mutations::BaseMutation - include ::Mutations::PackageEventable - + class Destroy < ::Mutations::ContainerRepositories::DestroyBase graphql_name 'DestroyContainerRepository' authorize :destroy_container_image @@ -31,15 +29,6 @@ module Mutations errors: [] } end - - private - - 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[::ContainerRepository].coerce_isolated_input(id) - GitlabSchema.find_by_gid(id) - end end end end diff --git a/app/graphql/mutations/container_repositories/destroy_base.rb b/app/graphql/mutations/container_repositories/destroy_base.rb new file mode 100644 index 00000000000..ddaa6c52121 --- /dev/null +++ b/app/graphql/mutations/container_repositories/destroy_base.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Mutations + module ContainerRepositories + class DestroyBase < Mutations::BaseMutation + include ::Mutations::PackageEventable + + private + + 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[::ContainerRepository].coerce_isolated_input(id) + GitlabSchema.find_by_gid(id) + end + end + end +end diff --git a/app/graphql/mutations/container_repositories/destroy_tags.rb b/app/graphql/mutations/container_repositories/destroy_tags.rb new file mode 100644 index 00000000000..ca6a67867c3 --- /dev/null +++ b/app/graphql/mutations/container_repositories/destroy_tags.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +module Mutations + module ContainerRepositories + class DestroyTags < ::Mutations::ContainerRepositories::DestroyBase + LIMIT = 20.freeze + + TOO_MANY_TAGS_ERROR_MESSAGE = "Number of tags is greater than #{LIMIT}" + + graphql_name 'DestroyContainerRepositoryTags' + + authorize :destroy_container_image + + argument :id, + ::Types::GlobalIDType[::ContainerRepository], + required: true, + description: 'ID of the container repository.' + + argument :tag_names, + [GraphQL::STRING_TYPE], + required: true, + description: "Container repository tag(s) to delete. Total number can't be greater than #{LIMIT}", + prepare: ->(tag_names, _) do + raise Gitlab::Graphql::Errors::ArgumentError, TOO_MANY_TAGS_ERROR_MESSAGE if tag_names.size > LIMIT + + tag_names + end + + field :deleted_tag_names, + [GraphQL::STRING_TYPE], + description: 'Deleted container repository tags', + null: false + + def resolve(id:, tag_names:) + container_repository = authorized_find!(id: id) + + result = ::Projects::ContainerRepository::DeleteTagsService + .new(container_repository.project, current_user, tags: tag_names) + .execute(container_repository) + + track_event(:delete_tag_bulk, :tag) if result[:status] == :success + + { + errors: Array(result[:message]), + deleted_tag_names: result[:deleted] || [] + } + end + end + end +end diff --git a/app/graphql/mutations/design_management/base.rb b/app/graphql/mutations/design_management/base.rb index 918e5709b94..69fd22e46cd 100644 --- a/app/graphql/mutations/design_management/base.rb +++ b/app/graphql/mutations/design_management/base.rb @@ -11,7 +11,7 @@ module Mutations argument :iid, GraphQL::ID_TYPE, required: true, - description: "The iid of the issue to modify designs for" + description: "The IID of the issue to modify designs for" private diff --git a/app/graphql/mutations/discussions/toggle_resolve.rb b/app/graphql/mutations/discussions/toggle_resolve.rb index 4492da74706..0e3baf8d548 100644 --- a/app/graphql/mutations/discussions/toggle_resolve.rb +++ b/app/graphql/mutations/discussions/toggle_resolve.rb @@ -10,7 +10,7 @@ module Mutations argument :id, Types::GlobalIDType[Discussion], required: true, - description: 'The global id of the discussion' + description: 'The global ID of the discussion' argument :resolve, GraphQL::BOOLEAN_TYPE, diff --git a/app/graphql/mutations/environments/canary_ingress/update.rb b/app/graphql/mutations/environments/canary_ingress/update.rb new file mode 100644 index 00000000000..1798143053a --- /dev/null +++ b/app/graphql/mutations/environments/canary_ingress/update.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +module Mutations + module Environments + module CanaryIngress + class Update < ::Mutations::BaseMutation + graphql_name 'EnvironmentsCanaryIngressUpdate' + + authorize :update_environment + + argument :id, + ::Types::GlobalIDType[::Environment], + required: true, + description: 'The global ID of the environment to update' + + argument :weight, + GraphQL::INT_TYPE, + required: true, + description: 'The weight of the Canary Ingress' + + def resolve(id:, **kwargs) + environment = authorized_find!(id: id) + + result = ::Environments::CanaryIngress::UpdateService + .new(environment.project, current_user, kwargs) + .execute_async(environment) + + { errors: Array.wrap(result[:message]) } + end + + def find_object(id:) + # TODO: remove as part of https://gitlab.com/gitlab-org/gitlab/-/issues/257883 + id = ::Types::GlobalIDType[::Environment].coerce_isolated_input(id) + GitlabSchema.find_by_gid(id) + end + end + end + end +end diff --git a/app/graphql/mutations/issues/update.rb b/app/graphql/mutations/issues/update.rb index 9b216b31f9b..d34e351b2a6 100644 --- a/app/graphql/mutations/issues/update.rb +++ b/app/graphql/mutations/issues/update.rb @@ -11,7 +11,7 @@ module Mutations required: false, description: copy_field_description(Types::IssueType, :title) - argument :milestone_id, GraphQL::ID_TYPE, + argument :milestone_id, GraphQL::ID_TYPE, # rubocop: disable Graphql/IDType required: false, description: 'The ID of the milestone to assign to the issue. On update milestone will be removed if set to null' diff --git a/app/graphql/mutations/merge_requests/base.rb b/app/graphql/mutations/merge_requests/base.rb index 96228855ace..57920259cf7 100644 --- a/app/graphql/mutations/merge_requests/base.rb +++ b/app/graphql/mutations/merge_requests/base.rb @@ -11,7 +11,7 @@ module Mutations argument :iid, GraphQL::STRING_TYPE, required: true, - description: "The iid of the merge request to mutate" + description: "The IID of the merge request to mutate" field :merge_request, Types::MergeRequestType, diff --git a/app/graphql/mutations/metrics/dashboard/annotations/create.rb b/app/graphql/mutations/metrics/dashboard/annotations/create.rb index b064f55825f..c2ec88c68ed 100644 --- a/app/graphql/mutations/metrics/dashboard/annotations/create.rb +++ b/app/graphql/mutations/metrics/dashboard/annotations/create.rb @@ -20,12 +20,12 @@ module Mutations argument :environment_id, ::Types::GlobalIDType[::Environment], required: false, - description: 'The global id of the environment to add an annotation to' + description: 'The global ID of the environment to add an annotation to' argument :cluster_id, ::Types::GlobalIDType[::Clusters::Cluster], required: false, - description: 'The global id of the cluster to add an annotation to' + description: 'The global ID of the cluster to add an annotation to' argument :starting_at, Types::TimeType, required: true, diff --git a/app/graphql/mutations/metrics/dashboard/annotations/delete.rb b/app/graphql/mutations/metrics/dashboard/annotations/delete.rb index d6731dfcafd..5d6763d8711 100644 --- a/app/graphql/mutations/metrics/dashboard/annotations/delete.rb +++ b/app/graphql/mutations/metrics/dashboard/annotations/delete.rb @@ -11,7 +11,7 @@ module Mutations argument :id, ::Types::GlobalIDType[::Metrics::Dashboard::Annotation], required: true, - description: 'The global ID of the annotation to delete' + description: 'Global ID of the annotation to delete' def resolve(id:) annotation = authorized_find!(id: id) diff --git a/app/graphql/mutations/notes/create/base.rb b/app/graphql/mutations/notes/create/base.rb index 3cfdaf84760..a1d81c62d91 100644 --- a/app/graphql/mutations/notes/create/base.rb +++ b/app/graphql/mutations/notes/create/base.rb @@ -11,7 +11,7 @@ module Mutations argument :noteable_id, ::Types::GlobalIDType[::Noteable], required: true, - description: 'The global id of the resource to add a note to' + description: 'The global ID of the resource to add a note to' argument :body, GraphQL::STRING_TYPE, diff --git a/app/graphql/mutations/notes/create/note.rb b/app/graphql/mutations/notes/create/note.rb index e97037171f7..f1cd3bddca8 100644 --- a/app/graphql/mutations/notes/create/note.rb +++ b/app/graphql/mutations/notes/create/note.rb @@ -9,7 +9,7 @@ module Mutations argument :discussion_id, ::Types::GlobalIDType[::Discussion], required: false, - description: 'The global id of the discussion this note is in reply to' + description: 'The global ID of the discussion this note is in reply to' private diff --git a/app/graphql/mutations/notes/destroy.rb b/app/graphql/mutations/notes/destroy.rb index 63e5eeb5ecf..0e6a215bf00 100644 --- a/app/graphql/mutations/notes/destroy.rb +++ b/app/graphql/mutations/notes/destroy.rb @@ -10,7 +10,7 @@ module Mutations argument :id, ::Types::GlobalIDType[::Note], required: true, - description: 'The global id of the note to destroy' + description: 'The global ID of the note to destroy' def resolve(id:) note = authorized_find!(id: id) diff --git a/app/graphql/mutations/notes/reposition_image_diff_note.rb b/app/graphql/mutations/notes/reposition_image_diff_note.rb index 0d88bcd9a30..15bfb361b13 100644 --- a/app/graphql/mutations/notes/reposition_image_diff_note.rb +++ b/app/graphql/mutations/notes/reposition_image_diff_note.rb @@ -16,7 +16,7 @@ module Mutations loads: Types::Notes::NoteType, as: :note, required: true, - description: 'The global id of the DiffNote to update' + description: 'The global ID of the DiffNote to update' argument :position, Types::Notes::UpdateDiffImagePositionInputType, diff --git a/app/graphql/mutations/notes/update/base.rb b/app/graphql/mutations/notes/update/base.rb index 1d5738ada77..42dac20f5d3 100644 --- a/app/graphql/mutations/notes/update/base.rb +++ b/app/graphql/mutations/notes/update/base.rb @@ -11,7 +11,7 @@ module Mutations argument :id, ::Types::GlobalIDType[::Note], required: true, - description: 'The global id of the note to update' + description: 'The global ID of the note to update' def resolve(args) note = authorized_find!(id: args[:id]) diff --git a/app/graphql/mutations/releases/create.rb b/app/graphql/mutations/releases/create.rb index 57c1541c368..156cd252848 100644 --- a/app/graphql/mutations/releases/create.rb +++ b/app/graphql/mutations/releases/create.rb @@ -40,12 +40,11 @@ module Mutations authorize :create_release - def resolve(project_path:, milestones: nil, assets: nil, **scalars) + def resolve(project_path:, assets: nil, **scalars) project = authorized_find!(full_path: project_path) params = { **scalars, - milestones: milestones.presence || [], assets: assets.to_h }.with_indifferent_access diff --git a/app/graphql/mutations/releases/delete.rb b/app/graphql/mutations/releases/delete.rb new file mode 100644 index 00000000000..e887b702cce --- /dev/null +++ b/app/graphql/mutations/releases/delete.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +module Mutations + module Releases + class Delete < Base + graphql_name 'ReleaseDelete' + + field :release, + Types::ReleaseType, + null: true, + description: 'The deleted release.' + + argument :tag_name, GraphQL::STRING_TYPE, + required: true, as: :tag, + description: 'Name of the tag associated with the release to delete.' + + authorize :destroy_release + + def resolve(project_path:, tag:) + project = authorized_find!(full_path: project_path) + + params = { tag: tag }.with_indifferent_access + + result = ::Releases::DestroyService.new(project, current_user, params).execute + + if result[:status] == :success + { + release: result[:release], + errors: [] + } + else + { + release: nil, + errors: [result[:message]] + } + end + end + end + end +end diff --git a/app/graphql/mutations/releases/update.rb b/app/graphql/mutations/releases/update.rb new file mode 100644 index 00000000000..bf72b907679 --- /dev/null +++ b/app/graphql/mutations/releases/update.rb @@ -0,0 +1,70 @@ +# frozen_string_literal: true + +module Mutations + module Releases + class Update < Base + graphql_name 'ReleaseUpdate' + + field :release, + Types::ReleaseType, + null: true, + description: 'The release after mutation.' + + argument :tag_name, GraphQL::STRING_TYPE, + required: true, as: :tag, + description: 'Name of the tag associated with the release' + + argument :name, GraphQL::STRING_TYPE, + required: false, + description: 'Name of the release' + + argument :description, GraphQL::STRING_TYPE, + required: false, + description: 'Description (release notes) of the release' + + argument :released_at, Types::TimeType, + required: false, + description: 'The release date' + + argument :milestones, [GraphQL::STRING_TYPE], + required: false, + description: 'The title of each milestone the release is associated with. GitLab Premium customers can specify group milestones.' + + authorize :update_release + + def ready?(**args) + if args.key?(:released_at) && args[:released_at].nil? + raise Gitlab::Graphql::Errors::ArgumentError, + 'if the releasedAt argument is provided, it cannot be null' + end + + if args.key?(:milestones) && args[:milestones].nil? + raise Gitlab::Graphql::Errors::ArgumentError, + 'if the milestones argument is provided, it cannot be null' + end + + super + end + + def resolve(project_path:, **scalars) + project = authorized_find!(full_path: project_path) + + params = scalars.with_indifferent_access + + release_result = ::Releases::UpdateService.new(project, current_user, params).execute + + if release_result[:status] == :success + { + release: release_result[:release], + errors: [] + } + else + { + release: nil, + errors: [release_result[:message]] + } + end + end + end + end +end diff --git a/app/graphql/mutations/snippets/create.rb b/app/graphql/mutations/snippets/create.rb index 37c0f80310c..56c3b398949 100644 --- a/app/graphql/mutations/snippets/create.rb +++ b/app/graphql/mutations/snippets/create.rb @@ -4,7 +4,8 @@ module Mutations module Snippets class Create < BaseMutation include SpammableMutationFields - include ResolvesProject + + authorize :create_snippet graphql_name 'CreateSnippet' @@ -37,17 +38,15 @@ module Mutations description: 'Actions to perform over the snippet repository and blobs', required: false - def resolve(args) - project_path = args.delete(:project_path) - + def resolve(project_path: nil, **args) if project_path.present? - project = find_project!(project_path: project_path) - elsif !can_create_personal_snippet? - raise_resource_not_available_error! + project = authorized_find!(project_path) + else + authorize!(:global) end service_response = ::Snippets::CreateService.new(project, - context[:current_user], + current_user, create_params(args)).execute snippet = service_response.payload[:snippet] @@ -67,20 +66,8 @@ module Mutations private - def find_project!(project_path:) - authorized_find!(full_path: project_path) - end - - def find_object(full_path:) - resolve_project(full_path: full_path) - end - - def authorized_resource?(project) - Ability.allowed?(context[:current_user], :create_snippet, project) - end - - def can_create_personal_snippet? - Ability.allowed?(context[:current_user], :create_snippet) + def find_object(full_path) + Project.find_by_full_path(full_path) end def create_params(args) diff --git a/app/graphql/mutations/snippets/destroy.rb b/app/graphql/mutations/snippets/destroy.rb index 4915d7dd77a..bee6503372d 100644 --- a/app/graphql/mutations/snippets/destroy.rb +++ b/app/graphql/mutations/snippets/destroy.rb @@ -9,7 +9,7 @@ module Mutations argument :id, ::Types::GlobalIDType[::Snippet], required: true, - description: 'The global id of the snippet to destroy' + description: 'The global ID of the snippet to destroy' def resolve(id:) snippet = authorized_find!(id: id) diff --git a/app/graphql/mutations/snippets/mark_as_spam.rb b/app/graphql/mutations/snippets/mark_as_spam.rb index d6b96c699c0..2d6fea1f5ec 100644 --- a/app/graphql/mutations/snippets/mark_as_spam.rb +++ b/app/graphql/mutations/snippets/mark_as_spam.rb @@ -7,7 +7,7 @@ module Mutations argument :id, ::Types::GlobalIDType[::Snippet], required: true, - description: 'The global id of the snippet to update' + description: 'The global ID of the snippet to update' def resolve(id:) snippet = authorized_find!(id: id) @@ -23,7 +23,7 @@ module Mutations private def mark_as_spam(snippet) - Spam::MarkAsSpamService.new(spammable: snippet).execute + Spam::MarkAsSpamService.new(target: snippet).execute end def authorized_resource?(snippet) diff --git a/app/graphql/mutations/snippets/update.rb b/app/graphql/mutations/snippets/update.rb index bcaa807e4c1..6df1ad6d8b9 100644 --- a/app/graphql/mutations/snippets/update.rb +++ b/app/graphql/mutations/snippets/update.rb @@ -9,7 +9,7 @@ module Mutations argument :id, ::Types::GlobalIDType[::Snippet], required: true, - description: 'The global id of the snippet to update' + description: 'The global ID of the snippet to update' argument :title, GraphQL::STRING_TYPE, required: false, @@ -27,11 +27,11 @@ module Mutations description: 'Actions to perform over the snippet repository and blobs', required: false - def resolve(args) - snippet = authorized_find!(id: args.delete(:id)) + def resolve(id:, **args) + snippet = authorized_find!(id: id) result = ::Snippets::UpdateService.new(snippet.project, - context[:current_user], + current_user, update_params(args)).execute(snippet) snippet = result.payload[:snippet] diff --git a/app/graphql/mutations/todos/mark_done.rb b/app/graphql/mutations/todos/mark_done.rb index 3d73022f266..2ae50846108 100644 --- a/app/graphql/mutations/todos/mark_done.rb +++ b/app/graphql/mutations/todos/mark_done.rb @@ -10,7 +10,7 @@ module Mutations argument :id, ::Types::GlobalIDType[::Todo], required: true, - description: 'The global id of the todo to mark as done' + description: 'The global ID of the todo to mark as done' field :todo, Types::TodoType, null: false, diff --git a/app/graphql/mutations/todos/restore.rb b/app/graphql/mutations/todos/restore.rb index 7c8f92d32f5..c532b455a16 100644 --- a/app/graphql/mutations/todos/restore.rb +++ b/app/graphql/mutations/todos/restore.rb @@ -10,7 +10,7 @@ module Mutations argument :id, ::Types::GlobalIDType[::Todo], required: true, - description: 'The global id of the todo to restore' + description: 'The global ID of the todo to restore' field :todo, Types::TodoType, null: false, diff --git a/app/graphql/mutations/todos/restore_many.rb b/app/graphql/mutations/todos/restore_many.rb index 9e0a95c48ec..59965589856 100644 --- a/app/graphql/mutations/todos/restore_many.rb +++ b/app/graphql/mutations/todos/restore_many.rb @@ -10,11 +10,11 @@ module Mutations argument :ids, [::Types::GlobalIDType[::Todo]], required: true, - description: 'The global ids of the todos to restore (a maximum of 50 is supported at once)' + description: 'The global IDs of the todos to restore (a maximum of 50 is supported at once)' field :updated_ids, [::Types::GlobalIDType[Todo]], null: false, - description: 'The ids of the updated todo items', + description: 'The IDs of the updated todo items', deprecated: { reason: 'Use todos', milestone: '13.2' } field :todos, [::Types::TodoType], |