2019-10-23 17:06:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ReleasePresenter < Gitlab::View::Presenter::Delegated
|
|
|
|
include ActionView::Helpers::UrlHelper
|
|
|
|
|
|
|
|
presents :release
|
|
|
|
|
2020-06-18 02:08:33 -04:00
|
|
|
delegate :project, :tag, to: :release
|
2019-10-23 17:06:17 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2020-01-31 13:09:11 -05:00
|
|
|
def self_url
|
2021-02-01 19:09:14 -05:00
|
|
|
return unless can_download_code?
|
|
|
|
|
2020-01-31 13:09:11 -05:00
|
|
|
project_release_url(project, release)
|
|
|
|
end
|
|
|
|
|
2020-10-30 11:08:59 -04:00
|
|
|
def opened_merge_requests_url
|
2019-10-23 17:06:17 -04:00
|
|
|
return unless release_mr_issue_urls_available?
|
|
|
|
|
|
|
|
project_merge_requests_url(project, params_for_issues_and_mrs)
|
|
|
|
end
|
|
|
|
|
2020-10-29 08:08:50 -04:00
|
|
|
def merged_merge_requests_url
|
|
|
|
return unless release_mr_issue_urls_available?
|
|
|
|
|
|
|
|
project_merge_requests_url(project, params_for_issues_and_mrs(state: 'merged'))
|
|
|
|
end
|
|
|
|
|
|
|
|
def closed_merge_requests_url
|
|
|
|
return unless release_mr_issue_urls_available?
|
|
|
|
|
|
|
|
project_merge_requests_url(project, params_for_issues_and_mrs(state: 'closed'))
|
|
|
|
end
|
|
|
|
|
2020-10-30 11:08:59 -04:00
|
|
|
def opened_issues_url
|
2019-10-23 17:06:17 -04:00
|
|
|
return unless release_mr_issue_urls_available?
|
|
|
|
|
|
|
|
project_issues_url(project, params_for_issues_and_mrs)
|
|
|
|
end
|
|
|
|
|
2020-10-29 08:08:50 -04:00
|
|
|
def closed_issues_url
|
|
|
|
return unless release_mr_issue_urls_available?
|
|
|
|
|
|
|
|
project_issues_url(project, params_for_issues_and_mrs(state: 'closed'))
|
|
|
|
end
|
|
|
|
|
2019-10-31 23:06:26 -04:00
|
|
|
def edit_url
|
|
|
|
return unless release_edit_page_available?
|
|
|
|
|
|
|
|
edit_project_release_url(project, release)
|
|
|
|
end
|
|
|
|
|
2020-06-18 02:08:33 -04:00
|
|
|
def assets_count
|
|
|
|
if can_download_code?
|
|
|
|
release.assets_count
|
|
|
|
else
|
|
|
|
release.assets_count(except: [:sources])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def name
|
|
|
|
can_download_code? ? release.name : "Release-#{release.id}"
|
|
|
|
end
|
|
|
|
|
2020-11-12 10:09:09 -05:00
|
|
|
def download_url(filepath)
|
|
|
|
filepath = filepath.sub(%r{^/}, '') if filepath.start_with?('/')
|
|
|
|
|
|
|
|
downloads_project_release_url(project, release, filepath)
|
|
|
|
end
|
|
|
|
|
2019-10-23 17:06:17 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def can_download_code?
|
|
|
|
can?(current_user, :download_code, project)
|
|
|
|
end
|
|
|
|
|
2020-10-29 08:08:50 -04:00
|
|
|
def params_for_issues_and_mrs(state: 'opened')
|
|
|
|
{ scope: 'all', state: state, release_tag: release.tag }
|
2019-10-23 17:06:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def release_mr_issue_urls_available?
|
2020-11-06 07:09:17 -05:00
|
|
|
::Feature.enabled?(:release_mr_issue_urls, project, default_enabled: true)
|
2019-10-23 17:06:17 -04:00
|
|
|
end
|
2019-10-31 23:06:26 -04:00
|
|
|
|
|
|
|
def release_edit_page_available?
|
2019-11-22 16:06:19 -05:00
|
|
|
can?(current_user, :update_release, release)
|
2019-10-31 23:06:26 -04:00
|
|
|
end
|
2019-10-23 17:06:17 -04:00
|
|
|
end
|