2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class LabelPresenter < Gitlab::View::Presenter::Delegated
|
2021-11-18 22:05:49 +05:30
|
|
|
presents ::Label, as: :label
|
2022-03-02 08:16:31 +05:30
|
|
|
delegate :name, :full_name, to: :label_subject, prefix: :subject, allow_nil: true
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
delegator_override :subject # TODO: Fix `Gitlab::View::Presenter::Delegated#subject` not to override `Label#subject`.
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
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)
|
2022-03-02 08:16:31 +05:30
|
|
|
else edit_admin_label_path(label)
|
2019-07-31 22:56:46 +05:30
|
|
|
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)
|
2022-03-02 08:16:31 +05:30
|
|
|
else admin_label_path(label)
|
2019-07-31 22:56:46 +05:30
|
|
|
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
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
def label_subject
|
2022-03-02 08:16:31 +05:30
|
|
|
@label_subject ||= label.subject if label.respond_to?(:subject)
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def context_subject
|
|
|
|
issuable_subject || label.try(:subject)
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
LabelPresenter.prepend_mod_with('LabelPresenter')
|