diff options
Diffstat (limited to 'app/presenters')
-rw-r--r-- | app/presenters/alert_management/alert_presenter.rb | 33 | ||||
-rw-r--r-- | app/presenters/clusterable_presenter.rb | 2 | ||||
-rw-r--r-- | app/presenters/environment_presenter.rb | 13 | ||||
-rw-r--r-- | app/presenters/event_presenter.rb | 22 | ||||
-rw-r--r-- | app/presenters/instance_clusterable_presenter.rb | 2 | ||||
-rw-r--r-- | app/presenters/issue_presenter.rb | 2 | ||||
-rw-r--r-- | app/presenters/label_presenter.rb | 5 | ||||
-rw-r--r-- | app/presenters/merge_request_presenter.rb | 2 | ||||
-rw-r--r-- | app/presenters/packages/detail/package_presenter.rb | 6 | ||||
-rw-r--r-- | app/presenters/packages/pypi/package_presenter.rb | 4 | ||||
-rw-r--r-- | app/presenters/project_presenter.rb | 52 | ||||
-rw-r--r-- | app/presenters/projects/prometheus/alert_presenter.rb | 179 | ||||
-rw-r--r-- | app/presenters/release_presenter.rb | 2 | ||||
-rw-r--r-- | app/presenters/sentry_error_presenter.rb | 2 | ||||
-rw-r--r-- | app/presenters/snippet_blob_presenter.rb | 8 | ||||
-rw-r--r-- | app/presenters/snippet_presenter.rb | 10 |
16 files changed, 122 insertions, 222 deletions
diff --git a/app/presenters/alert_management/alert_presenter.rb b/app/presenters/alert_management/alert_presenter.rb index 5debe6d5dbd..4bfa3dc9a13 100644 --- a/app/presenters/alert_management/alert_presenter.rb +++ b/app/presenters/alert_management/alert_presenter.rb @@ -8,10 +8,11 @@ module AlertManagement MARKDOWN_LINE_BREAK = " \n" HORIZONTAL_LINE = "\n\n---\n\n" + INCIDENT_LABEL_NAME = ::IncidentManagement::CreateIncidentLabelService::LABEL_PROPERTIES[:title] delegate :metrics_dashboard_url, :runbook, to: :parsed_payload - def initialize(alert, _attributes = {}) + def initialize(alert, **attributes) super @alert = alert @@ -38,6 +39,30 @@ module AlertManagement Gitlab::Utils::InlineHash.merge_keys(payload) end + def show_incident_issues_link? + project.incident_management_setting&.create_issue? + end + + def show_performance_dashboard_link? + prometheus_alert.present? + end + + def incident_issues_link + project_issues_url(project, label_name: INCIDENT_LABEL_NAME) + end + + def performance_dashboard_link + if environment + metrics_project_environment_url(project, environment) + else + metrics_project_environments_url(project) + end + end + + def email_title + [environment&.name, query_title].compact.join(': ') + end + private attr_reader :alert, :project @@ -80,5 +105,11 @@ module AlertManagement def host_links hosts.join(' ') end + + def query_title + return title unless prometheus_alert + + "#{prometheus_alert.title} #{prometheus_alert.computed_operator} #{prometheus_alert.threshold} for 5 minutes" + end end end diff --git a/app/presenters/clusterable_presenter.rb b/app/presenters/clusterable_presenter.rb index efb3cf7f348..62488465c24 100644 --- a/app/presenters/clusterable_presenter.rb +++ b/app/presenters/clusterable_presenter.rb @@ -8,7 +8,7 @@ class ClusterablePresenter < Gitlab::View::Presenter::Delegated attributes_with_presenter_class = attributes.merge(presenter_class: presenter_class) Gitlab::View::Presenter::Factory - .new(clusterable, attributes_with_presenter_class) + .new(clusterable, **attributes_with_presenter_class) .fabricate! end diff --git a/app/presenters/environment_presenter.rb b/app/presenters/environment_presenter.rb new file mode 100644 index 00000000000..3fa31eb69a2 --- /dev/null +++ b/app/presenters/environment_presenter.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class EnvironmentPresenter < Gitlab::View::Presenter::Delegated + include ActionView::Helpers::UrlHelper + + presents :environment + + def path + if Feature.enabled?(:expose_environment_path_in_alert_details, project) + project_environment_path(project, self) + end + end +end diff --git a/app/presenters/event_presenter.rb b/app/presenters/event_presenter.rb index 8f2388c2c31..c37721f7213 100644 --- a/app/presenters/event_presenter.rb +++ b/app/presenters/event_presenter.rb @@ -29,4 +29,26 @@ class EventPresenter < Gitlab::View::Presenter::Delegated '' end end + + def target_type_name + if design? + 'Design' + elsif wiki_page? + 'Wiki Page' + elsif target_type.present? + target_type.titleize + else + "Project" + end.downcase + end + + def note_target_type_name + return unless note? + + if design_note? + 'Design' + else + target.noteable_type.titleize + end.downcase + end end diff --git a/app/presenters/instance_clusterable_presenter.rb b/app/presenters/instance_clusterable_presenter.rb index 7704e6b59c1..94c1195ed6a 100644 --- a/app/presenters/instance_clusterable_presenter.rb +++ b/app/presenters/instance_clusterable_presenter.rb @@ -8,7 +8,7 @@ class InstanceClusterablePresenter < ClusterablePresenter attributes_with_presenter_class = attributes.merge(presenter_class: InstanceClusterablePresenter) Gitlab::View::Presenter::Factory - .new(clusterable, attributes_with_presenter_class) + .new(clusterable, **attributes_with_presenter_class) .fabricate! end diff --git a/app/presenters/issue_presenter.rb b/app/presenters/issue_presenter.rb index 185fcd3e934..0b498ce97d8 100644 --- a/app/presenters/issue_presenter.rb +++ b/app/presenters/issue_presenter.rb @@ -11,3 +11,5 @@ class IssuePresenter < Gitlab::View::Presenter::Delegated issue.subscribed?(current_user, issue.project) end end + +IssuePresenter.prepend_if_ee('EE::IssuePresenter') diff --git a/app/presenters/label_presenter.rb b/app/presenters/label_presenter.rb index 68aa05ada8e..c23d6ce2218 100644 --- a/app/presenters/label_presenter.rb +++ b/app/presenters/label_presenter.rb @@ -2,6 +2,7 @@ class LabelPresenter < Gitlab::View::Presenter::Delegated presents :label + delegate :name, :full_name, to: :label_subject, prefix: :subject def edit_path case label @@ -39,8 +40,8 @@ class LabelPresenter < Gitlab::View::Presenter::Delegated label.is_a?(ProjectLabel) end - def subject_name - label.subject.name + def label_subject + @label_subject ||= label.subject end private diff --git a/app/presenters/merge_request_presenter.rb b/app/presenters/merge_request_presenter.rb index 1ff02412994..a22138011ae 100644 --- a/app/presenters/merge_request_presenter.rb +++ b/app/presenters/merge_request_presenter.rb @@ -37,7 +37,7 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated end def remove_wip_path - if work_in_progress? && can?(current_user, :update_merge_request, merge_request.project) + if can?(current_user, :update_merge_request, merge_request.project) remove_wip_project_merge_request_path(project, merge_request) end end diff --git a/app/presenters/packages/detail/package_presenter.rb b/app/presenters/packages/detail/package_presenter.rb index bdb2e34854e..e8223d6498b 100644 --- a/app/presenters/packages/detail/package_presenter.rb +++ b/app/presenters/packages/detail/package_presenter.rb @@ -8,10 +8,13 @@ module Packages end def detail_view + name = @package.name + name = @package.conan_recipe if @package.conan? + package_detail = { id: @package.id, created_at: @package.created_at, - name: @package.name, + name: name, package_files: @package.package_files.map { |pf| build_package_file_view(pf) }, package_type: @package.package_type, project_id: @package.project_id, @@ -20,6 +23,7 @@ module Packages version: @package.version } + package_detail[:conan_package_name] = @package.name if @package.conan? package_detail[:maven_metadatum] = @package.maven_metadatum if @package.maven_metadatum package_detail[:nuget_metadatum] = @package.nuget_metadatum if @package.nuget_metadatum package_detail[:composer_metadatum] = @package.composer_metadatum if @package.composer_metadatum diff --git a/app/presenters/packages/pypi/package_presenter.rb b/app/presenters/packages/pypi/package_presenter.rb index 4192e974645..1cb11c7be1a 100644 --- a/app/presenters/packages/pypi/package_presenter.rb +++ b/app/presenters/packages/pypi/package_presenter.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Display package version data acording to PyPi +# Display package version data acording to PyPI # Simple API: https://warehouse.pypa.io/api-reference/legacy/#simple-project-api module Packages module Pypi @@ -12,7 +12,7 @@ module Packages @project = project end - # Returns the HTML body for PyPi simple API. + # Returns the HTML body for PyPI simple API. # Basically a list of package download links for a specific # package def body diff --git a/app/presenters/project_presenter.rb b/app/presenters/project_presenter.rb index ef75c160b2d..392eeafb2b4 100644 --- a/app/presenters/project_presenter.rb +++ b/app/presenters/project_presenter.rb @@ -65,14 +65,14 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated if can?(current_user, :download_code, project) user_view - elsif user_view == "activity" - "activity" - elsif can?(current_user, :read_wiki, project) - "wiki" - elsif feature_available?(:issues, current_user) - "projects/issues/issues" + elsif user_view == 'activity' + 'activity' + elsif project.wiki_repository_exists? && can?(current_user, :read_wiki, project) + 'wiki' + elsif can?(current_user, :read_issue, project) + 'projects/issues/issues' else - "customize_workflow" + 'activity' end end @@ -106,26 +106,38 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated add_special_file_path(file_name: 'LICENSE') end + def add_license_ide_path + ide_edit_path(project, default_branch_or_master, 'LICENSE') + end + def add_changelog_path add_special_file_path(file_name: 'CHANGELOG') end + def add_changelog_ide_path + ide_edit_path(project, default_branch_or_master, 'CHANGELOG') + end + def add_contribution_guide_path add_special_file_path(file_name: 'CONTRIBUTING.md', commit_message: 'Add CONTRIBUTING') end - def add_ci_yml_path - add_special_file_path(file_name: ci_config_path_or_default) + def add_contribution_guide_ide_path + ide_edit_path(project, default_branch_or_master, 'CONTRIBUTING.md') end - def add_ci_yml_ide_path - ide_edit_path(project, default_branch_or_master, ci_config_path_or_default) + def add_ci_yml_path + add_special_file_path(file_name: ci_config_path_or_default) end def add_readme_path add_special_file_path(file_name: 'README.md') end + def add_readme_ide_path + ide_edit_path(project, default_branch_or_master, 'README.md') + end + def license_short_name license = repository.license license&.nickname || license&.name || 'LICENSE' @@ -222,9 +234,11 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated def new_file_anchor_data if current_user && can_current_user_push_to_default_branch? + new_file_path = empty_repo? ? ide_edit_path(project, default_branch_or_master) : project_new_blob_path(project, default_branch_or_master) + AnchorData.new(false, statistic_icon + _('New file'), - project_new_blob_path(project, default_branch_or_master), + new_file_path, 'missing') end end @@ -233,7 +247,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated if current_user && can_current_user_push_to_default_branch? && repository.readme.nil? AnchorData.new(false, statistic_icon + _('Add README'), - add_readme_path) + empty_repo? ? add_readme_ide_path : add_readme_path) elsif repository.readme AnchorData.new(false, statistic_icon('doc-text') + _('README'), @@ -247,7 +261,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated if current_user && can_current_user_push_to_default_branch? && repository.changelog.blank? AnchorData.new(false, statistic_icon + _('Add CHANGELOG'), - add_changelog_path) + empty_repo? ? add_changelog_ide_path : add_changelog_path) elsif repository.changelog.present? AnchorData.new(false, statistic_icon('doc-text') + _('CHANGELOG'), @@ -268,7 +282,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated if current_user && can_current_user_push_to_default_branch? AnchorData.new(false, content_tag(:span, statistic_icon + _('Add LICENSE'), class: 'add-license-link d-flex'), - add_license_path) + empty_repo? ? add_license_ide_path : add_license_path) else AnchorData.new(false, icon + content_tag(:span, _('No license. All rights reserved'), class: 'project-stat-value'), @@ -281,7 +295,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated if current_user && can_current_user_push_to_default_branch? && repository.contribution_guide.blank? AnchorData.new(false, statistic_icon + _('Add CONTRIBUTING'), - add_contribution_guide_path) + empty_repo? ? add_contribution_guide_ide_path : add_contribution_guide_path) elsif repository.contribution_guide.present? AnchorData.new(false, statistic_icon('doc-text') + _('CONTRIBUTING'), @@ -330,7 +344,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated if cicd_missing? AnchorData.new(false, statistic_icon + _('Set up CI/CD'), - add_ci_yml_ide_path) + add_ci_yml_path) elsif repository.gitlab_ci_yml.present? AnchorData.new(false, statistic_icon('doc-text') + _('CI/CD configuration'), @@ -393,6 +407,10 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated def anonymous_project_view if !project.empty_repo? && can?(current_user, :download_code, project) 'files' + elsif project.wiki_repository_exists? && can?(current_user, :read_wiki, project) + 'wiki' + elsif can?(current_user, :read_issue, project) + 'projects/issues/issues' else 'activity' end diff --git a/app/presenters/projects/prometheus/alert_presenter.rb b/app/presenters/projects/prometheus/alert_presenter.rb deleted file mode 100644 index 783b2b2b1e0..00000000000 --- a/app/presenters/projects/prometheus/alert_presenter.rb +++ /dev/null @@ -1,179 +0,0 @@ -# frozen_string_literal: true - -module Projects - module Prometheus - class AlertPresenter < Gitlab::View::Presenter::Delegated - GENERIC_ALERT_SUMMARY_ANNOTATIONS = %w(monitoring_tool service hosts).freeze - MARKDOWN_LINE_BREAK = " \n".freeze - INCIDENT_LABEL_NAME = ::IncidentManagement::CreateIncidentLabelService::LABEL_PROPERTIES[:title].freeze - METRIC_TIME_WINDOW = 30.minutes - - def full_title - [environment_name, alert_title].compact.join(': ') - end - - def project_full_path - project.full_path - end - - def metric_query - gitlab_alert&.full_query - end - - def environment_name - environment&.name - end - - def performance_dashboard_link - if environment - metrics_project_environment_url(project, environment) - else - metrics_project_environments_url(project) - end - end - - def show_performance_dashboard_link? - gitlab_alert.present? - end - - def show_incident_issues_link? - project.incident_management_setting&.create_issue? - end - - def incident_issues_link - project_issues_url(project, label_name: INCIDENT_LABEL_NAME) - end - - def start_time - starts_at&.strftime('%d %B %Y, %-l:%M%p (%Z)') - end - - def issue_summary_markdown - <<~MARKDOWN.chomp - #{metadata_list} - #{metric_embed_for_alert} - MARKDOWN - end - - def metric_embed_for_alert - "\n[](#{metrics_dashboard_url})" if metrics_dashboard_url - end - - def metrics_dashboard_url - strong_memoize(:metrics_dashboard_url) do - embed_url_for_gitlab_alert || embed_url_for_self_managed_alert - end - end - - def details_url - return unless am_alert - - ::Gitlab::Routing.url_helpers.details_project_alert_management_url( - project, - am_alert.iid - ) - end - - private - - def alert_title - query_title || title - end - - def query_title - return unless gitlab_alert - - "#{gitlab_alert.title} #{gitlab_alert.computed_operator} #{gitlab_alert.threshold} for 5 minutes" - end - - def metadata_list - metadata = [] - - metadata << list_item('Start time', start_time) if start_time - metadata << list_item('full_query', backtick(full_query)) if full_query - metadata << list_item(service.label.humanize, service.value) if service - metadata << list_item(monitoring_tool.label.humanize, monitoring_tool.value) if monitoring_tool - metadata << list_item(hosts.label.humanize, host_links) if hosts - metadata << list_item('GitLab alert', details_url) if details_url - - metadata.join(MARKDOWN_LINE_BREAK) - end - - def details - Gitlab::Utils::InlineHash.merge_keys(payload) - end - - def list_item(key, value) - "**#{key}:** #{value}".strip - end - - def backtick(value) - "`#{value}`" - end - - GENERIC_ALERT_SUMMARY_ANNOTATIONS.each do |annotation_name| - define_method(annotation_name) do - annotations.find { |a| a.label == annotation_name } - end - end - - def host_links - Array(hosts.value).join(' ') - end - - def embed_url_for_gitlab_alert - return unless gitlab_alert - - metrics_dashboard_project_prometheus_alert_url( - project, - gitlab_alert.prometheus_metric_id, - environment_id: environment.id, - embedded: true, - **alert_embed_window_params(embed_time) - ) - end - - def embed_url_for_self_managed_alert - return unless environment && full_query && title - - metrics_dashboard_project_environment_url( - project, - environment, - embed_json: dashboard_for_self_managed_alert.to_json, - embedded: true, - **alert_embed_window_params(embed_time) - ) - end - - def embed_time - starts_at || Time.current - end - - def alert_embed_window_params(time) - { - start: format_embed_timestamp(time - METRIC_TIME_WINDOW), - end: format_embed_timestamp(time + METRIC_TIME_WINDOW) - } - end - - def format_embed_timestamp(time) - time.utc.strftime('%FT%TZ') - end - - def dashboard_for_self_managed_alert - { - panel_groups: [{ - panels: [{ - type: 'area-chart', - title: title, - y_label: y_label, - metrics: [{ - query_range: full_query - }] - }] - }] - } - end - end - end -end diff --git a/app/presenters/release_presenter.rb b/app/presenters/release_presenter.rb index 4393ca05f48..c27059c6d63 100644 --- a/app/presenters/release_presenter.rb +++ b/app/presenters/release_presenter.rb @@ -20,8 +20,6 @@ class ReleasePresenter < Gitlab::View::Presenter::Delegated end def self_url - return unless ::Feature.enabled?(:release_show_page, project, default_enabled: true) - project_release_url(project, release) end diff --git a/app/presenters/sentry_error_presenter.rb b/app/presenters/sentry_error_presenter.rb index ba724b0f8be..669bcb68b7c 100644 --- a/app/presenters/sentry_error_presenter.rb +++ b/app/presenters/sentry_error_presenter.rb @@ -14,7 +14,7 @@ class SentryErrorPresenter < Gitlab::View::Presenter::Delegated end def project_id - Gitlab::GlobalId.build(model_name: 'Project', id: error.project_id).to_s + Gitlab::GlobalId.build(model_name: 'SentryProject', id: error.project_id).to_s end def frequency diff --git a/app/presenters/snippet_blob_presenter.rb b/app/presenters/snippet_blob_presenter.rb index abe95f5c44d..597ef6ebc39 100644 --- a/app/presenters/snippet_blob_presenter.rb +++ b/app/presenters/snippet_blob_presenter.rb @@ -25,10 +25,6 @@ class SnippetBlobPresenter < BlobPresenter private - def snippet_multiple_files? - blob.container.repository_exists? && Feature.enabled?(:snippet_multiple_files, current_user) - end - def snippet blob.container end @@ -52,8 +48,8 @@ class SnippetBlobPresenter < BlobPresenter end def snippet_blob_raw_route(only_path: false) - return gitlab_raw_snippet_blob_url(snippet, blob.path, only_path: only_path) if snippet_multiple_files? + return gitlab_raw_snippet_url(snippet, only_path: only_path) unless snippet.repository_exists? - gitlab_raw_snippet_url(snippet, only_path: only_path) + gitlab_raw_snippet_blob_url(snippet, blob.path, only_path: only_path) end end diff --git a/app/presenters/snippet_presenter.rb b/app/presenters/snippet_presenter.rb index d814c4404b6..695aa266e2c 100644 --- a/app/presenters/snippet_presenter.rb +++ b/app/presenters/snippet_presenter.rb @@ -32,15 +32,9 @@ class SnippetPresenter < Gitlab::View::Presenter::Delegated end def blob - blobs.first - end + return snippet.blob if snippet.empty_repo? - def blobs - if snippet.empty_repo? - [snippet.blob] - else - snippet.blobs - end + blobs.first end private |