debian-mirror-gitlab/app/presenters/release_presenter.rb

82 lines
1.7 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
class ReleasePresenter < Gitlab::View::Presenter::Delegated
2021-11-18 22:05:49 +05:30
presents ::Release, as: :release
2019-12-26 22:10:19 +05:30
def commit_path
2023-01-13 00:05:48 +05:30
return unless release.commit && can_read_code?
2019-12-26 22:10:19 +05:30
project_commit_path(project, release.commit.id)
end
def tag_path
2023-01-13 00:05:48 +05:30
return unless can_read_code?
2019-12-26 22:10:19 +05:30
project_tag_path(project, release.tag)
end
2020-03-13 15:44:24 +05:30
def self_url
project_release_url(project, release)
end
2021-01-29 00:20:46 +05:30
def opened_merge_requests_url
2019-12-26 22:10:19 +05:30
project_merge_requests_url(project, params_for_issues_and_mrs)
end
2021-01-29 00:20:46 +05:30
def merged_merge_requests_url
project_merge_requests_url(project, params_for_issues_and_mrs(state: 'merged'))
end
def closed_merge_requests_url
project_merge_requests_url(project, params_for_issues_and_mrs(state: 'closed'))
end
def opened_issues_url
2019-12-26 22:10:19 +05:30
project_issues_url(project, params_for_issues_and_mrs)
end
2021-01-29 00:20:46 +05:30
def closed_issues_url
project_issues_url(project, params_for_issues_and_mrs(state: 'closed'))
end
2019-12-26 22:10:19 +05:30
def edit_url
return unless release_edit_page_available?
edit_project_release_url(project, release)
end
2021-11-18 22:05:49 +05:30
delegator_override :assets_count
2020-07-28 23:09:34 +05:30
def assets_count
2023-01-13 00:05:48 +05:30
if can_read_code?
2020-07-28 23:09:34 +05:30
release.assets_count
else
release.assets_count(except: [:sources])
end
end
2021-11-18 22:05:49 +05:30
delegator_override :name
2020-07-28 23:09:34 +05:30
def name
2021-12-11 22:18:48 +05:30
release.name
2020-07-28 23:09:34 +05:30
end
2021-01-29 00:20:46 +05:30
def download_url(filepath)
filepath = filepath.sub(%r{^/}, '') if filepath.start_with?('/')
downloads_project_release_url(project, release, filepath)
end
2019-12-26 22:10:19 +05:30
private
2023-01-13 00:05:48 +05:30
def can_read_code?
can?(current_user, :read_code, project)
2019-12-26 22:10:19 +05:30
end
2021-01-29 00:20:46 +05:30
def params_for_issues_and_mrs(state: 'opened')
{ scope: 'all', state: state, release_tag: release.tag }
2019-12-26 22:10:19 +05:30
end
def release_edit_page_available?
2020-01-01 13:55:28 +05:30
can?(current_user, :update_release, release)
2019-12-26 22:10:19 +05:30
end
end