summaryrefslogtreecommitdiff
path: root/app/presenters/label_presenter.rb
blob: 9e51e6fa4bae37a0acff26fa74e38f5a60f4e53c (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
# frozen_string_literal: true

class LabelPresenter < Gitlab::View::Presenter::Delegated
  presents :label
  delegate :name, :full_name, to: :label_subject, prefix: :subject

  def edit_path
    case label
    when GroupLabel then edit_group_label_path(label.group, label)
    when ProjectLabel then edit_project_label_path(label.project, label)
    end
  end

  def destroy_path
    case label
    when GroupLabel then group_label_path(label.group, label)
    when ProjectLabel then project_label_path(label.project, label)
    end
  end

  def filter_path(type: :issue)
    case context_subject
    when Group
      send("#{type.to_s.pluralize}_group_path", # rubocop:disable GitlabSecurity/PublicSend
                  context_subject,
                  label_name: [label.name])
    when Project
      send("namespace_project_#{type.to_s.pluralize}_path", # rubocop:disable GitlabSecurity/PublicSend
                  context_subject.namespace,
                  context_subject,
                  label_name: [label.name])
    end
  end

  def can_subscribe_to_label_in_different_levels?
    issuable_subject.is_a?(Project) && label.is_a?(GroupLabel)
  end

  def project_label?
    label.is_a?(ProjectLabel)
  end

  def label_subject
    @label_subject ||= label.subject
  end

  private

  def context_subject
    issuable_subject || label.try(:subject)
  end
end

LabelPresenter.prepend_mod_with('LabelPresenter')