Class: Mutations::Ci::JobArtifact::BulkDestroy

Inherits:
BaseMutation
  • Object
show all
Defined in:
app/graphql/mutations/ci/job_artifact/bulk_destroy.rb

Constant Summary collapse

ArtifactId =
::Types::GlobalIDType[::Ci::JobArtifact]
ProjectId =
::Types::GlobalIDType[::Project]

Constants inherited from BaseMutation

BaseMutation::ERROR_MESSAGE

Constants included from Gitlab::Graphql::Authorize::AuthorizeResource

Gitlab::Graphql::Authorize::AuthorizeResource::ConfigurationError, Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR

Instance Method Summary collapse

Methods inherited from BaseMutation

#api_user?, authorization, authorized?, authorizes_object?, #current_user, #errors_on_object, #load_application_object, #read_only?, #ready?, #unauthorized_object

Methods included from Gitlab::Graphql::Authorize::AuthorizeResource

#authorize!, #authorized_find!, #authorized_resource?, #raise_resource_not_available_error!

Instance Method Details

#find_object(id:) ⇒ Object



31
32
33
# File 'app/graphql/mutations/ci/job_artifact/bulk_destroy.rb', line 31

def find_object(id:)
  GlobalID::Locator.locate(id)
end

#resolve(**args) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/graphql/mutations/ci/job_artifact/bulk_destroy.rb', line 35

def resolve(**args)
  ids = args[:ids]
  project_id = args[:project_id]

  project = authorized_find!(id: project_id)

  raise Gitlab::Graphql::Errors::ArgumentError, 'IDs array of job artifacts can not be empty' if ids.empty?

  result = ::Ci::JobArtifacts::BulkDeleteByProjectService.new(
    job_artifact_ids: model_ids_of(ids),
    current_user: current_user,
    project: project
  ).execute

  if result.success?
    result.payload.slice(:destroyed_count, :destroyed_ids).merge(errors: [])
  else
    { errors: result.errors }
  end
end