diff options
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/application_helper.rb | 5 | ||||
-rw-r--r-- | app/helpers/application_settings_helper.rb | 13 | ||||
-rw-r--r-- | app/helpers/avatars_helper.rb | 23 | ||||
-rw-r--r-- | app/helpers/blob_helper.rb | 12 | ||||
-rw-r--r-- | app/helpers/button_helper.rb | 2 | ||||
-rw-r--r-- | app/helpers/ci_status_helper.rb | 17 | ||||
-rw-r--r-- | app/helpers/diff_helper.rb | 15 | ||||
-rw-r--r-- | app/helpers/environment_helper.rb | 33 | ||||
-rw-r--r-- | app/helpers/export_helper.rb | 17 | ||||
-rw-r--r-- | app/helpers/gitlab_routing_helper.rb | 8 | ||||
-rw-r--r-- | app/helpers/groups_helper.rb | 15 | ||||
-rw-r--r-- | app/helpers/issuables_helper.rb | 14 | ||||
-rw-r--r-- | app/helpers/nav_helper.rb | 7 | ||||
-rw-r--r-- | app/helpers/projects_helper.rb | 16 | ||||
-rw-r--r-- | app/helpers/releases_helper.rb | 24 | ||||
-rw-r--r-- | app/helpers/search_helper.rb | 19 | ||||
-rw-r--r-- | app/helpers/sorting_helper.rb | 20 | ||||
-rw-r--r-- | app/helpers/submodule_helper.rb | 2 | ||||
-rw-r--r-- | app/helpers/tags_helper.rb | 10 | ||||
-rw-r--r-- | app/helpers/todos_helper.rb | 6 |
20 files changed, 218 insertions, 60 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5c2420e80f2..ecaeb7060c8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -108,6 +108,11 @@ module ApplicationHelper Gitlab.config.extra end + # shortcut for gitlab registry config + def registry_config + Gitlab.config.registry + end + # Render a `time` element with Javascript-based relative date and tooltip # # time - Time object diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb index 8c5be1c315d..df17b82412f 100644 --- a/app/helpers/application_settings_helper.rb +++ b/app/helpers/application_settings_helper.rb @@ -265,6 +265,10 @@ module ApplicationSettingsHelper :throttle_unauthenticated_enabled, :throttle_unauthenticated_period_in_seconds, :throttle_unauthenticated_requests_per_period, + :throttle_protected_paths_enabled, + :throttle_protected_paths_period_in_seconds, + :throttle_protected_paths_requests_per_period, + :protected_paths_raw, :time_tracking_limit_to_hours, :two_factor_grace_period, :unique_ips_limit_enabled, @@ -285,7 +289,10 @@ module ApplicationSettingsHelper :snowplow_collector_hostname, :snowplow_cookie_domain, :snowplow_enabled, - :snowplow_site_id + :snowplow_site_id, + :push_event_hooks_limit, + :push_event_activities_limit, + :custom_http_clone_url_root ] end @@ -308,6 +315,10 @@ module ApplicationSettingsHelper def instance_clusters_enabled? can?(current_user, :read_cluster, Clusters::Instance.new) end + + def omnibus_protected_paths_throttle? + Rack::Attack.throttles.key?('protected paths') + end end ApplicationSettingsHelper.prepend_if_ee('EE::ApplicationSettingsHelper') # rubocop: disable Cop/InjectEnterpriseEditionModule diff --git a/app/helpers/avatars_helper.rb b/app/helpers/avatars_helper.rb index b7f7e617825..733d21daec1 100644 --- a/app/helpers/avatars_helper.rb +++ b/app/helpers/avatars_helper.rb @@ -56,16 +56,6 @@ module AvatarsHelper })) end - def user_avatar_url_for(only_path: true, **options) - if options[:url] - options[:url] - elsif options[:user] - avatar_icon_for_user(options[:user], options[:size], only_path: only_path) - else - avatar_icon_for_email(options[:user_email], options[:size], only_path: only_path) - end - end - def user_avatar_without_link(options = {}) avatar_size = options[:size] || 16 user_name = options[:user].try(:name) || options[:user_name] @@ -111,6 +101,19 @@ module AvatarsHelper private + def user_avatar_url_for(only_path: true, **options) + return options[:url] if options[:url] + + email = options[:user_email] + user = options.key?(:user) ? options[:user] : User.find_by_any_email(email) + + if user + avatar_icon_for_user(user, options[:size], only_path: only_path) + else + gravatar_icon(email, options[:size]) + end + end + def source_icon(source, options = {}) avatar_url = source.try(:avatar_url) diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 4b0713001a1..5c24b0e1704 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -32,6 +32,14 @@ module BlobHelper File.join(segments) end + def ide_fork_and_edit_path(project = @project, ref = @ref, path = @path, options = {}) + if current_user + project_forks_path(project, + namespace_key: current_user&.namespace&.id, + continue: edit_blob_fork_params(ide_edit_path(project, ref, path))) + end + end + def encode_ide_path(path) url_encode(path).gsub('%2F', '/') end @@ -197,13 +205,13 @@ module BlobHelper end def copy_file_path_button(file_path) - clipboard_button(text: file_path, gfm: "`#{file_path}`", class: 'btn-clipboard btn-transparent', title: 'Copy file path to clipboard') + clipboard_button(text: file_path, gfm: "`#{file_path}`", class: 'btn-clipboard btn-transparent', title: _('Copy file path')) end def copy_blob_source_button(blob) return unless blob.rendered_as_text?(ignore_errors: false) - clipboard_button(target: ".blob-content[data-blob-id='#{blob.id}']", class: "btn btn-sm js-copy-blob-source-btn", title: "Copy source to clipboard") + clipboard_button(target: ".blob-content[data-blob-id='#{blob.id}']", class: "btn btn-sm js-copy-blob-source-btn", title: _("Copy file contents")) end def open_raw_blob_button(blob) diff --git a/app/helpers/button_helper.rb b/app/helpers/button_helper.rb index 12cd5403f71..610d823dd3c 100644 --- a/app/helpers/button_helper.rb +++ b/app/helpers/button_helper.rb @@ -21,7 +21,7 @@ module ButtonHelper # See http://clipboardjs.com/#usage def clipboard_button(data = {}) css_class = data[:class] || 'btn-clipboard btn-transparent' - title = data[:title] || _('Copy to clipboard') + title = data[:title] || _('Copy') button_text = data[:button_text] || '' hide_tooltip = data[:hide_tooltip] || false hide_button_icon = data[:hide_button_icon] || false diff --git a/app/helpers/ci_status_helper.rb b/app/helpers/ci_status_helper.rb index 144df676304..4471d5b64b2 100644 --- a/app/helpers/ci_status_helper.rb +++ b/app/helpers/ci_status_helper.rb @@ -64,7 +64,7 @@ module CiStatusHelper def ci_icon_for_status(status, size: 16) if detailed_status?(status) - return sprite_icon(status.icon) + return sprite_icon(status.icon, size: size) end icon_name = @@ -77,6 +77,8 @@ module CiStatusHelper 'status_failed' when 'pending' 'status_pending' + when 'preparing' + 'status_preparing' when 'running' 'status_running' when 'play' @@ -96,23 +98,29 @@ module CiStatusHelper sprite_icon(icon_name, size: size) end + def ci_icon_class_for_status(status) + group = detailed_status?(status) ? status.group : status.dasherize + + "ci-status-icon-#{group}" + end + def pipeline_status_cache_key(pipeline_status) "pipeline-status/#{pipeline_status.sha}-#{pipeline_status.status}" end - def render_commit_status(commit, ref: nil, tooltip_placement: 'left') + def render_commit_status(commit, status, ref: nil, tooltip_placement: 'left') project = commit.project path = pipelines_project_commit_path(project, commit, ref: ref) render_status_with_link( - commit.status(ref), + status, path, tooltip_placement: tooltip_placement, icon_size: 24) end def render_status_with_link(status, path = nil, type: _('pipeline'), tooltip_placement: 'left', cssclass: '', container: 'body', icon_size: 16) - klass = "ci-status-link ci-status-icon-#{status.dasherize} d-inline-flex #{cssclass}" + klass = "ci-status-link #{ci_icon_class_for_status(status)} d-inline-flex #{cssclass}" title = "#{type.titleize}: #{ci_label_for_status(status)}" data = { toggle: 'tooltip', placement: tooltip_placement, container: container } @@ -127,6 +135,7 @@ module CiStatusHelper def detailed_status?(status) status.respond_to?(:text) && + status.respond_to?(:group) && status.respond_to?(:label) && status.respond_to?(:icon) end diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb index 7f3e78f3a81..52ec2eadf5e 100644 --- a/app/helpers/diff_helper.rb +++ b/app/helpers/diff_helper.rb @@ -60,9 +60,14 @@ module DiffHelper if line.blank? " ".html_safe else - # We can't use `sub` because the HTML-safeness of `line` will not survive. - line[0] = '' if line.start_with?('+', '-', ' ') - line + # `sub` and substring-ing would destroy HTML-safeness of `line` + if line.start_with?('+', '-', ' ') + line.dup.tap do |line| + line[0] = '' + end + else + line + end end end @@ -198,8 +203,8 @@ module DiffHelper link_to "#{hide_whitespace? ? 'Show' : 'Hide'} whitespace changes", url, class: options[:class] end - def render_overflow_warning?(diff_files) - diffs = @merge_request_diff.presence || diff_files + def render_overflow_warning?(diffs_collection) + diffs = @merge_request_diff.presence || diffs_collection.diff_files diffs.overflow? end diff --git a/app/helpers/environment_helper.rb b/app/helpers/environment_helper.rb index 2b7320817ed..52f189b122f 100644 --- a/app/helpers/environment_helper.rb +++ b/app/helpers/environment_helper.rb @@ -18,12 +18,16 @@ module EnvironmentHelper end end + def deployment_path(deployment) + [deployment.project.namespace.becomes(Namespace), deployment.project, deployment.deployable] + end + def deployment_link(deployment, text: nil) return unless deployment link_label = text ? text : "##{deployment.iid}" - link_to link_label, [deployment.project.namespace.becomes(Namespace), deployment.project, deployment.deployable] + link_to link_label, deployment_path(deployment) end def last_deployment_link_for_environment_build(project, build) @@ -32,4 +36,31 @@ module EnvironmentHelper deployment_link(environment.last_deployment) end + + def render_deployment_status(deployment) + status = deployment.status + + status_text = + case status + when 'created' + s_('Deployment|created') + when 'running' + s_('Deployment|running') + when 'success' + s_('Deployment|success') + when 'failed' + s_('Deployment|failed') + when 'canceled' + s_('Deployment|canceled') + end + + klass = "ci-status ci-#{status.dasherize}" + text = "#{ci_icon_for_status(status)} #{status_text}".html_safe + + if deployment.deployable + link_to(text, deployment_path(deployment), class: klass) + else + content_tag(:span, text, class: klass) + end + end end diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb new file mode 100644 index 00000000000..d03fa6eadb2 --- /dev/null +++ b/app/helpers/export_helper.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module ExportHelper + # An EE-overwriteable list of descriptions + def project_export_descriptions + [ + _('Project and wiki repositories'), + _('Project uploads'), + _('Project configuration, including services'), + _('Issues with comments, merge requests with diffs and comments, labels, milestones, snippets, and other project entities'), + _('LFS objects'), + _('Issue Boards') + ] + end +end + +ExportHelper.prepend_if_ee('EE::ExportHelper') diff --git a/app/helpers/gitlab_routing_helper.rb b/app/helpers/gitlab_routing_helper.rb index f524696cc2f..4f31cc67ccc 100644 --- a/app/helpers/gitlab_routing_helper.rb +++ b/app/helpers/gitlab_routing_helper.rb @@ -58,7 +58,7 @@ module GitlabRoutingHelper end def commits_url(entity, *args) - project_commits_url(entity.project, entity.ref, *args) + project_commits_url(entity.project, entity.source_ref, *args) end def commit_url(entity, *args) @@ -76,10 +76,10 @@ module GitlabRoutingHelper end def edit_milestone_path(entity, *args) - if entity.parent.is_a?(Group) - edit_group_milestone_path(entity.parent, entity, *args) + if entity.resource_parent.is_a?(Group) + edit_group_milestone_path(entity.resource_parent, entity, *args) else - edit_project_milestone_path(entity.parent, entity, *args) + edit_project_milestone_path(entity.resource_parent, entity, *args) end end diff --git a/app/helpers/groups_helper.rb b/app/helpers/groups_helper.rb index 601560cca92..6ddcbf61090 100644 --- a/app/helpers/groups_helper.rb +++ b/app/helpers/groups_helper.rb @@ -15,6 +15,18 @@ module GroupsHelper %w[groups#projects groups#edit badges#index ci_cd#show ldap_group_links#index hooks#index audit_events#index pipeline_quota#index] end + def group_packages_nav_link_paths + %w[ + groups/container_registries#index + ] + end + + def group_container_registry_nav? + Gitlab.config.registry.enabled && + can?(current_user, :read_container_image, @group) && + Feature.enabled?(:group_container_registry_browser, @group) + end + def group_sidebar_links @group_sidebar_links ||= get_group_sidebar_links end @@ -32,8 +44,7 @@ module GroupsHelper end def can_disable_group_emails?(group) - Feature.enabled?(:emails_disabled, group, default_enabled: true) && - can?(current_user, :set_emails_disabled, group) && !group.parent&.emails_disabled? + can?(current_user, :set_emails_disabled, group) && !group.parent&.emails_disabled? end def group_issues_count(state:) diff --git a/app/helpers/issuables_helper.rb b/app/helpers/issuables_helper.rb index 014523b54cb..df9d1933271 100644 --- a/app/helpers/issuables_helper.rb +++ b/app/helpers/issuables_helper.rb @@ -272,7 +272,7 @@ module IssuablesHelper markdownPreviewPath: preview_markdown_path(parent), markdownDocsPath: help_page_path('user/markdown'), lockVersion: issuable.lock_version, - issuableTemplates: issuable_templates(issuable), + issuableTemplateNamesPath: template_names_path(parent, issuable), initialTitleHtml: markdown_field(issuable, :title), initialTitleText: issuable.title, initialDescriptionHtml: markdown_field(issuable, :description), @@ -372,6 +372,12 @@ module IssuablesHelper finder.class.scalar_params.any? { |p| params[p].present? } end + def assignee_sidebar_data(assignee, merge_request: nil) + { avatar_url: assignee.avatar_url, name: assignee.name, username: assignee.username }.tap do |data| + data[:can_merge] = merge_request.can_be_merged_by?(assignee) if merge_request + end + end + private def sidebar_gutter_collapsed? @@ -429,6 +435,12 @@ module IssuablesHelper end end + def template_names_path(parent, issuable) + return '' unless parent.is_a?(Project) + + project_template_names_path(parent, template_type: issuable.class.name.underscore) + end + def issuable_sidebar_options(issuable) { endpoint: "#{issuable[:issuable_json_path]}?serializer=sidebar_extras", diff --git a/app/helpers/nav_helper.rb b/app/helpers/nav_helper.rb index 6aa910e6c3f..2ce45cec878 100644 --- a/app/helpers/nav_helper.rb +++ b/app/helpers/nav_helper.rb @@ -20,7 +20,6 @@ module NavHelper def page_gutter_class if page_has_markdown? - if cookies[:collapsed_gutter] == 'true' %w[page-gutter right-sidebar-collapsed] else @@ -87,6 +86,12 @@ module NavHelper links << :admin_impersonation end + if Feature.enabled?(:user_mode_in_session) + if current_user&.admin? && current_user_mode&.admin_mode? + links << :admin_mode + end + end + links end end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index bf6abdb8c4b..16360c7139a 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -76,7 +76,7 @@ module ProjectsHelper link_to(author_html, user_path(author), class: "author-link js-user-link #{"#{opts[:extra_class]}" if opts[:extra_class]} #{"#{opts[:mobile_classes]}" if opts[:mobile_classes]}", data: data_attrs).html_safe else title = opts[:title].sub(":name", sanitize(author.name)) - link_to(author_html, user_path(author), class: "author-link has-tooltip", title: title, data: { container: 'body' }).html_safe + link_to(author_html, user_path(author), class: "author-link has-tooltip", title: title, data: { container: 'body', qa_selector: 'assignee_link' }).html_safe end end @@ -160,7 +160,7 @@ module ProjectsHelper def can_disable_emails?(project, current_user) return false if project.group&.emails_disabled? - can?(current_user, :set_emails_disabled, project) && Feature.enabled?(:emails_disabled, project, default_enabled: true) + can?(current_user, :set_emails_disabled, project) end def last_push_event @@ -168,7 +168,7 @@ module ProjectsHelper end def link_to_autodeploy_doc - link_to _('About auto deploy'), help_page_path('ci/autodeploy/index'), target: '_blank' + link_to _('About auto deploy'), help_page_path('autodevops/index.md#auto-deploy'), target: '_blank' end def autodeploy_flash_notice(branch_name) @@ -354,6 +354,14 @@ module ProjectsHelper @project.metrics_setting_external_dashboard_url end + def grafana_integration_url + @project.grafana_integration&.grafana_url + end + + def grafana_integration_token + @project.grafana_integration&.token + end + private def get_project_nav_tabs(project, current_user) @@ -565,7 +573,7 @@ module ProjectsHelper lfsHelpPath: help_page_path('workflow/lfs/manage_large_binaries_with_git_lfs'), pagesAvailable: Gitlab.config.pages.enabled, pagesAccessControlEnabled: Gitlab.config.pages.access_control, - pagesHelpPath: help_page_path('user/project/pages/introduction', anchor: 'gitlab-pages-access-control-core-only') + pagesHelpPath: help_page_path('user/project/pages/introduction', anchor: 'gitlab-pages-access-control-core') } end diff --git a/app/helpers/releases_helper.rb b/app/helpers/releases_helper.rb index 4d9fe345edf..68a19152d8f 100644 --- a/app/helpers/releases_helper.rb +++ b/app/helpers/releases_helper.rb @@ -12,27 +12,21 @@ module ReleasesHelper help_page_path(DOCUMENTATION_PATH) end - def url_for_merge_requests - project_merge_requests_url(@project, params_for_issue_and_mr_paths) - end - - def url_for_issues - project_issues_url(@project, params_for_issue_and_mr_paths) - end - def data_for_releases_page { project_id: @project.id, illustration_path: illustration, - documentation_path: help_page, - merge_requests_url: url_for_merge_requests, - issues_url: url_for_issues + documentation_path: help_page } end - private - - def params_for_issue_and_mr_paths - { scope: 'all', state: 'opened' } + def data_for_edit_release_page + { + project_id: @project.id, + tag_name: @release.tag, + markdown_preview_path: preview_markdown_path(@project), + markdown_docs_path: help_page_path('user/markdown'), + releases_page_path: project_releases_path(@project, anchor: @release.tag) + } end end diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 0f4e5adca6c..9a19758b4e8 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -34,15 +34,15 @@ module SearchHelper from: from, to: to, count: count, - scope: search_entries_info_label(scope, count), + scope: search_entries_scope_label(scope, count), term: term } end - def search_entries_info_label(scope, count) + def search_entries_scope_label(scope, count) case scope - when 'blobs', 'snippet_blobs', 'wiki_blobs' - ns_('SearchResults|result', 'SearchResults|results', count) + when 'blobs' + ns_('SearchResults|code result', 'SearchResults|code results', count) when 'commits' ns_('SearchResults|commit', 'SearchResults|commits', count) when 'issues' @@ -55,10 +55,14 @@ 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' ns_('SearchResults|user', 'SearchResults|users', count) + when 'wiki_blobs' + ns_('SearchResults|wiki result', 'SearchResults|wiki results', count) else raise "Unrecognized search scope '#{scope}'" end @@ -72,6 +76,13 @@ module SearchHelper end end + def search_entries_empty_message(scope, term) + (s_("SearchResults|We couldn't find any %{scope} matching %{term}") % { + scope: search_entries_scope_label(scope, 0), + term: "<code>#{h(term)}</code>" + }).html_safe + end + def find_project_for_result_blob(projects, result) @project end diff --git a/app/helpers/sorting_helper.rb b/app/helpers/sorting_helper.rb index d680e10525d..33f3bb0b749 100644 --- a/app/helpers/sorting_helper.rb +++ b/app/helpers/sorting_helper.rb @@ -28,7 +28,9 @@ module SortingHelper sort_value_priority => sort_title_priority, sort_value_upvotes => sort_title_upvotes, sort_value_contacted_date => sort_title_contacted_date, - sort_value_relative_position => sort_title_relative_position + sort_value_relative_position => sort_title_relative_position, + sort_value_size => sort_title_size, + sort_value_expire_date => sort_title_expire_date } end @@ -406,6 +408,14 @@ module SortingHelper s_('SortOptions|Manual') end + def sort_title_size + s_('SortOptions|Size') + end + + def sort_title_expire_date + s_('SortOptions|Expired date') + end + # Values. def sort_value_access_level_asc 'access_level_asc' @@ -558,4 +568,12 @@ module SortingHelper def sort_value_relative_position 'relative_position' end + + def sort_value_size + 'size_desc' + end + + def sort_value_expire_date + 'expired_asc' + end end diff --git a/app/helpers/submodule_helper.rb b/app/helpers/submodule_helper.rb index e683e2959d1..4b83988e8bb 100644 --- a/app/helpers/submodule_helper.rb +++ b/app/helpers/submodule_helper.rb @@ -81,7 +81,7 @@ module SubmoduleHelper end def relative_self_links(relative_path, commit, project) - relative_path.rstrip! + relative_path = relative_path.rstrip absolute_project_path = "/" + project.full_path # Resolve `relative_path` to target path diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index de0b92b6fd7..4984b51555d 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -28,4 +28,14 @@ module TagsHelper def protected_tag?(project, tag) ProtectedTag.protected?(project, tag.name) end + + def tag_description_help_text + text = s_('TagsPage|Optionally, add a message to the tag. Leaving this blank creates '\ + 'a %{link_start}lightweight tag.%{link_end}') % { + link_start: '<a href="https://git-scm.com/book/en/v2/Git-Basics-Tagging\" target="_blank" rel="noopener noreferrer">', + link_end: '</a>' + } + + text.html_safe + end end diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index a919c068c42..dce0842060d 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -45,8 +45,8 @@ module TodosHelper end def todo_parent_path(todo) - if todo.parent.is_a?(Group) - link_to todo.parent.name, group_path(todo.parent) + if todo.resource_parent.is_a?(Group) + link_to todo.resource_parent.name, group_path(todo.resource_parent) else link_to_project(todo.project) end @@ -64,7 +64,7 @@ module TodosHelper if todo.for_commit? project_commit_path(todo.project, todo.target, path_options) else - path = [todo.parent, todo.target] + path = [todo.resource_parent, todo.target] path.unshift(:pipelines) if todo.build_failed? |