diff options
Diffstat (limited to 'app/models/work_items')
-rw-r--r-- | app/models/work_items/parent_link.rb | 23 | ||||
-rw-r--r-- | app/models/work_items/type.rb | 16 | ||||
-rw-r--r-- | app/models/work_items/widgets/labels.rb | 10 | ||||
-rw-r--r-- | app/models/work_items/widgets/start_and_due_date.rb | 9 | ||||
-rw-r--r-- | app/models/work_items/widgets/weight.rb | 9 |
5 files changed, 52 insertions, 15 deletions
diff --git a/app/models/work_items/parent_link.rb b/app/models/work_items/parent_link.rb index f5ebbfa59b8..13d6db3e08e 100644 --- a/app/models/work_items/parent_link.rb +++ b/app/models/work_items/parent_link.rb @@ -16,6 +16,20 @@ module WorkItems validate :validate_parent_type validate :validate_same_project validate :validate_max_children + validate :validate_confidentiality + + class << self + def has_public_children?(parent_id) + joins(:work_item).where(work_item_parent_id: parent_id, 'issues.confidential': false).exists? + end + + def has_confidential_parent?(id) + link = find_by_work_item_id(id) + return false unless link + + link.work_item_parent.confidential? + end + end private @@ -56,5 +70,14 @@ module WorkItems errors.add :work_item_parent, _('parent already has maximum number of children.') end end + + def validate_confidentiality + return unless work_item_parent && work_item + + if work_item_parent.confidential? && !work_item.confidential? + errors.add :work_item, _("cannot assign a non-confidential work item to a confidential "\ + "parent. Make the work item confidential and try again.") + end + end end end diff --git a/app/models/work_items/type.rb b/app/models/work_items/type.rb index e38d0ae153a..753fcbcb8f9 100644 --- a/app/models/work_items/type.rb +++ b/app/models/work_items/type.rb @@ -13,21 +13,23 @@ module WorkItems # Base types need to exist on the DB on app startup # This constant is used by the DB seeder BASE_TYPES = { - issue: { name: 'Issue', icon_name: 'issue-type-issue', enum_value: 0 }, - incident: { name: 'Incident', icon_name: 'issue-type-incident', enum_value: 1 }, - test_case: { name: 'Test Case', icon_name: 'issue-type-test-case', enum_value: 2 }, ## EE-only + issue: { name: 'Issue', icon_name: 'issue-type-issue', enum_value: 0 }, + incident: { name: 'Incident', icon_name: 'issue-type-incident', enum_value: 1 }, + test_case: { name: 'Test Case', icon_name: 'issue-type-test-case', enum_value: 2 }, ## EE-only requirement: { name: 'Requirement', icon_name: 'issue-type-requirements', enum_value: 3 }, ## EE-only - task: { name: 'Task', icon_name: 'issue-type-task', enum_value: 4 } + task: { name: 'Task', icon_name: 'issue-type-task', enum_value: 4 } }.freeze WIDGETS_FOR_TYPE = { - issue: [Widgets::Assignees, Widgets::Description, Widgets::Hierarchy, Widgets::Weight], + issue: [Widgets::Assignees, Widgets::Labels, Widgets::Description, Widgets::Hierarchy, Widgets::StartAndDueDate], incident: [Widgets::Description, Widgets::Hierarchy], test_case: [Widgets::Description], requirement: [Widgets::Description], - task: [Widgets::Assignees, Widgets::Description, Widgets::Hierarchy, Widgets::Weight] + task: [Widgets::Assignees, Widgets::Labels, Widgets::Description, Widgets::Hierarchy, Widgets::StartAndDueDate] }.freeze + WI_TYPES_WITH_CREATED_HEADER = %w[issue incident].freeze + cache_markdown_field :description, pipeline: :single_line enum base_type: BASE_TYPES.transform_values { |value| value[:enum_value] } @@ -83,3 +85,5 @@ module WorkItems end end end + +WorkItems::Type.prepend_mod diff --git a/app/models/work_items/widgets/labels.rb b/app/models/work_items/widgets/labels.rb new file mode 100644 index 00000000000..4ad8319ffac --- /dev/null +++ b/app/models/work_items/widgets/labels.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module WorkItems + module Widgets + class Labels < Base + delegate :labels, to: :work_item + delegate :allows_scoped_labels?, to: :work_item + end + end +end diff --git a/app/models/work_items/widgets/start_and_due_date.rb b/app/models/work_items/widgets/start_and_due_date.rb new file mode 100644 index 00000000000..0b828c5b5a9 --- /dev/null +++ b/app/models/work_items/widgets/start_and_due_date.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module WorkItems + module Widgets + class StartAndDueDate < Base + delegate :start_date, :due_date, to: :work_item + end + end +end diff --git a/app/models/work_items/widgets/weight.rb b/app/models/work_items/widgets/weight.rb deleted file mode 100644 index f589378f307..00000000000 --- a/app/models/work_items/widgets/weight.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -module WorkItems - module Widgets - class Weight < Base - delegate :weight, to: :work_item - end - end -end |