diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
commit | d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch) | |
tree | 2341ef426af70ad1e289c38036737e04b0aa5007 /app/helpers | |
parent | d6e514dd13db8947884cd58fe2a9c2a063400a9b (diff) |
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'app/helpers')
23 files changed, 171 insertions, 55 deletions
diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb index cf15433f2e5..2103a37180f 100644 --- a/app/helpers/application_settings_helper.rb +++ b/app/helpers/application_settings_helper.rb @@ -333,6 +333,9 @@ module ApplicationSettingsHelper :throttle_authenticated_files_api_enabled, :throttle_authenticated_files_api_period_in_seconds, :throttle_authenticated_files_api_requests_per_period, + :throttle_authenticated_deprecated_api_enabled, + :throttle_authenticated_deprecated_api_period_in_seconds, + :throttle_authenticated_deprecated_api_requests_per_period, :throttle_unauthenticated_api_enabled, :throttle_unauthenticated_api_period_in_seconds, :throttle_unauthenticated_api_requests_per_period, @@ -345,6 +348,9 @@ module ApplicationSettingsHelper :throttle_unauthenticated_files_api_enabled, :throttle_unauthenticated_files_api_period_in_seconds, :throttle_unauthenticated_files_api_requests_per_period, + :throttle_unauthenticated_deprecated_api_enabled, + :throttle_unauthenticated_deprecated_api_period_in_seconds, + :throttle_unauthenticated_deprecated_api_requests_per_period, :throttle_protected_paths_enabled, :throttle_protected_paths_period_in_seconds, :throttle_protected_paths_requests_per_period, @@ -400,7 +406,8 @@ module ApplicationSettingsHelper :user_deactivation_emails_enabled, :sidekiq_job_limiter_mode, :sidekiq_job_limiter_compression_threshold_bytes, - :sidekiq_job_limiter_limit_bytes + :sidekiq_job_limiter_limit_bytes, + :suggest_pipeline_enabled ].tap do |settings| settings << :deactivate_dormant_users unless Gitlab.com? end @@ -464,10 +471,6 @@ module ApplicationSettingsHelper } end - def show_documentation_base_url_field? - Feature.enabled?(:help_page_documentation_redirect) - end - def valid_runner_registrars Gitlab::CurrentSettings.valid_runner_registrars end @@ -477,8 +480,6 @@ module ApplicationSettingsHelper end def pending_user_count - return 0 if Gitlab::CurrentSettings.new_user_signups_cap.blank? - User.blocked_pending_approval.count end end diff --git a/app/helpers/avatars_helper.rb b/app/helpers/avatars_helper.rb index 4cfa1528d9b..dd852a68682 100644 --- a/app/helpers/avatars_helper.rb +++ b/app/helpers/avatars_helper.rb @@ -9,6 +9,10 @@ module AvatarsHelper source_icon(group, options) end + def topic_icon(topic, options = {}) + source_icon(topic, options) + end + # Takes both user and email and returns the avatar_icon by # user (preferred) or email. def avatar_icon_for(user = nil, email = nil, size = nil, scale = 2, only_path: true) diff --git a/app/helpers/ci/jobs_helper.rb b/app/helpers/ci/jobs_helper.rb index 882302f05ad..d02fe3f20b0 100644 --- a/app/helpers/ci/jobs_helper.rb +++ b/app/helpers/ci/jobs_helper.rb @@ -7,7 +7,7 @@ module Ci "endpoint" => project_job_path(@project, @build, format: :json), "project_path" => @project.full_path, "artifact_help_url" => help_page_path('user/gitlab_com/index.html', anchor: 'gitlab-cicd'), - "deployment_help_url" => help_page_path('user/project/clusters/index.html', anchor: 'troubleshooting'), + "deployment_help_url" => help_page_path('user/project/clusters/deploy_to_cluster.html', anchor: 'troubleshooting'), "runner_settings_url" => project_runners_path(@build.project, anchor: 'js-runners-settings'), "page_path" => project_job_path(@project, @build), "build_status" => @build.status, diff --git a/app/helpers/ci/runners_helper.rb b/app/helpers/ci/runners_helper.rb index c9231a4eff3..ec10610714b 100644 --- a/app/helpers/ci/runners_helper.rb +++ b/app/helpers/ci/runners_helper.rb @@ -77,7 +77,7 @@ module Ci def toggle_shared_runners_settings_data(project) { is_enabled: "#{project.shared_runners_enabled?}", - is_disabled_and_unoverridable: "#{project.group&.shared_runners_setting == 'disabled_and_unoverridable'}", + is_disabled_and_unoverridable: "#{project.group&.shared_runners_setting == Namespace::SR_DISABLED_AND_UNOVERRIDABLE}", update_path: toggle_shared_runners_project_runners_path(project) } end diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb index 53017beee85..ee5f4bb364a 100644 --- a/app/helpers/commits_helper.rb +++ b/app/helpers/commits_helper.rb @@ -17,6 +17,15 @@ module CommitsHelper commit_person_link(commit, options.merge(source: :committer)) end + def commit_committer_avatar(committer, options = {}) + user_avatar(options.merge({ + user: committer, + user_name: committer.name, + user_email: committer.email, + css_class: 'd-none d-sm-inline-block float-none gl-mr-0! gl-vertical-align-text-bottom' + })) + end + def commit_to_html(commit, ref, project) render 'projects/commits/commit.html', commit: commit, diff --git a/app/helpers/feature_flags_helper.rb b/app/helpers/feature_flags_helper.rb index 2b8804bc07e..e12c6c605d2 100644 --- a/app/helpers/feature_flags_helper.rb +++ b/app/helpers/feature_flags_helper.rb @@ -11,8 +11,15 @@ module FeatureFlagsHelper project.feature_flags_client_token end - def feature_flag_issues_links_endpoint(_project, _feature_flag, _user) - '' + def edit_feature_flag_data + { + endpoint: project_feature_flag_path(@project, @feature_flag), + project_id: @project.id, + feature_flags_path: project_feature_flags_path(@project), + environments_endpoint: search_project_environments_path(@project, format: :json), + strategy_type_docs_page_path: help_page_path('operations/feature_flags', anchor: 'feature-flag-strategies'), + environments_scope_docs_path: help_page_path('ci/environments/index.md', anchor: 'scope-environments-with-specs') + } end end diff --git a/app/helpers/groups_helper.rb b/app/helpers/groups_helper.rb index a24776eb2e4..30aaa0a5acc 100644 --- a/app/helpers/groups_helper.rb +++ b/app/helpers/groups_helper.rb @@ -109,7 +109,7 @@ module GroupsHelper end def prevent_sharing_groups_outside_hierarchy_help_text(group) - s_("GroupSettings|This setting is only available on the top-level group and it applies to all subgroups. Groups that have already been shared with a group outside %{group} will still be shared, and this access will have to be revoked manually.").html_safe % { group: link_to_group(group) } + s_("GroupSettings|Available only on the top-level group. Applies to all subgroups. Groups already shared with a group outside %{group} are still shared unless removed manually.").html_safe % { group: link_to_group(group) } end def parent_group_options(current_group) @@ -178,7 +178,7 @@ module GroupsHelper end def default_help - s_("GroupSettings|This setting will be applied to all subgroups unless overridden by a group owner. Groups that already have access to the project will continue to have access unless removed manually.") + s_("GroupSettings|Applied to all subgroups unless overridden by a group owner. Groups already added to the project lose access.") end def ancestor_locked_but_you_can_override(group) diff --git a/app/helpers/hooks_helper.rb b/app/helpers/hooks_helper.rb index 2725d28c47c..c1dfd2b2cda 100644 --- a/app/helpers/hooks_helper.rb +++ b/app/helpers/hooks_helper.rb @@ -36,6 +36,15 @@ module HooksHelper admin_hook_path(hook) end end + + def hook_log_path(hook, hook_log) + case hook + when ProjectHook + hook_log.present.details_path + when SystemHook + admin_hook_hook_log_path(hook, hook_log) + end + end end HooksHelper.prepend_mod_with('HooksHelper') diff --git a/app/helpers/integrations_helper.rb b/app/helpers/integrations_helper.rb index 904508867d3..8819aa9e9cc 100644 --- a/app/helpers/integrations_helper.rb +++ b/app/helpers/integrations_helper.rb @@ -125,15 +125,6 @@ module IntegrationsHelper !Gitlab.com? end - def integration_tabs(integration:) - [ - { key: 'edit', text: _('Settings'), href: scoped_edit_integration_path(integration) }, - ( - { key: 'overrides', text: s_('Integrations|Projects using custom settings'), href: scoped_overrides_integration_path(integration) } if integration.instance_level? - ) - ].compact - end - def jira_issue_breadcrumb_link(issue_reference) link_to '', { class: 'gl-display-flex gl-align-items-center gl-white-space-nowrap' } do icon = image_tag image_path('illustrations/logos/jira.svg'), width: 15, height: 15, class: 'gl-mr-2' diff --git a/app/helpers/issuables_helper.rb b/app/helpers/issuables_helper.rb index f3cc46216e5..24c6ef8cd68 100644 --- a/app/helpers/issuables_helper.rb +++ b/app/helpers/issuables_helper.rb @@ -198,7 +198,7 @@ module IssuablesHelper if count != -1 html << " " << content_tag(:span, format_count(issuable_type, count, Gitlab::IssuablesCountForState::THRESHOLD), - class: 'badge badge-muted badge-pill gl-badge gl-tab-counter-badge sm' + class: 'badge badge-muted badge-pill gl-badge gl-tab-counter-badge sm gl-display-none gl-sm-display-inline-flex' ) end diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 40e86b4623c..49f7d9aeef1 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -238,9 +238,10 @@ module IssuesHelper ) end - def group_issues_list_data(group, current_user, issues) + def group_issues_list_data(group, current_user, issues, projects) common_issues_list_data(group, current_user).merge( - has_any_issues: issues.to_a.any?.to_s + has_any_issues: issues.to_a.any?.to_s, + has_any_projects: any_projects?(projects).to_s ) end diff --git a/app/helpers/one_trust_helper.rb b/app/helpers/one_trust_helper.rb new file mode 100644 index 00000000000..9f92a73a4d4 --- /dev/null +++ b/app/helpers/one_trust_helper.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module OneTrustHelper + def one_trust_enabled? + Feature.enabled?(:ecomm_instrumentation, type: :ops) && + Gitlab.config.extra.has_key?('one_trust_id') && + Gitlab.config.extra.one_trust_id.present? && + !current_user + end +end diff --git a/app/helpers/packages_helper.rb b/app/helpers/packages_helper.rb index ebf30fb3538..c69d9eb1326 100644 --- a/app/helpers/packages_helper.rb +++ b/app/helpers/packages_helper.rb @@ -41,6 +41,7 @@ module PackagesHelper def packages_list_data(type, resource) { resource_id: resource.id, + full_path: resource.full_path, page_type: type, empty_list_help_url: help_page_path('user/packages/package_registry/index'), empty_list_illustration: image_path('illustrations/no-packages.svg'), @@ -70,6 +71,7 @@ module PackagesHelper can_delete: can?(current_user, :destroy_package, project).to_s, svg_path: image_path('illustrations/no-packages.svg'), npm_path: package_registry_instance_url(:npm), + npm_project_path: package_registry_project_url(project.id, :npm), npm_help_path: help_page_path('user/packages/npm_registry/index'), maven_path: package_registry_project_url(project.id, :maven), maven_help_path: help_page_path('user/packages/maven_repository/index'), diff --git a/app/helpers/projects/cluster_agents_helper.rb b/app/helpers/projects/cluster_agents_helper.rb new file mode 100644 index 00000000000..20fa721cc3b --- /dev/null +++ b/app/helpers/projects/cluster_agents_helper.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Projects::ClusterAgentsHelper + def js_cluster_agent_details_data(agent_name, project) + { + agent_name: agent_name, + project_path: project.full_path + } + end +end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index d7f1cd505e9..03e7fb5ffc4 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -20,16 +20,15 @@ module ProjectsHelper end def link_to_member_avatar(author, opts = {}) - default_opts = { size: 16, lazy_load: false } + default_opts = { size: 16 } opts = default_opts.merge(opts) classes = %W[avatar avatar-inline s#{opts[:size]}] classes << opts[:avatar_class] if opts[:avatar_class] avatar = avatar_icon_for_user(author, opts[:size]) - src = opts[:lazy_load] ? nil : avatar - image_tag(src, width: opts[:size], class: classes, alt: '', "data-src" => avatar) + image_tag(avatar, width: opts[:size], class: classes, alt: '') end def author_content_tag(author, opts = {}) @@ -351,7 +350,7 @@ module ProjectsHelper end def show_terraform_banner?(project) - project.repository_languages.with_programming_language('HCL').exists? && project.terraform_states.empty? + Feature.enabled?(:show_terraform_banner, type: :ops, default_enabled: true) && project.repository_languages.with_programming_language('HCL').exists? && project.terraform_states.empty? end def project_permissions_panel_data(project) diff --git a/app/helpers/routing/pseudonymization_helper.rb b/app/helpers/routing/pseudonymization_helper.rb index 1d9320f0106..b73e49803ae 100644 --- a/app/helpers/routing/pseudonymization_helper.rb +++ b/app/helpers/routing/pseudonymization_helper.rb @@ -6,7 +6,8 @@ module Routing return unless Feature.enabled?(:mask_page_urls, type: :ops) mask_params(Rails.application.routes.recognize_path(request.original_fullpath)) - rescue ActionController::RoutingError, URI::InvalidURIError + rescue ActionController::RoutingError, URI::InvalidURIError => e + Gitlab::ErrorTracking.track_exception(e, url: request.original_fullpath) nil end @@ -27,7 +28,7 @@ module Routing when 'groups' "/namespace:#{group.id}" when 'projects' - "/namespace:#{project.namespace.id}/project:#{project.id}" + "/namespace:#{project.namespace_id}/project:#{project.id}" when 'root' '' else @@ -43,7 +44,7 @@ module Routing masked_url = "#{request.protocol}#{request.host_with_port}" if request_params.has_key?(:project_id) - masked_url += "/namespace:#{project.namespace.id}/project:#{project.id}/-/#{namespace_type}" + masked_url += "/namespace:#{project.namespace_id}/project:#{project.id}/-/#{namespace_type}" end if request_params.has_key?(:id) diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index b8e58e3afb1..cb28025c900 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -87,9 +87,9 @@ module SearchHelper def search_entries_info_template(collection) if collection.total_pages > 1 - s_("SearchResults|Showing %{from} - %{to} of %{count} %{scope} for%{term_element}").html_safe + s_("SearchResults|Showing %{from} - %{to} of %{count} %{scope} for %{term_element}").html_safe else - s_("SearchResults|Showing %{count} %{scope} for%{term_element}").html_safe + s_("SearchResults|Showing %{count} %{scope} for %{term_element}").html_safe end end diff --git a/app/helpers/startupjs_helper.rb b/app/helpers/startupjs_helper.rb index b595590c7c9..2e8f0cb7dbe 100644 --- a/app/helpers/startupjs_helper.rb +++ b/app/helpers/startupjs_helper.rb @@ -5,6 +5,13 @@ module StartupjsHelper @graphql_startup_calls end + def page_startup_graphql_headers + { + 'X-CSRF-Token' => form_authenticity_token, + 'x-gitlab-feature-category' => ::Gitlab::ApplicationContext.current_context_attribute(:feature_category).presence || '' + } + end + def add_page_startup_graphql_call(query, variables = {}) @graphql_startup_calls ||= [] file_location = File.join(Rails.root, "app/graphql/queries/#{query}.query.graphql") diff --git a/app/helpers/tab_helper.rb b/app/helpers/tab_helper.rb index e64e1c935dd..a6bb2f3b246 100644 --- a/app/helpers/tab_helper.rb +++ b/app/helpers/tab_helper.rb @@ -1,6 +1,67 @@ # frozen_string_literal: true module TabHelper + # Navigation tabs helper + + # Create a <gl-tabs> container + # + # Returns a `ul` element with classes that correspond to + # the <gl-tabs/> component. Can be populated by + # gl_tab_link_to elements. + # + # See more at: https://gitlab-org.gitlab.io/gitlab-ui/?path=/story/base-tabs-tab--default + def gl_tabs_nav(html_options = {}, &block) + gl_tabs_classes = %w[nav gl-tabs-nav] + + html_options = html_options.merge( + class: [*html_options[:class], gl_tabs_classes].join(' '), + role: 'tablist' + ) + + content = capture(&block) if block_given? + content_tag(:ul, content, html_options) + end + + # Create a <gl-tab> link + # + # When a tab is active it gets highlighted to indicate this is currently viewed tab. + # Internally `current_page?` is called to determine if this is the current tab. + # + # Usage is the same as "link_to", with the following additional options: + # + # html_options - The html_options hash (default: {}) + # :item_active - Overrides the default state focing the "active" css classes (optional). + # + def gl_tab_link_to(name = nil, options = {}, html_options = {}, &block) + tab_class = 'nav-item' + link_classes = %w[nav-link gl-tab-nav-item] + active_link_classes = %w[active gl-tab-nav-item-active gl-tab-nav-item-active-indigo] + + if block_given? + # Shift params to skip the omitted "name" param + html_options = options + options = name + end + + html_options = html_options.merge( + class: [*html_options[:class], link_classes].join(' ') + ) + + if gl_tab_link_to_active?(options, html_options) + html_options[:class] = [*html_options[:class], active_link_classes].join(' ') + end + + html_options = html_options.except(:item_active) + + content_tag(:li, class: tab_class, role: 'presentation') do + if block_given? + link_to(options, html_options, &block) + else + link_to(name, options, html_options) + end + end + end + # Navigation link helper # # Returns an `li` element with an 'active' class if the supplied @@ -12,7 +73,6 @@ module TabHelper # :action - One or more action names to check (optional). # :path - A shorthand path, such as 'dashboard#index', to check (optional). # :html_options - Extra options to be passed to the list element (optional). - # :unless - Callable object to skip rendering the 'active' class on `li` element (optional). # block - An optional block that will become the contents of the returned # `li` element. # @@ -57,11 +117,6 @@ module TabHelper # nav_link(path: 'admin/appearances#show') { "Hello"} # # => '<li class="active">Hello</li>' # - # # Shorthand path + unless - # # Add `active` class when TreeController is requested, except the `index` action. - # nav_link(controller: 'tree', unless: -> { action_name?('index') }) { "Hello" } - # # => '<li class="active">Hello</li>' - # # # When `TreeController#index` is requested # # => '<li>Hello</li>' # @@ -90,8 +145,6 @@ module TabHelper end def active_nav_link?(options) - return false if options[:unless]&.call - controller = options.delete(:controller) action = options.delete(:action) @@ -148,4 +201,12 @@ module TabHelper current_controller?(*controller) || current_action?(*action) end end + + def gl_tab_link_to_active?(options, html_options) + if html_options.has_key?(:item_active) + return html_options[:item_active] + end + + current_page?(options) + end end diff --git a/app/helpers/time_zone_helper.rb b/app/helpers/time_zone_helper.rb index f92e32ff9b6..a0d9c8403e8 100644 --- a/app/helpers/time_zone_helper.rb +++ b/app/helpers/time_zone_helper.rb @@ -33,6 +33,8 @@ module TimeZoneHelper end def local_time(timezone) + return if timezone.blank? + time_zone_instance = ActiveSupport::TimeZone.new(timezone) || Time.zone time_zone_instance.now.strftime("%-l:%M %p") end diff --git a/app/helpers/timeboxes_helper.rb b/app/helpers/timeboxes_helper.rb index 0993e210f42..eca40572735 100644 --- a/app/helpers/timeboxes_helper.rb +++ b/app/helpers/timeboxes_helper.rb @@ -78,19 +78,6 @@ module TimeboxesHelper end # rubocop: enable CodeReuse/ActiveRecord - # Show 'active' class if provided GET param matches check - # `or_blank` allows the function to return 'active' when given an empty param - # Could be refactored to be simpler but that may make it harder to read - def milestone_class_for_state(param, check, match_blank_param = false) - if match_blank_param - 'active' if param.blank? || param == check - elsif param == check - 'active' - else - check - end - end - def milestone_progress_tooltip_text(milestone) has_issues = milestone.total_issues_count > 0 diff --git a/app/helpers/user_callouts_helper.rb b/app/helpers/user_callouts_helper.rb index 2c3dc243d85..1c67ca983fa 100644 --- a/app/helpers/user_callouts_helper.rb +++ b/app/helpers/user_callouts_helper.rb @@ -10,6 +10,7 @@ module UserCalloutsHelper REGISTRATION_ENABLED_CALLOUT = 'registration_enabled_callout' UNFINISHED_TAG_CLEANUP_CALLOUT = 'unfinished_tag_cleanup_callout' INVITE_MEMBERS_BANNER = 'invite_members_banner' + SECURITY_NEWSLETTER_CALLOUT = 'security_newsletter_callout' def show_gke_cluster_integration_callout?(project) active_nav_link?(controller: sidebar_operations_paths) && @@ -64,6 +65,11 @@ module UserCalloutsHelper !multiple_members?(group) end + def show_security_newsletter_user_callout? + current_user&.admin? && + !user_dismissed?(SECURITY_NEWSLETTER_CALLOUT) + end + private def user_dismissed?(feature_name, ignore_dismissal_earlier_than = nil) diff --git a/app/helpers/workhorse_helper.rb b/app/helpers/workhorse_helper.rb index 8785c4cdcbb..4862282bc73 100644 --- a/app/helpers/workhorse_helper.rb +++ b/app/helpers/workhorse_helper.rb @@ -41,6 +41,15 @@ module WorkhorseHelper head :ok end + def send_dependency(token, url, filename) + headers.store(*Gitlab::Workhorse.send_dependency(token, url)) + headers['Content-Disposition'] = + ActionDispatch::Http::ContentDisposition.format(disposition: 'attachment', filename: filename) + headers['Content-Type'] = 'application/gzip' + + head :ok + end + def set_workhorse_internal_api_content_type headers['Content-Type'] = Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE end |