summaryrefslogtreecommitdiff
path: root/app/presenters
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-04-20 10:00:54 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-04-20 10:00:54 +0000
commit3cccd102ba543e02725d247893729e5c73b38295 (patch)
treef36a04ec38517f5deaaacb5acc7d949688d1e187 /app/presenters
parent205943281328046ef7b4528031b90fbda70c75ac (diff)
downloadgitlab-ce-3cccd102ba543e02725d247893729e5c73b38295.tar.gz
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'app/presenters')
-rw-r--r--app/presenters/README.md8
-rw-r--r--app/presenters/ci/bridge_presenter.rb4
-rw-r--r--app/presenters/ci/build_presenter.rb6
-rw-r--r--app/presenters/ci/build_runner_presenter.rb57
-rw-r--r--app/presenters/clusterable_presenter.rb4
-rw-r--r--app/presenters/commit_status_presenter.rb2
-rw-r--r--app/presenters/dev_ops_report/metric_presenter.rb44
-rw-r--r--app/presenters/event_presenter.rb2
-rw-r--r--app/presenters/gitlab/blame_presenter.rb22
-rw-r--r--app/presenters/instance_clusterable_presenter.rb5
-rw-r--r--app/presenters/issue_presenter.rb16
-rw-r--r--app/presenters/label_presenter.rb2
-rw-r--r--app/presenters/pages_domain_presenter.rb2
-rw-r--r--app/presenters/projects/security/configuration_presenter.rb3
14 files changed, 109 insertions, 68 deletions
diff --git a/app/presenters/README.md b/app/presenters/README.md
index 31e5c971a88..e2461580107 100644
--- a/app/presenters/README.md
+++ b/app/presenters/README.md
@@ -68,9 +68,11 @@ we gain the following benefits:
If you need a presenter class that has only necessary interfaces for the view-related context,
inherit from `Gitlab::View::Presenter::Simple`.
-It provides a `.presents` the method which allows you to define an accessor for the
-presented object. It also includes common helpers like `Gitlab::Routing` and
-`Gitlab::Allowable`.
+
+It provides a `.presents` class method which allows you to define the class the presenter is wrapping,
+and specify an accessor for the presented object using the `as:` keyword.
+
+It also includes common helpers like `Gitlab::Routing` and `Gitlab::Allowable`.
```ruby
class LabelPresenter < Gitlab::View::Presenter::Simple
diff --git a/app/presenters/ci/bridge_presenter.rb b/app/presenters/ci/bridge_presenter.rb
index a62d7cdbbd4..ded3844ac99 100644
--- a/app/presenters/ci/bridge_presenter.rb
+++ b/app/presenters/ci/bridge_presenter.rb
@@ -2,11 +2,11 @@
module Ci
class BridgePresenter < ProcessablePresenter
- presents ::Ci::Bridge
+ presents ::Ci::Bridge, as: :bridge
delegator_override :detailed_status
def detailed_status
- @detailed_status ||= subject.detailed_status(user)
+ @detailed_status ||= bridge.detailed_status(user)
end
end
end
diff --git a/app/presenters/ci/build_presenter.rb b/app/presenters/ci/build_presenter.rb
index 65e1c80085f..0be684901d5 100644
--- a/app/presenters/ci/build_presenter.rb
+++ b/app/presenters/ci/build_presenter.rb
@@ -2,7 +2,7 @@
module Ci
class BuildPresenter < ProcessablePresenter
- presents ::Ci::Build
+ presents ::Ci::Build, as: :build
def erased_by_user?
# Build can be erased through API, therefore it does not have
@@ -34,7 +34,7 @@ module Ci
end
def tooltip_message
- "#{subject.name} - #{detailed_status.status_tooltip}"
+ "#{build.name} - #{detailed_status.status_tooltip}"
end
def execute_in
@@ -48,7 +48,7 @@ module Ci
end
def detailed_status
- @detailed_status ||= subject.detailed_status(user)
+ @detailed_status ||= build.detailed_status(user)
end
end
end
diff --git a/app/presenters/ci/build_runner_presenter.rb b/app/presenters/ci/build_runner_presenter.rb
index 082993130a1..015dfc16df0 100644
--- a/app/presenters/ci/build_runner_presenter.rb
+++ b/app/presenters/ci/build_runner_presenter.rb
@@ -64,35 +64,50 @@ module Ci
def create_archive(artifacts)
return unless artifacts[:untracked] || artifacts[:paths]
- archive = {
- artifact_type: :archive,
- artifact_format: :zip,
- name: artifacts[:name],
- untracked: artifacts[:untracked],
- paths: artifacts[:paths],
- when: artifacts[:when],
- expire_in: artifacts[:expire_in]
- }
-
- if artifacts.dig(:exclude).present?
- archive.merge(exclude: artifacts[:exclude])
- else
- archive
+ BuildArtifact.for_archive(artifacts).to_h.tap do |artifact|
+ artifact.delete(:exclude) unless artifact[:exclude].present?
end
end
def create_reports(reports, expire_in:)
return unless reports&.any?
- reports.map do |report_type, report_paths|
- {
- artifact_type: report_type.to_sym,
- artifact_format: ::Ci::JobArtifact::TYPE_AND_FORMAT_PAIRS.fetch(report_type.to_sym),
- name: ::Ci::JobArtifact::DEFAULT_FILE_NAMES.fetch(report_type.to_sym),
- paths: report_paths,
+ reports.map { |report| BuildArtifact.for_report(report, expire_in).to_h.compact }
+ end
+
+ BuildArtifact = Struct.new(:name, :untracked, :paths, :exclude, :when, :expire_in, :artifact_type, :artifact_format, keyword_init: true) do
+ def self.for_archive(artifacts)
+ self.new(
+ artifact_type: :archive,
+ artifact_format: :zip,
+ name: artifacts[:name],
+ untracked: artifacts[:untracked],
+ paths: artifacts[:paths],
+ when: artifacts[:when],
+ expire_in: artifacts[:expire_in],
+ exclude: artifacts[:exclude]
+ )
+ end
+
+ def self.for_report(report, expire_in)
+ type, params = report
+
+ if type == :coverage_report
+ artifact_type = params[:coverage_format].to_sym
+ paths = [params[:path]]
+ else
+ artifact_type = type
+ paths = params
+ end
+
+ self.new(
+ artifact_type: artifact_type,
+ artifact_format: ::Ci::JobArtifact::TYPE_AND_FORMAT_PAIRS.fetch(artifact_type),
+ name: ::Ci::JobArtifact::DEFAULT_FILE_NAMES.fetch(artifact_type),
+ paths: paths,
when: 'always',
expire_in: expire_in
- }
+ )
end
end
diff --git a/app/presenters/clusterable_presenter.rb b/app/presenters/clusterable_presenter.rb
index 82152ce42ae..c2ed40d8b0c 100644
--- a/app/presenters/clusterable_presenter.rb
+++ b/app/presenters/clusterable_presenter.rb
@@ -36,6 +36,10 @@ class ClusterablePresenter < Gitlab::View::Presenter::Delegated
polymorphic_path([clusterable, :clusters], action: :connect)
end
+ def new_cluster_docs_path
+ polymorphic_path([clusterable, :clusters], action: :new_cluster_docs)
+ end
+
def authorize_aws_role_path
polymorphic_path([clusterable, :clusters], action: :authorize_aws_role)
end
diff --git a/app/presenters/commit_status_presenter.rb b/app/presenters/commit_status_presenter.rb
index 250715d7c9c..fdfcc896bf8 100644
--- a/app/presenters/commit_status_presenter.rb
+++ b/app/presenters/commit_status_presenter.rb
@@ -39,7 +39,7 @@ class CommitStatusPresenter < Gitlab::View::Presenter::Delegated
private_constant :CALLOUT_FAILURE_MESSAGES
- presents ::CommitStatus, as: :build
+ presents ::CommitStatus
def self.callout_failure_messages
CALLOUT_FAILURE_MESSAGES
diff --git a/app/presenters/dev_ops_report/metric_presenter.rb b/app/presenters/dev_ops_report/metric_presenter.rb
index 55326f8f678..ec85c5d3809 100644
--- a/app/presenters/dev_ops_report/metric_presenter.rb
+++ b/app/presenters/dev_ops_report/metric_presenter.rb
@@ -2,28 +2,28 @@
module DevOpsReport
class MetricPresenter < Gitlab::View::Presenter::Simple
- presents ::DevOpsReport::Metric
+ presents ::DevOpsReport::Metric, as: :metric
- delegate :created_at, to: :subject
+ delegate :created_at, to: :metric
def cards
[
Card.new(
- metric: subject,
+ metric: metric,
title: 'Issues',
description: 'created per active user',
feature: 'issues',
blog: 'https://www2.deloitte.com/content/dam/Deloitte/se/Documents/technology-media-telecommunications/deloitte-digital-collaboration.pdf'
),
Card.new(
- metric: subject,
+ metric: metric,
title: 'Comments',
description: 'created per active user',
feature: 'notes',
blog: 'http://conversationaldevelopment.com/why/'
),
Card.new(
- metric: subject,
+ metric: metric,
title: 'Milestones',
description: 'created per active user',
feature: 'milestones',
@@ -31,7 +31,7 @@ module DevOpsReport
docs: help_page_path('user/project/milestones/index')
),
Card.new(
- metric: subject,
+ metric: metric,
title: 'Boards',
description: 'created per active user',
feature: 'boards',
@@ -39,7 +39,7 @@ module DevOpsReport
docs: help_page_path('user/project/issue_board')
),
Card.new(
- metric: subject,
+ metric: metric,
title: 'Merge requests',
description: 'per active user',
feature: 'merge_requests',
@@ -47,7 +47,7 @@ module DevOpsReport
docs: help_page_path('user/project/merge_requests/index')
),
Card.new(
- metric: subject,
+ metric: metric,
title: 'Pipelines',
description: 'created per active user',
feature: 'ci_pipelines',
@@ -55,7 +55,7 @@ module DevOpsReport
docs: help_page_path('ci/index')
),
Card.new(
- metric: subject,
+ metric: metric,
title: 'Environments',
description: 'created per active user',
feature: 'environments',
@@ -63,14 +63,14 @@ module DevOpsReport
docs: help_page_path('ci/environments')
),
Card.new(
- metric: subject,
+ metric: metric,
title: 'Deployments',
description: 'created per active user',
feature: 'deployments',
blog: 'https://puppet.com/blog/continuous-delivery-vs-continuous-deployment-what-s-diff'
),
Card.new(
- metric: subject,
+ metric: metric,
title: 'Monitoring',
description: 'fraction of all projects',
feature: 'projects_prometheus_active',
@@ -78,7 +78,7 @@ module DevOpsReport
docs: help_page_path('user/project/integrations/prometheus')
),
Card.new(
- metric: subject,
+ metric: metric,
title: 'Service Desk',
description: 'issues created per active user',
feature: 'service_desk_issues',
@@ -91,52 +91,52 @@ module DevOpsReport
def idea_to_production_steps
[
IdeaToProductionStep.new(
- metric: subject,
+ metric: metric,
title: 'Idea',
features: %w(issues)
),
IdeaToProductionStep.new(
- metric: subject,
+ metric: metric,
title: 'Issue',
features: %w(issues notes)
),
IdeaToProductionStep.new(
- metric: subject,
+ metric: metric,
title: 'Plan',
features: %w(milestones boards)
),
IdeaToProductionStep.new(
- metric: subject,
+ metric: metric,
title: 'Code',
features: %w(merge_requests)
),
IdeaToProductionStep.new(
- metric: subject,
+ metric: metric,
title: 'Commit',
features: %w(merge_requests)
),
IdeaToProductionStep.new(
- metric: subject,
+ metric: metric,
title: 'Test',
features: %w(ci_pipelines)
),
IdeaToProductionStep.new(
- metric: subject,
+ metric: metric,
title: 'Review',
features: %w(ci_pipelines environments)
),
IdeaToProductionStep.new(
- metric: subject,
+ metric: metric,
title: 'Staging',
features: %w(environments deployments)
),
IdeaToProductionStep.new(
- metric: subject,
+ metric: metric,
title: 'Production',
features: %w(deployments)
),
IdeaToProductionStep.new(
- metric: subject,
+ metric: metric,
title: 'Feedback',
features: %w(projects_prometheus_active service_desk_issues)
)
diff --git a/app/presenters/event_presenter.rb b/app/presenters/event_presenter.rb
index 4c787b88e20..7fa87d33c0d 100644
--- a/app/presenters/event_presenter.rb
+++ b/app/presenters/event_presenter.rb
@@ -3,7 +3,7 @@
class EventPresenter < Gitlab::View::Presenter::Delegated
presents ::Event, as: :event
- def initialize(subject, **attributes)
+ def initialize(event, **attributes)
super
@visible_to_user_cache = ActiveSupport::Cache::MemoryStore.new
diff --git a/app/presenters/gitlab/blame_presenter.rb b/app/presenters/gitlab/blame_presenter.rb
index 5dd2f3adda5..81a954761ea 100644
--- a/app/presenters/gitlab/blame_presenter.rb
+++ b/app/presenters/gitlab/blame_presenter.rb
@@ -21,19 +21,23 @@ module Gitlab
:project_blame_link,
:time_ago_tooltip)
- def initialize(subject, **attributes)
+ def initialize(blame, **attributes)
super
@commits = {}
precalculate_data_by_commit!
end
+ def first_line
+ blame.first_line
+ end
+
def groups
@groups ||= blame.groups
end
- def commit_data(commit)
- @commits[commit.id] ||= get_commit_data(commit)
+ def commit_data(commit, previous_path = nil)
+ @commits[commit.id] ||= get_commit_data(commit, previous_path)
end
private
@@ -44,25 +48,25 @@ module Gitlab
# to avoid recalculating it multiple times.
# For such files, it could significantly improve the performance of the Blame.
def precalculate_data_by_commit!
- groups.each { |group| commit_data(group[:commit]) }
+ groups.each { |group| commit_data(group[:commit], group[:previous_path]) }
end
- def get_commit_data(commit)
+ def get_commit_data(commit, previous_path = nil)
CommitData.new.tap do |data|
data.author_avatar = author_avatar(commit, size: 36, has_tooltip: false, lazy: true)
data.age_map_class = age_map_class(commit.committed_date, project_duration)
data.commit_link = link_to commit.title, project_commit_path(project, commit.id), class: "cdark", title: commit.title
data.commit_author_link = commit_author_link(commit, avatar: false)
- data.project_blame_link = project_blame_link(commit)
+ data.project_blame_link = project_blame_link(commit, previous_path)
data.time_ago_tooltip = time_ago_with_tooltip(commit.committed_date)
end
end
- def project_blame_link(commit)
+ def project_blame_link(commit, previous_path = nil)
previous_commit_id = commit.parent_id
- return unless previous_commit_id
+ return unless previous_commit_id && !previous_path.nil?
- link_to project_blame_path(project, tree_join(previous_commit_id, path)),
+ link_to project_blame_path(project, tree_join(previous_commit_id, previous_path)),
title: _('View blame prior to this change'),
aria: { label: _('View blame prior to this change') },
class: 'version-link',
diff --git a/app/presenters/instance_clusterable_presenter.rb b/app/presenters/instance_clusterable_presenter.rb
index 9e4a3b403ea..001c9cbb4e9 100644
--- a/app/presenters/instance_clusterable_presenter.rb
+++ b/app/presenters/instance_clusterable_presenter.rb
@@ -43,6 +43,11 @@ class InstanceClusterablePresenter < ClusterablePresenter
connect_admin_clusters_path
end
+ override :new_cluster_docs_path
+ def new_cluster_docs_path
+ nil
+ end
+
override :create_user_clusters_path
def create_user_clusters_path
create_user_admin_clusters_path
diff --git a/app/presenters/issue_presenter.rb b/app/presenters/issue_presenter.rb
index 72fe14d224d..75f6d749acb 100644
--- a/app/presenters/issue_presenter.rb
+++ b/app/presenters/issue_presenter.rb
@@ -4,7 +4,9 @@ class IssuePresenter < Gitlab::View::Presenter::Delegated
presents ::Issue, as: :issue
def issue_path
- url_builder.build(issue, only_path: true)
+ return url_builder.build(issue, only_path: true) unless use_work_items_path?
+
+ project_work_items_path(issue.project, work_items_path: issue.id)
end
delegator_override :subscribed?
@@ -15,6 +17,18 @@ class IssuePresenter < Gitlab::View::Presenter::Delegated
def project_emails_disabled?
issue.project.emails_disabled?
end
+
+ def web_url
+ return super unless use_work_items_path?
+
+ project_work_items_url(issue.project, work_items_path: issue.id)
+ end
+
+ private
+
+ def use_work_items_path?
+ issue.issue_type == 'task' && issue.project.work_items_feature_flag_enabled?
+ end
end
IssuePresenter.prepend_mod_with('IssuePresenter')
diff --git a/app/presenters/label_presenter.rb b/app/presenters/label_presenter.rb
index 6929bf79fdf..e60cdf4088c 100644
--- a/app/presenters/label_presenter.rb
+++ b/app/presenters/label_presenter.rb
@@ -4,8 +4,6 @@ class LabelPresenter < Gitlab::View::Presenter::Delegated
presents ::Label, as: :label
delegate :name, :full_name, to: :label_subject, prefix: :subject, allow_nil: true
- delegator_override :subject # TODO: Fix `Gitlab::View::Presenter::Delegated#subject` not to override `Label#subject`.
-
def edit_path
case label
when GroupLabel then edit_group_label_path(label.group, label)
diff --git a/app/presenters/pages_domain_presenter.rb b/app/presenters/pages_domain_presenter.rb
index 0523f702416..d730608cc27 100644
--- a/app/presenters/pages_domain_presenter.rb
+++ b/app/presenters/pages_domain_presenter.rb
@@ -3,8 +3,6 @@
class PagesDomainPresenter < Gitlab::View::Presenter::Delegated
presents ::PagesDomain, as: :pages_domain
- delegator_override :subject # TODO: Fix `Gitlab::View::Presenter::Delegated#subject` not to override `PagesDomain#subject`.
-
def needs_verification?
Gitlab::CurrentSettings.pages_domain_verification_enabled? && unverified?
end
diff --git a/app/presenters/projects/security/configuration_presenter.rb b/app/presenters/projects/security/configuration_presenter.rb
index 1798d4b780f..77f4d57ae09 100644
--- a/app/presenters/projects/security/configuration_presenter.rb
+++ b/app/presenters/projects/security/configuration_presenter.rb
@@ -81,7 +81,8 @@ module Projects
configured: scan.configured?,
configuration_path: scan.configuration_path,
available: scan.available?,
- can_enable_by_merge_request: scan.can_enable_by_merge_request?
+ can_enable_by_merge_request: scan.can_enable_by_merge_request?,
+ meta_info_path: scan.meta_info_path
}
end