From 9f46488805e86b1bc341ea1620b866016c2ce5ed Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 20 May 2020 14:34:42 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-0-stable-ee --- app/helpers/access_tokens_helper.rb | 7 ++ app/helpers/appearances_helper.rb | 4 ++ app/helpers/application_helper.rb | 4 ++ app/helpers/application_settings_helper.rb | 13 ++-- app/helpers/auth_helper.rb | 6 +- app/helpers/blob_helper.rb | 21 +++--- app/helpers/boards_helper.rb | 3 +- app/helpers/button_helper.rb | 4 +- app/helpers/clusters_helper.rb | 11 +++ app/helpers/commits_helper.rb | 2 + app/helpers/environment_helper.rb | 2 +- app/helpers/environments_helper.rb | 89 +++++++++++++++++-------- app/helpers/events_helper.rb | 14 ++++ app/helpers/export_helper.rb | 13 +++- app/helpers/form_helper.rb | 4 +- app/helpers/groups_helper.rb | 4 ++ app/helpers/icons_helper.rb | 2 +- app/helpers/issuables_helper.rb | 28 ++------ app/helpers/issues_helper.rb | 16 ++--- app/helpers/members_helper.rb | 13 +++- app/helpers/milestones_helper.rb | 2 +- app/helpers/namespaces_helper.rb | 4 +- app/helpers/nav_helper.rb | 5 +- app/helpers/preferences_helper.rb | 2 +- app/helpers/projects/alert_management_helper.rb | 21 ++++++ app/helpers/projects_helper.rb | 19 ++++-- app/helpers/releases_helper.rb | 4 +- app/helpers/search_helper.rb | 6 +- app/helpers/services_helper.rb | 12 ++-- app/helpers/snippets_helper.rb | 76 --------------------- app/helpers/sorting_helper.rb | 4 +- app/helpers/system_note_helper.rb | 8 ++- app/helpers/todos_helper.rb | 19 +++++- app/helpers/workhorse_helper.rb | 4 +- app/helpers/x509_helper.rb | 4 ++ 35 files changed, 253 insertions(+), 197 deletions(-) create mode 100644 app/helpers/access_tokens_helper.rb create mode 100644 app/helpers/projects/alert_management_helper.rb (limited to 'app/helpers') diff --git a/app/helpers/access_tokens_helper.rb b/app/helpers/access_tokens_helper.rb new file mode 100644 index 00000000000..877ad6db576 --- /dev/null +++ b/app/helpers/access_tokens_helper.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module AccessTokensHelper + def scope_description(prefix) + prefix == :project_access_token ? [:doorkeeper, :project_access_token_scope_desc] : [:doorkeeper, :scope_desc] + end +end diff --git a/app/helpers/appearances_helper.rb b/app/helpers/appearances_helper.rb index 0c1b2c7d093..3ae9f93a27a 100644 --- a/app/helpers/appearances_helper.rb +++ b/app/helpers/appearances_helper.rb @@ -25,6 +25,10 @@ module AppearancesHelper markdown_field(current_appearance, :new_project_guidelines) end + def brand_profile_image_guidelines + markdown_field(current_appearance, :profile_image_guidelines) + end + def current_appearance strong_memoize(:current_appearance) do Appearance.current diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a815b378f8b..2df33073a89 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -54,6 +54,10 @@ module ApplicationHelper args.any? { |v| v.to_s.downcase == action_name } end + def admin_section? + controller.class.ancestors.include?(Admin::ApplicationController) + end + def last_commit(project) if project.repo_exists? time_ago_with_tooltip(project.repository.commit.committed_date) diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb index 443451cd394..b9f0e3582df 100644 --- a/app/helpers/application_settings_helper.rb +++ b/app/helpers/application_settings_helper.rb @@ -229,14 +229,7 @@ module ApplicationSettingsHelper :max_artifacts_size, :max_attachment_size, :max_pages_size, - :metrics_enabled, - :metrics_host, :metrics_method_call_threshold, - :metrics_packet_size, - :metrics_pool_size, - :metrics_port, - :metrics_sample_interval, - :metrics_timeout, :minimum_password_length, :mirror_available, :pages_domain_verification_enabled, @@ -310,7 +303,9 @@ module ApplicationSettingsHelper :custom_http_clone_url_root, :snippet_size_limit, :email_restrictions_enabled, - :email_restrictions + :email_restrictions, + :issues_create_limit, + :raw_blob_request_limit ] end @@ -365,7 +360,7 @@ module ApplicationSettingsHelper end end -ApplicationSettingsHelper.prepend_if_ee('EE::ApplicationSettingsHelper') # rubocop: disable Cop/InjectEnterpriseEditionModule +ApplicationSettingsHelper.prepend_if_ee('EE::ApplicationSettingsHelper') # The methods in `EE::ApplicationSettingsHelper` should be available as both # instance and class methods. diff --git a/app/helpers/auth_helper.rb b/app/helpers/auth_helper.rb index 1f1ff75359d..a57e27d23c8 100644 --- a/app/helpers/auth_helper.rb +++ b/app/helpers/auth_helper.rb @@ -145,10 +145,14 @@ module AuthHelper IdentityProviderPolicy.new(current_user, provider).can?(:link) end + def allow_admin_mode_password_authentication_for_web? + current_user.allow_password_authentication_for_web? && !current_user.password_automatically_set? + end + extend self end -AuthHelper.prepend_if_ee('EE::AuthHelper') # rubocop: disable Cop/InjectEnterpriseEditionModule +AuthHelper.prepend_if_ee('EE::AuthHelper') # The methods added in EE should be available as both class and instance # methods, just like the methods provided by `AuthHelper` itself. diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 4debf66db64..69fe3303840 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -17,7 +17,7 @@ module BlobHelper options[:link_opts]) end - def ide_edit_path(project = @project, ref = @ref, path = @path, options = {}) + def ide_edit_path(project = @project, ref = @ref, path = @path) project_path = if !current_user || can?(current_user, :push_code, project) project.full_path @@ -52,28 +52,25 @@ module BlobHelper edit_button_tag(blob, common_classes, _('Edit'), - Feature.enabled?(:web_ide_default) ? ide_edit_path(project, ref, path, options) : edit_blob_path(project, ref, path, options), + Feature.enabled?(:web_ide_default) ? ide_edit_path(project, ref, path) : edit_blob_path(project, ref, path, options), project, ref) end - def ide_edit_button(project = @project, ref = @ref, path = @path, options = {}) + def ide_edit_button(project = @project, ref = @ref, path = @path, blob:) return if Feature.enabled?(:web_ide_default) - return unless blob = readable_blob(options, path, project, ref) + return unless blob edit_button_tag(blob, 'btn btn-inverted btn-primary ide-edit-button ml-2', _('Web IDE'), - ide_edit_path(project, ref, path, options), + ide_edit_path(project, ref, path), project, ref) end - def modify_file_button(project = @project, ref = @ref, path = @path, label:, action:, btn_class:, modal_type:) + def modify_file_button(project = @project, ref = @ref, path = @path, blob:, label:, action:, btn_class:, modal_type:) return unless current_user - - blob = project.repository.blob_at(ref, path) rescue nil - return unless blob common_classes = "btn btn-#{btn_class}" @@ -89,11 +86,12 @@ module BlobHelper end end - def replace_blob_link(project = @project, ref = @ref, path = @path) + def replace_blob_link(project = @project, ref = @ref, path = @path, blob:) modify_file_button( project, ref, path, + blob: blob, label: _("Replace"), action: "replace", btn_class: "default", @@ -101,11 +99,12 @@ module BlobHelper ) end - def delete_blob_link(project = @project, ref = @ref, path = @path) + def delete_blob_link(project = @project, ref = @ref, path = @path, blob:) modify_file_button( project, ref, path, + blob: blob, label: _("Delete"), action: "delete", btn_class: "default", diff --git a/app/helpers/boards_helper.rb b/app/helpers/boards_helper.rb index c14bc454bb9..f8c00f3a4cd 100644 --- a/app/helpers/boards_helper.rb +++ b/app/helpers/boards_helper.rb @@ -16,7 +16,8 @@ module BoardsHelper full_path: full_path, bulk_update_path: @bulk_issues_path, time_tracking_limit_to_hours: Gitlab::CurrentSettings.time_tracking_limit_to_hours.to_s, - recent_boards_endpoint: recent_boards_path + recent_boards_endpoint: recent_boards_path, + parent: current_board_parent.model_name.param_key } end diff --git a/app/helpers/button_helper.rb b/app/helpers/button_helper.rb index e1aed5393ea..c999d1f94ad 100644 --- a/app/helpers/button_helper.rb +++ b/app/helpers/button_helper.rb @@ -93,8 +93,8 @@ module ButtonHelper content_tag (href ? :a : :span), (href ? button_content : title), class: "#{title.downcase}-selector #{active_class}", - href: (href if href), - data: (data if data) + href: href, + data: data end end diff --git a/app/helpers/clusters_helper.rb b/app/helpers/clusters_helper.rb index a97216f8a22..39aaf242231 100644 --- a/app/helpers/clusters_helper.rb +++ b/app/helpers/clusters_helper.rb @@ -17,6 +17,17 @@ module ClustersHelper end end + def provider_icon(provider = nil) + case provider + when 'aws' + image_tag 'illustrations/logos/amazon_eks.svg', alt: s_('ClusterIntegration|Amazon EKS'), class: 'gl-h-full' + when 'gcp' + image_tag 'illustrations/logos/google_gke.svg', alt: s_('ClusterIntegration|Google GKE'), class: 'gl-h-full' + else + image_tag 'illustrations/logos/kubernetes.svg', alt: _('Kubernetes Cluster'), class: 'gl-h-full' + end + end + def render_gcp_signup_offer return if Gitlab::CurrentSettings.current_application_settings.hide_third_party_offers? return unless show_gcp_signup_offer? diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb index ace8bae03ac..2a0c2e73dd6 100644 --- a/app/helpers/commits_helper.rb +++ b/app/helpers/commits_helper.rb @@ -215,6 +215,8 @@ module CommitsHelper def commit_path(project, commit, merge_request: nil) if merge_request&.persisted? diffs_project_merge_request_path(project, merge_request, commit_id: commit.id) + elsif merge_request + project_commit_path(merge_request&.source_project, commit) else project_commit_path(project, commit) end diff --git a/app/helpers/environment_helper.rb b/app/helpers/environment_helper.rb index 52f189b122f..bd400009c96 100644 --- a/app/helpers/environment_helper.rb +++ b/app/helpers/environment_helper.rb @@ -25,7 +25,7 @@ module EnvironmentHelper def deployment_link(deployment, text: nil) return unless deployment - link_label = text ? text : "##{deployment.iid}" + link_label = text || "##{deployment.iid}" link_to link_label, deployment_path(deployment) end diff --git a/app/helpers/environments_helper.rb b/app/helpers/environments_helper.rb index 5b640ea6538..e7b561af3da 100644 --- a/app/helpers/environments_helper.rb +++ b/app/helpers/environments_helper.rb @@ -2,7 +2,6 @@ module EnvironmentsHelper include ActionView::Helpers::AssetUrlHelper - prepend_if_ee('::EE::EnvironmentsHelper') # rubocop: disable Cop/InjectEnterpriseEditionModule def environments_list_data { @@ -23,31 +22,13 @@ module EnvironmentsHelper end def metrics_data(project, environment) - { - "settings-path" => edit_project_service_path(project, 'prometheus'), - "clusters-path" => project_clusters_path(project), - "current-environment-name" => environment.name, - "documentation-path" => help_page_path('administration/monitoring/prometheus/index.md'), - "empty-getting-started-svg-path" => image_path('illustrations/monitoring/getting_started.svg'), - "empty-loading-svg-path" => image_path('illustrations/monitoring/loading.svg'), - "empty-no-data-svg-path" => image_path('illustrations/monitoring/no_data.svg'), - "empty-no-data-small-svg-path" => image_path('illustrations/chart-empty-state-small.svg'), - "empty-unable-to-connect-svg-path" => image_path('illustrations/monitoring/unable_to_connect.svg'), - "metrics-endpoint" => additional_metrics_project_environment_path(project, environment, format: :json), - "dashboards-endpoint" => project_performance_monitoring_dashboards_path(project, format: :json), - "dashboard-endpoint" => metrics_dashboard_project_environment_path(project, environment, format: :json), - "deployments-endpoint" => project_environment_deployments_path(project, environment, format: :json), - "default-branch" => project.default_branch, - "project-path" => project_path(project), - "tags-path" => project_tags_path(project), - "has-metrics" => "#{environment.has_metrics?}", - "prometheus-status" => "#{environment.prometheus_status}", - "external-dashboard-url" => project.metrics_setting_external_dashboard_url, - "environment-state" => "#{environment.state}", - "custom-metrics-path" => project_prometheus_metrics_path(project), - "validate-query-path" => validate_query_project_prometheus_metrics_path(project), - "custom-metrics-available" => "#{custom_metrics_available?(project)}" - } + metrics_data = {} + metrics_data.merge!(project_metrics_data(project)) if project + metrics_data.merge!(environment_metrics_data(environment)) if environment + metrics_data.merge!(project_and_environment_metrics_data(project, environment)) if project && environment + metrics_data.merge!(static_metrics_data) + + metrics_data end def environment_logs_data(project, environment) @@ -62,4 +43,60 @@ module EnvironmentsHelper def can_destroy_environment?(environment) can?(current_user, :destroy_environment, environment) end + + private + + def project_metrics_data(project) + return {} unless project + + { + 'settings-path' => edit_project_service_path(project, 'prometheus'), + 'clusters-path' => project_clusters_path(project), + 'dashboards-endpoint' => project_performance_monitoring_dashboards_path(project, format: :json), + 'default-branch' => project.default_branch, + 'project-path' => project_path(project), + 'tags-path' => project_tags_path(project), + 'external-dashboard-url' => project.metrics_setting_external_dashboard_url, + 'custom-metrics-path' => project_prometheus_metrics_path(project), + 'validate-query-path' => validate_query_project_prometheus_metrics_path(project), + 'custom-metrics-available' => "#{custom_metrics_available?(project)}", + 'prometheus-alerts-available' => "#{can?(current_user, :read_prometheus_alerts, project)}" + } + end + + def environment_metrics_data(environment) + return {} unless environment + + { + 'current-environment-name' => environment.name, + 'has-metrics' => "#{environment.has_metrics?}", + 'prometheus-status' => "#{environment.prometheus_status}", + 'environment-state' => "#{environment.state}" + } + end + + def project_and_environment_metrics_data(project, environment) + return {} unless project && environment + + { + 'metrics-endpoint' => additional_metrics_project_environment_path(project, environment, format: :json), + 'dashboard-endpoint' => metrics_dashboard_project_environment_path(project, environment, format: :json), + 'deployments-endpoint' => project_environment_deployments_path(project, environment, format: :json), + 'alerts-endpoint' => project_prometheus_alerts_path(project, environment_id: environment.id, format: :json) + + } + end + + def static_metrics_data + { + 'documentation-path' => help_page_path('administration/monitoring/prometheus/index.md'), + 'empty-getting-started-svg-path' => image_path('illustrations/monitoring/getting_started.svg'), + 'empty-loading-svg-path' => image_path('illustrations/monitoring/loading.svg'), + 'empty-no-data-svg-path' => image_path('illustrations/monitoring/no_data.svg'), + 'empty-no-data-small-svg-path' => image_path('illustrations/chart-empty-state-small.svg'), + 'empty-unable-to-connect-svg-path' => image_path('illustrations/monitoring/unable_to_connect.svg') + } + end end + +EnvironmentsHelper.prepend_if_ee('::EE::EnvironmentsHelper') diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index ba8e046f504..e93aeba6dfd 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -4,12 +4,14 @@ module EventsHelper ICON_NAMES_BY_EVENT_TYPE = { 'pushed to' => 'commit', 'pushed new' => 'commit', + 'updated' => 'commit', 'created' => 'status_open', 'opened' => 'status_open', 'closed' => 'status_closed', 'accepted' => 'fork', 'commented on' => 'comment', 'deleted' => 'remove', + 'destroyed' => 'remove', 'imported' => 'import', 'joined' => 'users' }.freeze @@ -167,6 +169,8 @@ module EventsHelper project_issue_url(event.project, id: event.note_target, anchor: dom_id(event.target)) elsif event.merge_request_note? project_merge_request_url(event.project, id: event.note_target, anchor: dom_id(event.target)) + elsif event.design_note? + design_url(event.note_target, anchor: dom_id(event.note)) else polymorphic_url([event.project.namespace.becomes(Namespace), event.project, event.note_target], @@ -237,6 +241,16 @@ module EventsHelper concat content_tag(:span, event.author.to_reference, class: "username") end end + + private + + def design_url(design, opts) + designs_project_issue_url( + design.project, + design.issue, + opts.merge(vueroute: design.filename) + ) + end end EventsHelper.prepend_if_ee('EE::EventsHelper') diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index d03fa6eadb2..483b350b99b 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -9,7 +9,18 @@ module ExportHelper _('Project configuration, including services'), _('Issues with comments, merge requests with diffs and comments, labels, milestones, snippets, and other project entities'), _('LFS objects'), - _('Issue Boards') + _('Issue Boards'), + _('Design Management files and data') + ] + end + + def group_export_descriptions + [ + _('Milestones'), + _('Labels'), + _('Boards and Board Lists'), + _('Badges'), + _('Subgroups') ] end end diff --git a/app/helpers/form_helper.rb b/app/helpers/form_helper.rb index b611f700d21..ecacde65c10 100644 --- a/app/helpers/form_helper.rb +++ b/app/helpers/form_helper.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true module FormHelper - prepend_if_ee('::EE::FormHelper') # rubocop: disable Cop/InjectEnterpriseEditionModule - def form_errors(model, type: 'form', truncate: []) return unless model.errors.any? @@ -79,3 +77,5 @@ module FormHelper new_options end end + +FormHelper.prepend_if_ee('::EE::FormHelper') diff --git a/app/helpers/groups_helper.rb b/app/helpers/groups_helper.rb index 91f8bc33e3e..a6c3c97a873 100644 --- a/app/helpers/groups_helper.rb +++ b/app/helpers/groups_helper.rb @@ -49,6 +49,10 @@ module GroupsHelper can?(current_user, :change_visibility_level, group) end + def can_update_default_branch_protection?(group) + can?(current_user, :update_default_branch_protection, group) + end + def can_change_share_with_group_lock?(group) can?(current_user, :change_share_with_group_lock, group) end diff --git a/app/helpers/icons_helper.rb b/app/helpers/icons_helper.rb index 876789e0d4a..8a32d3c8a3f 100644 --- a/app/helpers/icons_helper.rb +++ b/app/helpers/icons_helper.rb @@ -158,6 +158,6 @@ module IconsHelper def known_sprites return if Rails.env.production? - @known_sprites ||= JSON.parse(File.read(Rails.root.join('node_modules/@gitlab/svgs/dist/icons.json')))['icons'] + @known_sprites ||= Gitlab::Json.parse(File.read(Rails.root.join('node_modules/@gitlab/svgs/dist/icons.json')))['icons'] end end diff --git a/app/helpers/issuables_helper.rb b/app/helpers/issuables_helper.rb index 7e0cc591308..1ce99652463 100644 --- a/app/helpers/issuables_helper.rb +++ b/app/helpers/issuables_helper.rb @@ -196,7 +196,7 @@ module IssuablesHelper author_output = link_to_member(project, issuable.author, size: 24, mobile_classes: "d-none d-sm-inline") author_output << link_to_member(project, issuable.author, size: 24, by_username: true, avatar: false, mobile_classes: "d-inline d-sm-none") - author_output << gitlab_team_member_badge(issuable.author, css_class: 'ml-1') + author_output << issuable_meta_author_slot(issuable.author, css_class: 'ml-1') if status = user_status(issuable.author) author_output << "#{status}".html_safe @@ -213,6 +213,11 @@ module IssuablesHelper output.join.html_safe end + # This is a dummy method, and has an override defined in ee + def issuable_meta_author_slot(author, css_class: nil) + nil + end + def issuable_labels_tooltip(labels, limit: 5) first, last = labels.partition.with_index { |_, i| i < limit } @@ -242,27 +247,6 @@ module IssuablesHelper html.html_safe end - def gitlab_team_member_badge(author, css_class: nil) - return unless author.gitlab_employee? - - default_css_class = 'd-inline-block align-middle' - gitlab_team_member = _('GitLab Team Member') - - content_tag( - :span, - class: css_class ? "#{default_css_class} #{css_class}" : default_css_class, - data: { toggle: 'tooltip', title: gitlab_team_member, container: 'body' }, - role: 'img', - aria: { label: gitlab_team_member } - ) do - sprite_icon( - 'tanuki-verified', - size: 16, - css_class: 'gl-text-purple d-block' - ) - end - end - def issuable_first_contribution_icon content_tag(:span, class: 'fa-stack') do concat(icon('certificate', class: "fa-stack-2x")) diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 34b6ba05a62..39edfeea81e 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -9,13 +9,6 @@ module IssuesHelper classes.join(' ') end - # Returns an OpenStruct object suitable for use by options_from_collection_for_select - # to allow filtering issues by an unassigned User or Milestone - def unassigned_filter - # Milestone uses :title, Issue uses :name - OpenStruct.new(id: 0, title: 'None (backlog)', name: 'Unassigned') - end - def url_for_issue(issue_iid, project = @project, options = {}) return '' if project.nil? @@ -145,17 +138,12 @@ module IssuesHelper can?(current_user, :create_issue, project) end - def create_confidential_merge_request_enabled? - Feature.enabled?(:create_confidential_merge_request, @project, default_enabled: true) - end - def show_new_branch_button? can_create_confidential_merge_request? || !@issue.confidential? end def can_create_confidential_merge_request? @issue.confidential? && !@project.private? && - create_confidential_merge_request_enabled? && can?(current_user, :create_merge_request_in, @project) end @@ -177,6 +165,10 @@ module IssuesHelper end end + def show_moved_service_desk_issue_warning?(issue) + false + end + # Required for Banzai::Filter::IssueReferenceFilter module_function :url_for_issue module_function :url_for_internal_issue diff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rb index 11d5591d509..31995c27fac 100644 --- a/app/helpers/members_helper.rb +++ b/app/helpers/members_helper.rb @@ -15,7 +15,18 @@ module MembersHelper elsif member.invite? "revoke the invitation for #{member.invite_email} to join" else - "remove #{member.user.name} from" + if member.user + "remove #{member.user.name} from" + else + e = RuntimeError.new("Data integrity error: no associated user for member ID #{member.id}") + Gitlab::ErrorTracking.track_exception(e, + member_id: member.id, + invite_email: member.invite_email, + invite_accepted_at: member.invite_accepted_at, + source_id: member.source_id, + source_type: member.source_type) + "remove this orphaned member from" + end end "#{text} #{action} the #{member.source.human_name} #{source_text(member)}?" diff --git a/app/helpers/milestones_helper.rb b/app/helpers/milestones_helper.rb index 2f5aac892ab..df1ee54c5ac 100644 --- a/app/helpers/milestones_helper.rb +++ b/app/helpers/milestones_helper.rb @@ -249,7 +249,7 @@ module MilestonesHelper if milestone.legacy_group_milestone? group_milestone_path(@group, milestone.safe_title, title: milestone.title, milestone: params) else - group_milestone_path(@group, milestone.iid, milestone: params) + group_milestone_path(milestone.group, milestone.iid, milestone: params) end end diff --git a/app/helpers/namespaces_helper.rb b/app/helpers/namespaces_helper.rb index 9de28fb3ed9..228dc2cc27f 100644 --- a/app/helpers/namespaces_helper.rb +++ b/app/helpers/namespaces_helper.rb @@ -80,8 +80,8 @@ module NamespacesHelper visibility_level: n.visibility_level_value, visibility: n.visibility, name: n.name, - show_path: (type == 'group') ? group_path(n) : user_path(n), - edit_path: (type == 'group') ? edit_group_path(n) : nil + show_path: type == 'group' ? group_path(n) : user_path(n), + edit_path: type == 'group' ? edit_group_path(n) : nil }] end diff --git a/app/helpers/nav_helper.rb b/app/helpers/nav_helper.rb index 6013475acb1..9ea0b9cb584 100644 --- a/app/helpers/nav_helper.rb +++ b/app/helpers/nav_helper.rb @@ -54,11 +54,12 @@ module NavHelper current_path?('merge_requests#show') || current_path?('projects/merge_requests/conflicts#show') || current_path?('issues#show') || - current_path?('milestones#show') + current_path?('milestones#show') || + current_path?('issues#designs') end def admin_monitoring_nav_links - %w(system_info background_jobs logs health_check requests_profiles) + %w(system_info background_jobs health_check requests_profiles) end def group_issues_sub_menu_items diff --git a/app/helpers/preferences_helper.rb b/app/helpers/preferences_helper.rb index 070089d6ef8..7a0462e1b2c 100644 --- a/app/helpers/preferences_helper.rb +++ b/app/helpers/preferences_helper.rb @@ -70,7 +70,7 @@ module PreferencesHelper end def language_choices - Gitlab::I18n::AVAILABLE_LANGUAGES.map { |value, label| [label, value] } + Gitlab::I18n::AVAILABLE_LANGUAGES.map(&:reverse).sort end private diff --git a/app/helpers/projects/alert_management_helper.rb b/app/helpers/projects/alert_management_helper.rb new file mode 100644 index 00000000000..af86ef715c2 --- /dev/null +++ b/app/helpers/projects/alert_management_helper.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Projects::AlertManagementHelper + def alert_management_data(current_user, project) + { + 'project-path' => project.full_path, + 'enable-alert-management-path' => edit_project_service_path(project, AlertsService), + 'empty-alert-svg-path' => image_path('illustrations/alert-management-empty-state.svg'), + 'user-can-enable-alert-management' => can?(current_user, :admin_project, project).to_s, + 'alert-management-enabled' => (!!project.alerts_service_activated?).to_s + } + end + + def alert_management_detail_data(project, alert_id) + { + 'alert-id' => alert_id, + 'project-path' => project.full_path, + 'new-issue-path' => new_project_issue_path(project) + } + end +end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 8bec7599158..d743ea6aeea 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true module ProjectsHelper - prepend_if_ee('::EE::ProjectsHelper') # rubocop: disable Cop/InjectEnterpriseEditionModule - def project_incident_management_setting @project_incident_management_setting ||= @project.incident_management_setting || @project.build_incident_management_setting @@ -297,11 +295,11 @@ module ProjectsHelper end def show_merge_request_count?(disabled: false, compact_mode: false) - !disabled && !compact_mode && Feature.enabled?(:project_list_show_mr_count, default_enabled: true) + !disabled && !compact_mode end def show_issue_count?(disabled: false, compact_mode: false) - !disabled && !compact_mode && Feature.enabled?(:project_list_show_issue_count, default_enabled: true) + !disabled && !compact_mode end # overridden in EE @@ -448,6 +446,7 @@ module ProjectsHelper clusters: :read_cluster, serverless: :read_cluster, error_tracking: :read_sentry_issue, + alert_management: :read_alert_management_alert, labels: :read_label, issues: :read_issue, project_members: :read_project_member, @@ -588,7 +587,9 @@ module ProjectsHelper pagesAccessLevel: feature.pages_access_level, containerRegistryEnabled: !!project.container_registry_enabled, lfsEnabled: !!project.lfs_enabled, - emailsDisabled: project.emails_disabled? + emailsDisabled: project.emails_disabled?, + metricsDashboardAccessLevel: feature.metrics_dashboard_access_level, + showDefaultAwardEmojis: project.show_default_award_emojis? } end @@ -674,6 +675,7 @@ module ProjectsHelper services#edit hooks#index hooks#edit + access_tokens#index hook_logs#show repository#show ci_cd#show @@ -708,6 +710,7 @@ module ProjectsHelper clusters functions error_tracking + alert_management user gcp logs @@ -737,6 +740,12 @@ module ProjectsHelper Gitlab.config.registry.enabled && can?(current_user, :destroy_container_image, project) end + + def project_access_token_available?(project) + return false if ::Gitlab.com? + + ::Feature.enabled?(:resource_access_token, project) + end end ProjectsHelper.prepend_if_ee('EE::ProjectsHelper') diff --git a/app/helpers/releases_helper.rb b/app/helpers/releases_helper.rb index af51427dc91..1238567a4ed 100644 --- a/app/helpers/releases_helper.rb +++ b/app/helpers/releases_helper.rb @@ -30,7 +30,9 @@ module ReleasesHelper markdown_docs_path: help_page_path('user/markdown'), releases_page_path: project_releases_path(@project, anchor: @release.tag), update_release_api_docs_path: help_page_path('api/releases/index.md', anchor: 'update-a-release'), - release_assets_docs_path: help_page(anchor: 'release-assets') + release_assets_docs_path: help_page(anchor: 'release-assets'), + manage_milestones_path: project_milestones_path(@project), + new_milestone_path: new_project_milestone_url(@project) } end end diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index e478f76818f..5ad65c59a2e 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -58,8 +58,6 @@ module SearchHelper ns_('SearchResults|comment', 'SearchResults|comments', count) when 'projects' ns_('SearchResults|project', 'SearchResults|projects', count) - when 'snippet_blobs' - ns_('SearchResults|snippet result', 'SearchResults|snippet results', count) when 'snippet_titles' ns_('SearchResults|snippet', 'SearchResults|snippets', count) when 'users' @@ -209,11 +207,11 @@ module SearchHelper end end - def search_filter_input_options(type) + def search_filter_input_options(type, placeholder = _('Search or filter results...')) opts = { id: "filtered-search-#{type}", - placeholder: _('Search or filter results...'), + placeholder: placeholder, data: { 'username-params' => UserSerializer.new.represent(@users) }, diff --git a/app/helpers/services_helper.rb b/app/helpers/services_helper.rb index f3f4cdc857f..b13cc93436f 100644 --- a/app/helpers/services_helper.rb +++ b/app/helpers/services_helper.rb @@ -51,17 +51,13 @@ module ServicesHelper end end - def service_save_button(service) - button_tag(class: 'btn btn-success', type: 'submit', disabled: service.deprecated?, data: { qa_selector: 'save_changes_button' }) do + def service_save_button + button_tag(class: 'btn btn-success', type: 'submit', data: { qa_selector: 'save_changes_button' }) do icon('spinner spin', class: 'hidden js-btn-spinner') + content_tag(:span, 'Save changes', class: 'js-btn-label') end end - def disable_fields_service?(service) - !current_controller?("admin/services") && service.deprecated? - end - def scoped_integrations_path if @project.present? project_settings_integrations_path(@project) @@ -84,7 +80,7 @@ module ServicesHelper def scoped_edit_integration_path(integration) if @project.present? - edit_project_settings_integration_path(@project, integration) + edit_project_service_path(@project, integration) elsif @group.present? edit_group_settings_integration_path(@group, integration) else @@ -105,7 +101,7 @@ module ServicesHelper extend self end -ServicesHelper.prepend_if_ee('EE::ServicesHelper') # rubocop: disable Cop/InjectEnterpriseEditionModule +ServicesHelper.prepend_if_ee('EE::ServicesHelper') # The methods in `EE::ServicesHelper` should be available as both instance and # class methods. diff --git a/app/helpers/snippets_helper.rb b/app/helpers/snippets_helper.rb index a9f90a8f5e4..d6a9e447fbc 100644 --- a/app/helpers/snippets_helper.rb +++ b/app/helpers/snippets_helper.rb @@ -42,72 +42,6 @@ module SnippetsHelper (lower..upper).to_a end - # Returns a sorted set of lines to be included in a snippet preview. - # This ensures matching adjacent lines do not display duplicated - # surrounding code. - # - # @returns Array, unique and sorted. - def matching_lines(lined_content, surrounding_lines, query) - used_lines = [] - lined_content.each_with_index do |line, line_number| - used_lines.concat bounded_line_numbers( - line_number, - 0, - lined_content.size, - surrounding_lines - ) if line.downcase.include?(query.downcase) - end - - used_lines.uniq.sort - end - - # 'Chunkify' entire snippet. Splits the snippet data into matching lines + - # surrounding_lines() worth of unmatching lines. - # - # @returns a hash with {snippet_object, snippet_chunks:{data,start_line}} - def chunk_snippet(snippet, query, surrounding_lines = 3) - lined_content = snippet.content.split("\n") - used_lines = matching_lines(lined_content, surrounding_lines, query) - - snippet_chunk = [] - snippet_chunks = [] - snippet_start_line = 0 - last_line = -1 - - # Go through each used line, and add consecutive lines as a single chunk - # to the snippet chunk array. - used_lines.each do |line_number| - if last_line < 0 - # Start a new chunk. - snippet_start_line = line_number - snippet_chunk << lined_content[line_number] - elsif last_line == line_number - 1 - # Consecutive line, continue chunk. - snippet_chunk << lined_content[line_number] - else - # Non-consecutive line, add chunk to chunk array. - snippet_chunks << { - data: snippet_chunk.join("\n"), - start_line: snippet_start_line + 1 - } - - # Start a new chunk. - snippet_chunk = [lined_content[line_number]] - snippet_start_line = line_number - end - - last_line = line_number - end - # Add final chunk to chunk array - snippet_chunks << { - data: snippet_chunk.join("\n"), - start_line: snippet_start_line + 1 - } - - # Return snippet with chunk array - { snippet_object: snippet, snippet_chunks: snippet_chunks } - end - def snippet_embed_tag(snippet) content_tag(:script, nil, src: gitlab_snippet_url(snippet, format: :js)) end @@ -160,14 +94,4 @@ module SnippetsHelper title: 'Download', rel: 'noopener noreferrer') end - - def snippet_file_name(snippet) - blob = if Feature.enabled?(:version_snippets, current_user) && !snippet.repository.empty? - snippet.blobs.first - else - snippet.blob - end - - blob.name - end end diff --git a/app/helpers/sorting_helper.rb b/app/helpers/sorting_helper.rb index 3e448087db0..ed1b35338ae 100644 --- a/app/helpers/sorting_helper.rb +++ b/app/helpers/sorting_helper.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true module SortingHelper - prepend_if_ee('::EE::SortingHelper') # rubocop: disable Cop/InjectEnterpriseEditionModule - def sort_options_hash { sort_value_created_date => sort_title_created_date, @@ -584,3 +582,5 @@ module SortingHelper 'expired_asc' end end + +SortingHelper.prepend_if_ee('::EE::SortingHelper') diff --git a/app/helpers/system_note_helper.rb b/app/helpers/system_note_helper.rb index d3b6ecf2bd7..7baa615d36f 100644 --- a/app/helpers/system_note_helper.rb +++ b/app/helpers/system_note_helper.rb @@ -27,7 +27,11 @@ module SystemNoteHelper 'locked' => 'lock', 'unlocked' => 'lock-open', 'due_date' => 'calendar', - 'health_status' => 'status-health' + 'health_status' => 'status-health', + 'designs_added' => 'doc-image', + 'designs_modified' => 'doc-image', + 'designs_removed' => 'doc-image', + 'designs_discussion_added' => 'doc-image' }.freeze def system_note_icon_name(note) @@ -42,7 +46,7 @@ module SystemNoteHelper extend self end -SystemNoteHelper.prepend_if_ee('EE::SystemNoteHelper') # rubocop: disable Cop/InjectEnterpriseEditionModule +SystemNoteHelper.prepend_if_ee('EE::SystemNoteHelper') # The methods in `EE::SystemNoteHelper` should be available as both instance and # class methods. diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index 0211a22a8c4..41f39c7e798 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -53,6 +53,8 @@ module TodosHelper end def todo_target_type_name(todo) + return _('design') if todo.for_design? + todo.target_type.titleize.downcase end @@ -63,6 +65,8 @@ module TodosHelper if todo.for_commit? project_commit_path(todo.project, todo.target, path_options) + elsif todo.for_design? + todos_design_path(todo, path_options) else path = [todo.resource_parent, todo.target] @@ -151,7 +155,8 @@ module TodosHelper [ { id: '', text: 'Any Type' }, { id: 'Issue', text: 'Issue' }, - { id: 'MergeRequest', text: 'Merge Request' } + { id: 'MergeRequest', text: 'Merge Request' }, + { id: 'DesignManagement::Design', text: 'Design' } ] end @@ -188,6 +193,18 @@ module TodosHelper private + def todos_design_path(todo, path_options) + design = todo.target + + designs_project_issue_path( + todo.resource_parent, + design.issue, + path_options.merge( + vueroute: design.filename + ) + ) + end + def todo_action_subject(todo) todo.self_added? ? 'yourself' : 'you' end diff --git a/app/helpers/workhorse_helper.rb b/app/helpers/workhorse_helper.rb index bb5b1555dc4..f74b53d68a1 100644 --- a/app/helpers/workhorse_helper.rb +++ b/app/helpers/workhorse_helper.rb @@ -36,8 +36,8 @@ module WorkhorseHelper end # Send an entry from artifacts through Workhorse - def send_artifacts_entry(build, entry) - headers.store(*Gitlab::Workhorse.send_artifacts_entry(build, entry)) + def send_artifacts_entry(file, entry) + headers.store(*Gitlab::Workhorse.send_artifacts_entry(file, entry)) head :ok end diff --git a/app/helpers/x509_helper.rb b/app/helpers/x509_helper.rb index c330b599d74..009635fb629 100644 --- a/app/helpers/x509_helper.rb +++ b/app/helpers/x509_helper.rb @@ -16,4 +16,8 @@ module X509Helper rescue {} end + + def x509_signature?(sig) + sig.is_a?(X509CommitSignature) || sig.is_a?(Gitlab::X509::Signature) + end end -- cgit v1.2.3