diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
commit | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch) | |
tree | fb69158581673816a8cd895f9d352dcb3c678b1e /app/presenters/packages/pypi/package_presenter.rb | |
parent | d16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff) |
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'app/presenters/packages/pypi/package_presenter.rb')
-rw-r--r-- | app/presenters/packages/pypi/package_presenter.rb | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/app/presenters/packages/pypi/package_presenter.rb b/app/presenters/packages/pypi/package_presenter.rb index 1cb11c7be1a..7997c1b9b79 100644 --- a/app/presenters/packages/pypi/package_presenter.rb +++ b/app/presenters/packages/pypi/package_presenter.rb @@ -7,9 +7,9 @@ module Packages class PackagePresenter include API::Helpers::RelatedResourcesHelpers - def initialize(packages, project) + def initialize(packages, project_or_group) @packages = packages - @project = project + @project_or_group = project_or_group end # Returns the HTML body for PyPI simple API. @@ -51,16 +51,27 @@ module Packages end def build_pypi_package_path(file) - expose_url( - api_v4_projects_packages_pypi_files_file_identifier_path( - { - id: @project.id, - sha256: file.file_sha256, - file_identifier: file.file_name - }, - true - ) - ) + "#sha256=#{file.file_sha256}" + params = { + id: @project_or_group.id, + sha256: file.file_sha256, + file_identifier: file.file_name + } + + if project? + expose_url( + api_v4_projects_packages_pypi_files_file_identifier_path( + params, true + ) + ) + "#sha256=#{file.file_sha256}" + elsif group? + expose_url( + api_v4_groups___packages_pypi_files_file_identifier_path( + params, true + ) + ) + "#sha256=#{file.file_sha256}" + else + '' + end end def name @@ -70,6 +81,14 @@ module Packages def escape(str) ERB::Util.html_escape(str) end + + def project? + @project_or_group.is_a?(::Project) + end + + def group? + @project_or_group.is_a?(::Group) + end end end end |