diff options
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/appearances_helper.rb | 5 | ||||
-rw-r--r-- | app/helpers/application_settings_helper.rb | 5 | ||||
-rw-r--r-- | app/helpers/boards_helper.rb | 3 | ||||
-rw-r--r-- | app/helpers/ci_variables_helper.rb | 4 | ||||
-rw-r--r-- | app/helpers/dropdowns_helper.rb | 2 | ||||
-rw-r--r-- | app/helpers/emails_helper.rb | 6 | ||||
-rw-r--r-- | app/helpers/environments_helper.rb | 3 | ||||
-rw-r--r-- | app/helpers/issuables_helper.rb | 9 | ||||
-rw-r--r-- | app/helpers/issues_helper.rb | 15 | ||||
-rw-r--r-- | app/helpers/markup_helper.rb | 7 | ||||
-rw-r--r-- | app/helpers/recaptcha_experiment_helper.rb | 7 | ||||
-rw-r--r-- | app/helpers/search_helper.rb | 11 | ||||
-rw-r--r-- | app/helpers/services_helper.rb | 2 | ||||
-rw-r--r-- | app/helpers/todos_helper.rb | 2 | ||||
-rw-r--r-- | app/helpers/user_callouts_helper.rb | 5 | ||||
-rw-r--r-- | app/helpers/visibility_level_helper.rb | 38 |
16 files changed, 100 insertions, 24 deletions
diff --git a/app/helpers/appearances_helper.rb b/app/helpers/appearances_helper.rb index c0db9910143..6b43d52c775 100644 --- a/app/helpers/appearances_helper.rb +++ b/app/helpers/appearances_helper.rb @@ -2,6 +2,7 @@ module AppearancesHelper include MarkupHelper + include Gitlab::Utils::StrongMemoize def brand_title current_appearance&.title.presence || default_brand_title @@ -25,7 +26,9 @@ module AppearancesHelper end def current_appearance - @appearance ||= Appearance.current + strong_memoize(:current_appearance) do + Appearance.current + end end def brand_header_logo diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb index 4469118f065..aaaa954047f 100644 --- a/app/helpers/application_settings_helper.rb +++ b/app/helpers/application_settings_helper.rb @@ -165,8 +165,6 @@ module ApplicationSettingsHelper :authorized_keys_enabled, :auto_devops_enabled, :auto_devops_domain, - :clientside_sentry_dsn, - :clientside_sentry_enabled, :container_registry_token_expire_delay, :default_artifacts_expire_in, :default_branch_protection, @@ -235,8 +233,6 @@ module ApplicationSettingsHelper :restricted_visibility_levels, :rsa_key_restriction, :send_user_confirmation_email, - :sentry_dsn, - :sentry_enabled, :session_expire_delay, :shared_runners_enabled, :shared_runners_text, @@ -253,6 +249,7 @@ module ApplicationSettingsHelper :throttle_unauthenticated_enabled, :throttle_unauthenticated_period_in_seconds, :throttle_unauthenticated_requests_per_period, + :time_tracking_limit_to_hours, :two_factor_grace_period, :unique_ips_limit_enabled, :unique_ips_limit_per_user, diff --git a/app/helpers/boards_helper.rb b/app/helpers/boards_helper.rb index 1640f4fc93f..c5130b430b9 100644 --- a/app/helpers/boards_helper.rb +++ b/app/helpers/boards_helper.rb @@ -14,7 +14,8 @@ module BoardsHelper issue_link_base: build_issue_link_base, root_path: root_path, bulk_update_path: @bulk_issues_path, - default_avatar: image_path(default_avatar) + default_avatar: image_path(default_avatar), + time_tracking_limit_to_hours: Gitlab::CurrentSettings.time_tracking_limit_to_hours.to_s } end diff --git a/app/helpers/ci_variables_helper.rb b/app/helpers/ci_variables_helper.rb index e313015c937..fc51f00d052 100644 --- a/app/helpers/ci_variables_helper.rb +++ b/app/helpers/ci_variables_helper.rb @@ -27,4 +27,8 @@ module CiVariablesHelper %w(File file) ] end + + def ci_variable_maskable_regex + Maskable::REGEX.inspect.sub('\\A', '^').sub('\\z', '$').sub(/^\//, '').sub(/\/[a-z]*$/, '').gsub('\/', '/') + end end diff --git a/app/helpers/dropdowns_helper.rb b/app/helpers/dropdowns_helper.rb index 8d8c62f1291..64c5fae7d96 100644 --- a/app/helpers/dropdowns_helper.rb +++ b/app/helpers/dropdowns_helper.rb @@ -91,7 +91,7 @@ module DropdownsHelper def dropdown_filter(placeholder, search_id: nil) content_tag :div, class: "dropdown-input" do - filter_output = search_field_tag search_id, nil, class: "dropdown-input-field", placeholder: placeholder, autocomplete: 'off' + filter_output = search_field_tag search_id, nil, class: "dropdown-input-field qa-dropdown-input-field", placeholder: placeholder, autocomplete: 'off' filter_output << icon('search', class: "dropdown-input-search") filter_output << icon('times', class: "dropdown-input-clear js-dropdown-input-clear", role: "button") diff --git a/app/helpers/emails_helper.rb b/app/helpers/emails_helper.rb index 2beb081ab77..36122d3a22a 100644 --- a/app/helpers/emails_helper.rb +++ b/app/helpers/emails_helper.rb @@ -57,12 +57,6 @@ module EmailsHelper pluralize(valid_length, unit) end - def reset_token_expire_message - link_tag = link_to('request a new one', new_user_password_url(user_email: @user.email)) - "This link is valid for #{password_reset_token_valid_time}. " \ - "After it expires, you can #{link_tag}." - end - def header_logo if current_appearance&.header_logo? image_tag( diff --git a/app/helpers/environments_helper.rb b/app/helpers/environments_helper.rb index 8002eb08ada..0f118c235d8 100644 --- a/app/helpers/environments_helper.rb +++ b/app/helpers/environments_helper.rb @@ -26,7 +26,8 @@ module EnvironmentsHelper "empty-no-data-svg-path" => image_path('illustrations/monitoring/no_data.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), - "deployment-endpoint" => project_environment_deployments_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), "environments-endpoint": project_environments_path(project, format: :json), "project-path" => project_path(project), "tags-path" => project_tags_path(project), diff --git a/app/helpers/issuables_helper.rb b/app/helpers/issuables_helper.rb index 9a12db258d5..cd2669ef6ad 100644 --- a/app/helpers/issuables_helper.rb +++ b/app/helpers/issuables_helper.rb @@ -74,7 +74,7 @@ module IssuablesHelper end end - def serialize_issuable(issuable, serializer: nil) + def serialize_issuable(issuable, opts = {}) serializer_klass = case issuable when Issue IssueSerializer @@ -84,7 +84,7 @@ module IssuablesHelper serializer_klass .new(current_user: current_user, project: issuable.project) - .represent(issuable, serializer: serializer) + .represent(issuable, opts) .to_json end @@ -280,7 +280,7 @@ module IssuablesHelper initialTaskStatus: issuable.task_status } - data[:hasClosingMergeRequest] = issuable.merge_requests_count != 0 if issuable.is_a?(Issue) + data[:hasClosingMergeRequest] = issuable.merge_requests_count(current_user) != 0 if issuable.is_a?(Issue) if parent.is_a?(Group) data[:groupPath] = parent.path @@ -430,7 +430,8 @@ module IssuablesHelper editable: issuable.dig(:current_user, :can_edit), currentUser: issuable[:current_user], rootPath: root_path, - fullPath: issuable[:project_full_path] + fullPath: issuable[:project_full_path], + timeTrackingLimitToHours: Gitlab::CurrentSettings.time_tracking_limit_to_hours } end diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 957ab06b0ca..dfadcfc33b2 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -5,6 +5,7 @@ module IssuesHelper classes = ["issue"] classes << "closed" if issue.closed? classes << "today" if issue.today? + classes << "user-can-drag" if @sort == 'relative_position' classes.join(' ') end @@ -135,6 +136,20 @@ module IssuesHelper can?(current_user, :create_issue, project) end + def create_confidential_merge_request_enabled? + Feature.enabled?(:create_confidential_merge_request, @project) + 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 + # Required for Banzai::Filter::IssueReferenceFilter module_function :url_for_issue module_function :url_for_internal_issue diff --git a/app/helpers/markup_helper.rb b/app/helpers/markup_helper.rb index dce4168ad7b..8ccb39f8444 100644 --- a/app/helpers/markup_helper.rb +++ b/app/helpers/markup_helper.rb @@ -263,6 +263,11 @@ module MarkupHelper end def asciidoc_unsafe(text, context = {}) + context.merge!( + commit: @commit, + ref: @ref, + requested_path: @path + ) Gitlab::Asciidoc.render(text, context) end @@ -273,7 +278,7 @@ module MarkupHelper def prepare_for_rendering(html, context = {}) return '' unless html.present? - context.merge!( + context.reverse_merge!( current_user: (current_user if defined?(current_user)), # RelativeLinkFilter diff --git a/app/helpers/recaptcha_experiment_helper.rb b/app/helpers/recaptcha_experiment_helper.rb new file mode 100644 index 00000000000..d2eb9ac54f6 --- /dev/null +++ b/app/helpers/recaptcha_experiment_helper.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module RecaptchaExperimentHelper + def show_recaptcha_sign_up? + !!Gitlab::Recaptcha.enabled? + end +end diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 4594f5a31b9..f5c4686a3bf 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -169,14 +169,19 @@ module SearchHelper autocomplete: 'off' } + opts[:data]['runner-tags-endpoint'] = tag_list_admin_runners_path + if @project.present? opts[:data]['project-id'] = @project.id - opts[:data]['base-endpoint'] = project_path(@project) + opts[:data]['labels-endpoint'] = project_labels_path(@project) + opts[:data]['milestones-endpoint'] = project_milestones_path(@project) elsif @group.present? opts[:data]['group-id'] = @group.id - opts[:data]['base-endpoint'] = group_canonical_path(@group) + opts[:data]['labels-endpoint'] = group_labels_path(@group) + opts[:data]['milestones-endpoint'] = group_milestones_path(@group) else - opts[:data]['base-endpoint'] = root_dashboard_path + opts[:data]['labels-endpoint'] = dashboard_labels_path + opts[:data]['milestones-endpoint'] = dashboard_milestones_path end opts diff --git a/app/helpers/services_helper.rb b/app/helpers/services_helper.rb index d4b50b7ecfb..01ccf163b45 100644 --- a/app/helpers/services_helper.rb +++ b/app/helpers/services_helper.rb @@ -39,7 +39,7 @@ module ServicesHelper end def disable_fields_service?(service) - !current_controller?("admin/services") && service.deprecated? + service.is_a?(KubernetesService) || (!current_controller?("admin/services") && service.deprecated?) end extend self diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index 6bd78336ed3..645160077f5 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -170,7 +170,7 @@ module TodosHelper end def todo_group_options - groups = current_user.authorized_groups.map do |group| + groups = current_user.authorized_groups.with_route.map do |group| { id: group.id, text: group.full_name } end diff --git a/app/helpers/user_callouts_helper.rb b/app/helpers/user_callouts_helper.rb index 5d658d35107..d5e459311f7 100644 --- a/app/helpers/user_callouts_helper.rb +++ b/app/helpers/user_callouts_helper.rb @@ -3,6 +3,7 @@ module UserCalloutsHelper GKE_CLUSTER_INTEGRATION = 'gke_cluster_integration'.freeze GCP_SIGNUP_OFFER = 'gcp_signup_offer'.freeze + SUGGEST_POPOVER_DISMISSED = 'suggest_popover_dismissed'.freeze def show_gke_cluster_integration_callout?(project) can?(current_user, :create_cluster, project) && @@ -20,6 +21,10 @@ module UserCalloutsHelper def render_dashboard_gold_trial(user) end + def show_suggest_popover? + !user_dismissed?(SUGGEST_POPOVER_DISMISSED) + end + private def user_dismissed?(feature_name) diff --git a/app/helpers/visibility_level_helper.rb b/app/helpers/visibility_level_helper.rb index 9deb783d289..b318b27992a 100644 --- a/app/helpers/visibility_level_helper.rb +++ b/app/helpers/visibility_level_helper.rb @@ -165,8 +165,46 @@ module VisibilityLevelHelper !form_model.visibility_level_allowed?(level) end + # Visibility level can be restricted in two ways: + # + # 1. The group permissions (e.g. a subgroup is private, which requires + # all projects to be private) + # 2. The global allowed visibility settings, set by the admin + def selected_visibility_level(form_model, requested_level) + requested_level = + if requested_level.present? + requested_level.to_i + else + default_project_visibility + end + + [requested_level, max_allowed_visibility_level(form_model)].min + end + private + def max_allowed_visibility_level(form_model) + # First obtain the maximum visibility for the project or group + current_level = max_allowed_visibility_level_by_model(form_model) + + # Now limit this by the global setting + Gitlab::VisibilityLevel.closest_allowed_level(current_level) + end + + def max_allowed_visibility_level_by_model(form_model) + current_level = Gitlab::VisibilityLevel::PRIVATE + + Gitlab::VisibilityLevel.values.sort.each do |value| + if disallowed_visibility_level?(form_model, value) + break + else + current_level = value + end + end + + current_level + end + def visibility_level_errors_for_group(group, level_name) group_name = link_to group.name, group_path(group) change_visiblity = link_to 'change the visibility', edit_group_path(group) |