1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# frozen_string_literal: true
module Mutations
module DesignManagement
class Delete < Base
Errors = ::Gitlab::Graphql::Errors
graphql_name "DesignManagementDelete"
argument :filenames, [GraphQL::STRING_TYPE],
required: true,
description: "The filenames of the designs to delete.",
prepare: ->(names, _ctx) do
names.presence || (raise Errors::ArgumentError, 'no filenames')
end
field :version, Types::DesignManagement::VersionType,
null: true, # null on error
description: 'The new version in which the designs are deleted.'
authorize :destroy_design
def resolve(project_path:, iid:, filenames:)
issue = authorized_find!(project_path: project_path, iid: iid)
project = issue.project
designs = resolve_designs(issue, filenames)
result = ::DesignManagement::DeleteDesignsService
.new(project, current_user, issue: issue, designs: designs)
.execute
{
version: result[:version],
errors: Array.wrap(result[:message])
}
end
private
# Here we check that:
# * we find exactly as many designs as filenames
def resolve_designs(issue, filenames)
designs = issue.design_collection.designs_by_filename(filenames)
validate_all_were_found!(designs, filenames)
designs
end
def validate_all_were_found!(designs, filenames)
found_filenames = designs.map(&:filename)
missing = filenames.difference(found_filenames)
if missing.present?
raise Errors::ArgumentError, <<~MSG
Not all the designs you named currently exist.
The following filenames were not found:
#{missing.join(', ')}
They may have already been deleted.
MSG
end
end
end
end
end
|