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

class ReleasePresenter < Gitlab::View::Presenter::Delegated
  include ActionView::Helpers::UrlHelper

  presents :release

  delegate :project, :tag, :assets_count, to: :release

  def commit_path
    return unless release.commit && can_download_code?

    project_commit_path(project, release.commit.id)
  end

  def tag_path
    return unless can_download_code?

    project_tag_path(project, release.tag)
  end

  def self_url
    return unless ::Feature.enabled?(:release_show_page, project, default_enabled: true)

    project_release_url(project, release)
  end

  def merge_requests_url
    return unless release_mr_issue_urls_available?

    project_merge_requests_url(project, params_for_issues_and_mrs)
  end

  def issues_url
    return unless release_mr_issue_urls_available?

    project_issues_url(project, params_for_issues_and_mrs)
  end

  def edit_url
    return unless release_edit_page_available?

    edit_project_release_url(project, release)
  end

  private

  def can_download_code?
    can?(current_user, :download_code, project)
  end

  def params_for_issues_and_mrs
    { scope: 'all', state: 'opened', release_tag: release.tag }
  end

  def release_mr_issue_urls_available?
    ::Feature.enabled?(:release_mr_issue_urls, project)
  end

  def release_edit_page_available?
    can?(current_user, :update_release, release)
  end
end