summaryrefslogtreecommitdiff
path: root/app/presenters
diff options
context:
space:
mode:
Diffstat (limited to 'app/presenters')
-rw-r--r--app/presenters/README.md8
-rw-r--r--app/presenters/alert_management/alert_presenter.rb2
-rw-r--r--app/presenters/blob_presenter.rb30
-rw-r--r--app/presenters/blobs/unfold_presenter.rb2
-rw-r--r--app/presenters/ci/pipeline_presenter.rb2
-rw-r--r--app/presenters/ci/runner_presenter.rb4
-rw-r--r--app/presenters/clusterable_presenter.rb4
-rw-r--r--app/presenters/clusters/cluster_presenter.rb2
-rw-r--r--app/presenters/merge_request_presenter.rb2
-rw-r--r--app/presenters/packages/conan/package_presenter.rb6
-rw-r--r--app/presenters/packages/detail/package_presenter.rb6
-rw-r--r--app/presenters/packages/npm/package_presenter.rb6
-rw-r--r--app/presenters/packages/nuget/presenter_helpers.rb11
-rw-r--r--app/presenters/packages/pypi/package_presenter.rb6
-rw-r--r--app/presenters/project_presenter.rb2
-rw-r--r--app/presenters/projects/import_export/project_export_presenter.rb5
-rw-r--r--app/presenters/projects/security/configuration_presenter.rb3
-rw-r--r--app/presenters/snippet_blob_presenter.rb2
18 files changed, 58 insertions, 45 deletions
diff --git a/app/presenters/README.md b/app/presenters/README.md
index dfd1818f97d..31e5c971a88 100644
--- a/app/presenters/README.md
+++ b/app/presenters/README.md
@@ -223,13 +223,9 @@ To add methods of a module to an allowlist, use `delegator_override_with`. For e
```ruby
module Ci
class PipelinePresenter < Gitlab::View::Presenter::Delegated
- include Gitlab::Utils::StrongMemoize
- include ActionView::Helpers::UrlHelper
+ include ActionView::Helpers::TagHelper
- delegator_override_with Gitlab::Utils::StrongMemoize # TODO: Remove `Gitlab::Utils::StrongMemoize` inclusion as it's duplicate
- delegator_override_with ActionView::Helpers::TagHelper # TODO: Remove `ActionView::Helpers::UrlHelper` inclusion as it overrides `Ci::Pipeline#tag`
+ delegator_override_with ActionView::Helpers::TagHelper # TODO: Remove `ActionView::Helpers::TagHelper` inclusion as it overrides `Ci::Pipeline#tag`
```
-Keep in mind that if you use `delegator_override_with`,
-there is a high chance that you're doing **something wrong**.
Read the [Validate Accidental Overrides](#validate-accidental-overrides) for more information.
diff --git a/app/presenters/alert_management/alert_presenter.rb b/app/presenters/alert_management/alert_presenter.rb
index 86fe9859271..b692935d229 100644
--- a/app/presenters/alert_management/alert_presenter.rb
+++ b/app/presenters/alert_management/alert_presenter.rb
@@ -6,7 +6,7 @@ module AlertManagement
include ActionView::Helpers::UrlHelper
presents ::AlertManagement::Alert
- delegator_override_with Gitlab::Utils::StrongMemoize # TODO: Remove `Gitlab::Utils::StrongMemoize` inclusion as it's duplicate
+ delegator_override_with Gitlab::Utils::StrongMemoize # This module inclusion is expected. See https://gitlab.com/gitlab-org/gitlab/-/issues/352884.
MARKDOWN_LINE_BREAK = " \n"
HORIZONTAL_LINE = "\n\n---\n\n"
diff --git a/app/presenters/blob_presenter.rb b/app/presenters/blob_presenter.rb
index 2577fcaf303..47b72df32a2 100644
--- a/app/presenters/blob_presenter.rb
+++ b/app/presenters/blob_presenter.rb
@@ -32,7 +32,7 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated
end
def blob_language
- @_blob_language ||= Gitlab::Diff::CustomDiff.transformed_blob_language(blob) || language
+ @_blob_language ||= Gitlab::Diff::CustomDiff.transformed_blob_language(blob) || gitattr_language || detect_language
end
def raw_plain_data
@@ -79,6 +79,18 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated
url_helpers.project_blob_path(project, File.join(project.repository.commit.sha, blob.path))
end
+ def environment_formatted_external_url
+ return unless environment
+
+ environment.formatted_external_url
+ end
+
+ def environment_external_url_for_route_map
+ return unless environment
+
+ environment.external_url_for(blob.path, blob.commit_id)
+ end
+
# Will be overridden in EE
def code_owners
[]
@@ -113,7 +125,7 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated
def external_storage_url
return unless static_objects_external_storage_enabled?
- external_storage_url_or_path(url_helpers.project_raw_url(project, ref_qualified_path))
+ external_storage_url_or_path(url_helpers.project_raw_url(project, ref_qualified_path), project)
end
private
@@ -122,6 +134,12 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated
Gitlab::Routing.url_helpers
end
+ def environment
+ environment_params = project.repository.branch_exists?(blob.commit_id) ? { ref: blob.commit_id } : { sha: blob.commit_id }
+ environment_params[:find_latest] = true
+ ::Environments::EnvironmentsByDeploymentsFinder.new(project, current_user, environment_params).execute.last
+ end
+
def project
blob.repository.project
end
@@ -148,9 +166,15 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated
@all_lines ||= blob.data.lines
end
- def language
+ def gitattr_language
blob.language_from_gitattributes
end
+
+ def detect_language
+ return if blob.binary?
+
+ Rouge::Lexer.guess(filename: blob.path, source: blob_data(nil)) { |lex| lex.min_by(&:tag) }.tag
+ end
end
BlobPresenter.prepend_mod_with('BlobPresenter')
diff --git a/app/presenters/blobs/unfold_presenter.rb b/app/presenters/blobs/unfold_presenter.rb
index b921b5bf670..90b471abf22 100644
--- a/app/presenters/blobs/unfold_presenter.rb
+++ b/app/presenters/blobs/unfold_presenter.rb
@@ -108,7 +108,7 @@ module Blobs
def limit(lines)
return lines if full?
- lines[since - 1..to - 1]
+ lines[since - 1..to - 1] || []
end
end
end
diff --git a/app/presenters/ci/pipeline_presenter.rb b/app/presenters/ci/pipeline_presenter.rb
index 7f5dffadcfb..2818e6da036 100644
--- a/app/presenters/ci/pipeline_presenter.rb
+++ b/app/presenters/ci/pipeline_presenter.rb
@@ -4,7 +4,7 @@ module Ci
class PipelinePresenter < Gitlab::View::Presenter::Delegated
include Gitlab::Utils::StrongMemoize
- delegator_override_with Gitlab::Utils::StrongMemoize # TODO: Remove `Gitlab::Utils::StrongMemoize` inclusion as it's duplicate
+ delegator_override_with Gitlab::Utils::StrongMemoize # This module inclusion is expected. See https://gitlab.com/gitlab-org/gitlab/-/issues/352884.
delegator_override_with ActionView::Helpers::TagHelper # TODO: Remove `ActionView::Helpers::UrlHelper` inclusion as it overrides `Ci::Pipeline#tag`
# We use a class method here instead of a constant, allowing EE to redefine
diff --git a/app/presenters/ci/runner_presenter.rb b/app/presenters/ci/runner_presenter.rb
index ffd826fab64..482534f27b9 100644
--- a/app/presenters/ci/runner_presenter.rb
+++ b/app/presenters/ci/runner_presenter.rb
@@ -15,5 +15,9 @@ module Ci
def executor_name
Ci::Runner::EXECUTOR_TYPE_TO_NAMES[executor_type&.to_sym]
end
+
+ def paused
+ !active
+ end
end
end
diff --git a/app/presenters/clusterable_presenter.rb b/app/presenters/clusterable_presenter.rb
index 4b645510b51..cc466e0ff81 100644
--- a/app/presenters/clusterable_presenter.rb
+++ b/app/presenters/clusterable_presenter.rb
@@ -16,6 +16,10 @@ class ClusterablePresenter < Gitlab::View::Presenter::Delegated
can?(current_user, :add_cluster, clusterable)
end
+ def can_admin_cluster?
+ can?(current_user, :admin_cluster, clusterable)
+ end
+
def can_create_cluster?
can?(current_user, :create_cluster, clusterable)
end
diff --git a/app/presenters/clusters/cluster_presenter.rb b/app/presenters/clusters/cluster_presenter.rb
index ce060476cfd..e2fc2b4b485 100644
--- a/app/presenters/clusters/cluster_presenter.rb
+++ b/app/presenters/clusters/cluster_presenter.rb
@@ -4,7 +4,7 @@ module Clusters
class ClusterPresenter < Gitlab::View::Presenter::Delegated
include ::Gitlab::Utils::StrongMemoize
- delegator_override_with ::Gitlab::Utils::StrongMemoize # TODO: Remove `::Gitlab::Utils::StrongMemoize` inclusion as it's duplicate
+ delegator_override_with ::Gitlab::Utils::StrongMemoize # This module inclusion is expected. See https://gitlab.com/gitlab-org/gitlab/-/issues/352884.
presents ::Clusters::Cluster, as: :cluster
diff --git a/app/presenters/merge_request_presenter.rb b/app/presenters/merge_request_presenter.rb
index eeb94a8e657..8450679dd79 100644
--- a/app/presenters/merge_request_presenter.rb
+++ b/app/presenters/merge_request_presenter.rb
@@ -8,7 +8,7 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated
include ChecksCollaboration
include Gitlab::Utils::StrongMemoize
- delegator_override_with Gitlab::Utils::StrongMemoize # TODO: Remove `Gitlab::Utils::StrongMemoize` inclusion as it's duplicate
+ delegator_override_with Gitlab::Utils::StrongMemoize # This module inclusion is expected. See https://gitlab.com/gitlab-org/gitlab/-/issues/352884.
APPROVALS_WIDGET_BASE_TYPE = 'base'
diff --git a/app/presenters/packages/conan/package_presenter.rb b/app/presenters/packages/conan/package_presenter.rb
index 57636922676..0c7a81038dd 100644
--- a/app/presenters/packages/conan/package_presenter.rb
+++ b/app/presenters/packages/conan/package_presenter.rb
@@ -81,11 +81,7 @@ module Packages
return unless @package
strong_memoize(:package_files) do
- if Feature.enabled?(:packages_installable_package_files, default_enabled: :yaml)
- @package.installable_package_files.preload_conan_file_metadata
- else
- @package.package_files.preload_conan_file_metadata
- end
+ @package.installable_package_files.preload_conan_file_metadata
end
end
diff --git a/app/presenters/packages/detail/package_presenter.rb b/app/presenters/packages/detail/package_presenter.rb
index c257edcadfb..b82b558f0cd 100644
--- a/app/presenters/packages/detail/package_presenter.rb
+++ b/app/presenters/packages/detail/package_presenter.rb
@@ -39,11 +39,7 @@ module Packages
private
def package_file_views
- package_files = if Feature.enabled?(:packages_installable_package_files, default_enabled: :yaml)
- @package.installable_package_files
- else
- @package.package_files
- end
+ package_files = @package.installable_package_files
package_files.map { |pf| build_package_file_view(pf) }
end
diff --git a/app/presenters/packages/npm/package_presenter.rb b/app/presenters/packages/npm/package_presenter.rb
index 1f94187204f..fabb0a36746 100644
--- a/app/presenters/packages/npm/package_presenter.rb
+++ b/app/presenters/packages/npm/package_presenter.rb
@@ -26,11 +26,7 @@ module Packages
.preload_npm_metadatum
batched_packages.each do |package|
- package_file = if Feature.enabled?(:packages_installable_package_files, default_enabled: :yaml)
- package.installable_package_files.last
- else
- package.package_files.last
- end
+ package_file = package.installable_package_files.last
next unless package_file
diff --git a/app/presenters/packages/nuget/presenter_helpers.rb b/app/presenters/packages/nuget/presenter_helpers.rb
index cd3e123033c..5334e4aa6f8 100644
--- a/app/presenters/packages/nuget/presenter_helpers.rb
+++ b/app/presenters/packages/nuget/presenter_helpers.rb
@@ -27,13 +27,10 @@ module Packages
end
def archive_url_for(package)
- package_files = if Feature.enabled?(:packages_installable_package_files, default_enabled: :yaml)
- package.installable_package_files
- else
- package.package_files
- end
-
- package_filename = package_files.with_format(NUGET_PACKAGE_FORMAT).last&.file_name
+ package_filename = package.installable_package_files
+ .with_format(NUGET_PACKAGE_FORMAT)
+ .last
+ &.file_name
path = api_v4_projects_packages_nuget_download_package_name_package_version_package_filename_path(
{
id: package.project_id,
diff --git a/app/presenters/packages/pypi/package_presenter.rb b/app/presenters/packages/pypi/package_presenter.rb
index 33854e4d2fc..a779ce41cf9 100644
--- a/app/presenters/packages/pypi/package_presenter.rb
+++ b/app/presenters/packages/pypi/package_presenter.rb
@@ -36,11 +36,7 @@ module Packages
refs = []
@packages.map do |package|
- package_files = if Feature.enabled?(:packages_installable_package_files, default_enabled: :yaml)
- package.installable_package_files
- else
- package.package_files
- end
+ package_files = package.installable_package_files
package_files.each do |file|
url = build_pypi_package_path(file)
diff --git a/app/presenters/project_presenter.rb b/app/presenters/project_presenter.rb
index 64cd54953e2..9e64d2d43a2 100644
--- a/app/presenters/project_presenter.rb
+++ b/app/presenters/project_presenter.rb
@@ -13,7 +13,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
include Gitlab::Experiment::Dsl
delegator_override_with GitlabRoutingHelper # TODO: Remove `GitlabRoutingHelper` inclusion as it's duplicate
- delegator_override_with Gitlab::Utils::StrongMemoize # TODO: Remove `Gitlab::Utils::StrongMemoize` inclusion as it's duplicate
+ delegator_override_with Gitlab::Utils::StrongMemoize # This module inclusion is expected. See https://gitlab.com/gitlab-org/gitlab/-/issues/352884.
presents ::Project, as: :project
diff --git a/app/presenters/projects/import_export/project_export_presenter.rb b/app/presenters/projects/import_export/project_export_presenter.rb
index 7b2ffb6d755..53c547cde9e 100644
--- a/app/presenters/projects/import_export/project_export_presenter.rb
+++ b/app/presenters/projects/import_export/project_export_presenter.rb
@@ -3,11 +3,14 @@
module Projects
module ImportExport
class ProjectExportPresenter < Gitlab::View::Presenter::Delegated
+ # NOTE: This is needed because this presenter is serialized to JSON,
+ # and we need to make sure that `#as_json` is called in this class so
+ # it will use the overriden attributes below. Otherwise the call is
+ # delegated to the model and will use the original methods.
include ActiveModel::Serializers::JSON
presents ::Project, as: :project
- # TODO: Remove `ActiveModel::Serializers::JSON` inclusion as it's duplicate
delegator_override_with ActiveModel::Serializers::JSON
delegator_override_with ActiveModel::Naming
delegator_override :include_root_in_json, :include_root_in_json?
diff --git a/app/presenters/projects/security/configuration_presenter.rb b/app/presenters/projects/security/configuration_presenter.rb
index 89fca1a451a..1798d4b780f 100644
--- a/app/presenters/projects/security/configuration_presenter.rb
+++ b/app/presenters/projects/security/configuration_presenter.rb
@@ -80,7 +80,8 @@ module Projects
type: scan.type,
configured: scan.configured?,
configuration_path: scan.configuration_path,
- available: scan.available?
+ available: scan.available?,
+ can_enable_by_merge_request: scan.can_enable_by_merge_request?
}
end
diff --git a/app/presenters/snippet_blob_presenter.rb b/app/presenters/snippet_blob_presenter.rb
index 026d442291c..51ce6ccea58 100644
--- a/app/presenters/snippet_blob_presenter.rb
+++ b/app/presenters/snippet_blob_presenter.rb
@@ -33,7 +33,7 @@ class SnippetBlobPresenter < BlobPresenter
blob.container
end
- def language
+ def gitattr_language
nil
end