diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2019-04-23 19:58:20 +0000 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2019-04-23 19:58:20 +0000 |
commit | 8ce4b6093a2e64f21928dded6c58950f180d8c2a (patch) | |
tree | e3478cf58d2119fd2f84572d34acf0c507e75a5b /app/presenters | |
parent | be15592a1c1551bb6136081ea995dca49e238c8f (diff) | |
download | gitlab-ce-8ce4b6093a2e64f21928dded6c58950f180d8c2a.tar.gz |
Move scoped_label into label presenter
When rendering a label we want to check 'scoped_label' feature
availability on a project/group where label is being used. For
this reason a label presenter is used in UI and information about
context project/group is passed to this presenter.
Diffstat (limited to 'app/presenters')
-rw-r--r-- | app/presenters/label_presenter.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/app/presenters/label_presenter.rb b/app/presenters/label_presenter.rb new file mode 100644 index 00000000000..5227ef353c3 --- /dev/null +++ b/app/presenters/label_presenter.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +class LabelPresenter < Gitlab::View::Presenter::Delegated + presents :label + + 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 + + private + + def context_subject + issuable_subject || label.try(:subject) + end +end |