blob: fd9b2f086fc611876122abe8c4d60b8fd344c35f (
plain)
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 Gitlab
module Issuable
module Clone
class AttributesRewriter
attr_reader :current_user, :original_entity, :target_parent
def initialize(current_user, original_entity, target_parent)
raise ArgumentError, 'target_parent cannot be nil' if target_parent.nil?
@current_user = current_user
@original_entity = original_entity
@target_parent = target_parent
end
def execute(include_milestone: true)
attributes = { label_ids: cloneable_labels.pluck_primary_key }
if include_milestone
milestone = matching_milestone(original_entity.milestone&.title)
attributes[:milestone_id] = milestone.id if milestone.present?
end
attributes
end
private
def cloneable_labels
params = {
project_id: project&.id,
group_id: group&.id,
title: original_entity.labels.select(:title),
include_ancestor_groups: true
}
params[:only_group_labels] = true if target_parent.is_a?(Group)
LabelsFinder.new(current_user, params).execute
end
def matching_milestone(title)
return if title.blank?
params = { title: title, project_ids: project&.id, group_ids: group&.id }
milestones = MilestonesFinder.new(params).execute
milestones.first
end
def project
target_parent if target_parent.is_a?(Project)
end
def group
if target_parent.is_a?(Group)
target_parent
elsif target_parent&.group && current_user.can?(:read_group, target_parent.group)
target_parent.group
end
end
end
end
end
end
|