diff options
Diffstat (limited to 'app/controllers/concerns')
22 files changed, 164 insertions, 142 deletions
diff --git a/app/controllers/concerns/accepts_pending_invitations.rb b/app/controllers/concerns/accepts_pending_invitations.rb index cb66c1a055d..5601b7a7f79 100644 --- a/app/controllers/concerns/accepts_pending_invitations.rb +++ b/app/controllers/concerns/accepts_pending_invitations.rb @@ -6,7 +6,15 @@ module AcceptsPendingInvitations def accept_pending_invitations return unless resource.active_for_authentication? - clear_stored_location_for_resource if resource.accept_pending_invitations!.any? + if resource.pending_invitations.load.any? + resource.accept_pending_invitations! + clear_stored_location_for_resource + after_pending_invitations_hook + end + end + + def after_pending_invitations_hook + # no-op end def clear_stored_location_for_resource diff --git a/app/controllers/concerns/authenticates_with_two_factor.rb b/app/controllers/concerns/authenticates_with_two_factor.rb index 87555a28eb8..4f4b204def8 100644 --- a/app/controllers/concerns/authenticates_with_two_factor.rb +++ b/app/controllers/concerns/authenticates_with_two_factor.rb @@ -177,4 +177,4 @@ module AuthenticatesWithTwoFactor end end -AuthenticatesWithTwoFactor.prepend_if_ee('EE::AuthenticatesWithTwoFactor') +AuthenticatesWithTwoFactor.prepend_mod_with('AuthenticatesWithTwoFactor') diff --git a/app/controllers/concerns/boards_actions.rb b/app/controllers/concerns/boards_actions.rb index 79e6f027c2f..2f9edfad12d 100644 --- a/app/controllers/concerns/boards_actions.rb +++ b/app/controllers/concerns/boards_actions.rb @@ -7,12 +7,10 @@ module BoardsActions included do include BoardsResponses + before_action :authorize_read_board!, only: [:index, :show] before_action :boards, only: :index before_action :board, only: :show before_action :push_licensed_features, only: [:index, :show] - before_action do - push_frontend_feature_flag(:not_issuable_queries, parent, default_enabled: true) - end end def index @@ -21,7 +19,7 @@ module BoardsActions def show # Add / update the board in the recent visits table - Boards::Visits::CreateService.new(parent, current_user).execute(board) if request.format.html? + board_visit_service.new(parent, current_user).execute(board) if request.format.html? respond_with_board end @@ -54,6 +52,10 @@ module BoardsActions board_klass.to_type end + def board_visit_service + Boards::Visits::CreateService + end + def serializer BoardSerializer.new(current_user: current_user) end @@ -63,4 +65,4 @@ module BoardsActions end end -BoardsActions.prepend_if_ee('EE::BoardsActions') +BoardsActions.prepend_mod_with('BoardsActions') diff --git a/app/controllers/concerns/boards_responses.rb b/app/controllers/concerns/boards_responses.rb index 7307b7b4f8f..eb7392648a1 100644 --- a/app/controllers/concerns/boards_responses.rb +++ b/app/controllers/concerns/boards_responses.rb @@ -91,4 +91,4 @@ module BoardsResponses end end -BoardsResponses.prepend_if_ee('EE::BoardsResponses') +BoardsResponses.prepend_mod_with('BoardsResponses') diff --git a/app/controllers/concerns/cycle_analytics_params.rb b/app/controllers/concerns/cycle_analytics_params.rb index 50e340dc9b1..b74e343f90b 100644 --- a/app/controllers/concerns/cycle_analytics_params.rb +++ b/app/controllers/concerns/cycle_analytics_params.rb @@ -43,4 +43,4 @@ module CycleAnalyticsParams end end -CycleAnalyticsParams.prepend_if_ee('EE::CycleAnalyticsParams') +CycleAnalyticsParams.prepend_mod_with('CycleAnalyticsParams') diff --git a/app/controllers/concerns/enforces_two_factor_authentication.rb b/app/controllers/concerns/enforces_two_factor_authentication.rb index bf38e4ad117..c67e73d4e78 100644 --- a/app/controllers/concerns/enforces_two_factor_authentication.rb +++ b/app/controllers/concerns/enforces_two_factor_authentication.rb @@ -72,4 +72,4 @@ module EnforcesTwoFactorAuthentication end end -EnforcesTwoFactorAuthentication.prepend_if_ee('EE::EnforcesTwoFactorAuthentication') +EnforcesTwoFactorAuthentication.prepend_mod_with('EnforcesTwoFactorAuthentication') diff --git a/app/controllers/concerns/floc_opt_out.rb b/app/controllers/concerns/floc_opt_out.rb new file mode 100644 index 00000000000..3039af02bbb --- /dev/null +++ b/app/controllers/concerns/floc_opt_out.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module FlocOptOut + extend ActiveSupport::Concern + + included do + after_action :set_floc_opt_out_header, unless: :floc_enabled? + end + + def floc_enabled? + Gitlab::CurrentSettings.floc_enabled + end + + def set_floc_opt_out_header + response.headers['Permissions-Policy'] = 'interest-cohort=()' + end +end diff --git a/app/controllers/concerns/integrations/params.rb b/app/controllers/concerns/integrations/params.rb new file mode 100644 index 00000000000..10122b4c77b --- /dev/null +++ b/app/controllers/concerns/integrations/params.rb @@ -0,0 +1,105 @@ +# frozen_string_literal: true + +module Integrations + module Params + extend ActiveSupport::Concern + + ALLOWED_PARAMS_CE = [ + :active, + :add_pusher, + :alert_events, + :api_key, + :api_url, + :bamboo_url, + :branches_to_be_notified, + :labels_to_be_notified, + :labels_to_be_notified_behavior, + :build_key, + :build_type, + :ca_pem, + :channel, + :channels, + :color, + :colorize_messages, + :comment_on_event_enabled, + :comment_detail, + :confidential_issues_events, + :confluence_url, + :datadog_site, + :datadog_env, + :datadog_service, + :default_irc_uri, + :device, + :disable_diffs, + :drone_url, + :enable_ssl_verification, + :external_wiki_url, + :google_iap_service_account_json, + :google_iap_audience_client_id, + :inherit_from_id, + # We're using `issues_events` and `merge_requests_events` + # in the view so we still need to explicitly state them + # here. `Service#event_names` would only give + # `issue_events` and `merge_request_events` (singular!) + # See app/helpers/services_helper.rb for how we + # make those event names plural as special case. + :issues_events, + :issues_url, + :jenkins_url, + :jira_issue_transition_automatic, + :jira_issue_transition_id, + :manual_configuration, + :merge_requests_events, + :mock_service_url, + :namespace, + :new_issue_url, + :notify_only_broken_pipelines, + :password, + :priority, + :project_key, + :project_name, + :project_url, + :recipients, + :restrict_to_branch, + :room, + :send_from_committer_email, + :server, + :server_host, + :server_port, + :sound, + :subdomain, + :teamcity_url, + :token, + :type, + :url, + :user_key, + :username, + :webhook + ].freeze + + # Parameters to ignore if no value is specified + FILTER_BLANK_PARAMS = [:password].freeze + + def integration_params + dynamic_params = @integration.event_channel_names + @integration.event_names # rubocop:disable Gitlab/ModuleWithInstanceVariables + allowed = allowed_integration_params + dynamic_params + return_value = params.permit(:id, integration: allowed, service: allowed) + return_value[:integration] ||= return_value.delete(:service) + param_values = return_value[:integration] + + if param_values.is_a?(ActionController::Parameters) + FILTER_BLANK_PARAMS.each do |param| + param_values.delete(param) if param_values[param].blank? + end + end + + return_value + end + + def allowed_integration_params + ALLOWED_PARAMS_CE + end + end +end + +Integrations::Params.prepend_mod_with('Integrations::Params') diff --git a/app/controllers/concerns/integrations_actions.rb b/app/controllers/concerns/integrations_actions.rb index a3ea39d9c3d..f5a3ec913c2 100644 --- a/app/controllers/concerns/integrations_actions.rb +++ b/app/controllers/concerns/integrations_actions.rb @@ -4,7 +4,7 @@ module IntegrationsActions extend ActiveSupport::Concern included do - include ServiceParams + include Integrations::Params before_action :integration, only: [:edit, :update, :test] end @@ -14,7 +14,7 @@ module IntegrationsActions end def update - saved = integration.update(service_params[:service]) + saved = integration.update(integration_params[:integration]) respond_to do |format| format.html do @@ -49,9 +49,7 @@ module IntegrationsActions private def integration - # Using instance variable `@service` still required as it's used in ServiceParams. - # Should be removed once that is refactored to use `@integration`. - @integration = @service ||= find_or_initialize_non_project_specific_integration(params[:id]) # rubocop:disable Gitlab/ModuleWithInstanceVariables + @integration ||= find_or_initialize_non_project_specific_integration(params[:id]) end def success_message diff --git a/app/controllers/concerns/internal_redirect.rb b/app/controllers/concerns/internal_redirect.rb index a35bc19aa37..b803be67d2e 100644 --- a/app/controllers/concerns/internal_redirect.rb +++ b/app/controllers/concerns/internal_redirect.rb @@ -46,4 +46,4 @@ module InternalRedirect end end -InternalRedirect.prepend_if_ee('EE::InternalRedirect') +InternalRedirect.prepend_mod_with('InternalRedirect') diff --git a/app/controllers/concerns/issuable_actions.rb b/app/controllers/concerns/issuable_actions.rb index 57d4203ad43..929e60a9e77 100644 --- a/app/controllers/concerns/issuable_actions.rb +++ b/app/controllers/concerns/issuable_actions.rb @@ -8,9 +8,6 @@ module IssuableActions before_action :authorize_destroy_issuable!, only: :destroy before_action :check_destroy_confirmation!, only: :destroy before_action :authorize_admin_issuable!, only: :bulk_update - before_action do - push_frontend_feature_flag(:not_issuable_queries, @project, default_enabled: true) - end end def show @@ -64,7 +61,7 @@ module IssuableActions end def destroy - Issuable::DestroyService.new(issuable.project, current_user).execute(issuable) + Issuable::DestroyService.new(project: issuable.project, current_user: current_user).execute(issuable) name = issuable.human_class_name flash[:notice] = "The #{name} was successfully deleted." @@ -262,4 +259,4 @@ module IssuableActions # rubocop:enable Gitlab/ModuleWithInstanceVariables end -IssuableActions.prepend_if_ee('EE::IssuableActions') +IssuableActions.prepend_mod_with('IssuableActions') diff --git a/app/controllers/concerns/issuable_collections.rb b/app/controllers/concerns/issuable_collections.rb index 3f5f3b6e9df..d2d2e656af8 100644 --- a/app/controllers/concerns/issuable_collections.rb +++ b/app/controllers/concerns/issuable_collections.rb @@ -158,4 +158,4 @@ module IssuableCollections # rubocop:enable Gitlab/ModuleWithInstanceVariables end -IssuableCollections.prepend_if_ee('EE::IssuableCollections') +IssuableCollections.prepend_mod_with('IssuableCollections') diff --git a/app/controllers/concerns/issuable_collections_action.rb b/app/controllers/concerns/issuable_collections_action.rb index 7ed66027da3..ca2979a5a29 100644 --- a/app/controllers/concerns/issuable_collections_action.rb +++ b/app/controllers/concerns/issuable_collections_action.rb @@ -32,10 +32,6 @@ module IssuableCollectionsAction private - def set_not_query_feature_flag(object = nil) - push_frontend_feature_flag(:not_issuable_queries, object, default_enabled: true) - end - def sorting_field case action_name when 'issues' diff --git a/app/controllers/concerns/lfs_request.rb b/app/controllers/concerns/lfs_request.rb index bc3fd32759f..55e0ed8cd42 100644 --- a/app/controllers/concerns/lfs_request.rb +++ b/app/controllers/concerns/lfs_request.rb @@ -136,4 +136,4 @@ module LfsRequest end end -LfsRequest.prepend_if_ee('EE::LfsRequest') +LfsRequest.prepend_mod_with('LfsRequest') diff --git a/app/controllers/concerns/membership_actions.rb b/app/controllers/concerns/membership_actions.rb index 7bbee8ba79e..20861afbb88 100644 --- a/app/controllers/concerns/membership_actions.rb +++ b/app/controllers/concerns/membership_actions.rb @@ -186,3 +186,5 @@ module MembershipActions end end end + +MembershipActions.prepend_mod_with('MembershipActions') diff --git a/app/controllers/concerns/page_limiter.rb b/app/controllers/concerns/page_limiter.rb index 3c280fa4f12..362b02e5856 100644 --- a/app/controllers/concerns/page_limiter.rb +++ b/app/controllers/concerns/page_limiter.rb @@ -46,7 +46,7 @@ module PageLimiter if params[:page].present? && params[:page].to_i > max_page_number record_page_limit_interception - raise PageOutOfBoundsError.new(max_page_number) + raise PageOutOfBoundsError, max_page_number end end diff --git a/app/controllers/concerns/renders_commits.rb b/app/controllers/concerns/renders_commits.rb index 4ea07c814ef..f1f5a1179c9 100644 --- a/app/controllers/concerns/renders_commits.rb +++ b/app/controllers/concerns/renders_commits.rb @@ -23,6 +23,7 @@ module RendersCommits def prepare_commits_for_rendering(commits) commits.each(&:lazy_author) # preload commits' authors + commits.each(&:lazy_latest_pipeline) Banzai::CommitRenderer.render(commits, @project, current_user) # rubocop:disable Gitlab/ModuleWithInstanceVariables diff --git a/app/controllers/concerns/requires_whitelisted_monitoring_client.rb b/app/controllers/concerns/requires_whitelisted_monitoring_client.rb index c92b1cecaaa..e98c1a30887 100644 --- a/app/controllers/concerns/requires_whitelisted_monitoring_client.rb +++ b/app/controllers/concerns/requires_whitelisted_monitoring_client.rb @@ -35,6 +35,6 @@ module RequiresWhitelistedMonitoringClient end def render_404 - render file: Rails.root.join('public', '404'), layout: false, status: '404' + render "errors/not_found", layout: "errors", status: :not_found end end diff --git a/app/controllers/concerns/routable_actions.rb b/app/controllers/concerns/routable_actions.rb index bc2e7fba288..7257378f465 100644 --- a/app/controllers/concerns/routable_actions.rb +++ b/app/controllers/concerns/routable_actions.rb @@ -56,4 +56,4 @@ module RoutableActions end end -RoutableActions.prepend_if_ee('EE::RoutableActions') +RoutableActions.prepend_mod_with('RoutableActions') diff --git a/app/controllers/concerns/service_params.rb b/app/controllers/concerns/service_params.rb deleted file mode 100644 index 7c57d321c80..00000000000 --- a/app/controllers/concerns/service_params.rb +++ /dev/null @@ -1,101 +0,0 @@ -# frozen_string_literal: true - -module ServiceParams - extend ActiveSupport::Concern - - ALLOWED_PARAMS_CE = [ - :active, - :add_pusher, - :alert_events, - :api_key, - :api_url, - :api_version, - :bamboo_url, - :branches_to_be_notified, - :labels_to_be_notified, - :build_key, - :build_type, - :ca_pem, - :channel, - :channels, - :color, - :colorize_messages, - :comment_on_event_enabled, - :comment_detail, - :confidential_issues_events, - :confluence_url, - :datadog_site, - :datadog_env, - :datadog_service, - :default_irc_uri, - :device, - :disable_diffs, - :drone_url, - :enable_ssl_verification, - :external_wiki_url, - :google_iap_service_account_json, - :google_iap_audience_client_id, - :inherit_from_id, - # We're using `issues_events` and `merge_requests_events` - # in the view so we still need to explicitly state them - # here. `Service#event_names` would only give - # `issue_events` and `merge_request_events` (singular!) - # See app/helpers/services_helper.rb for how we - # make those event names plural as special case. - :issues_events, - :issues_url, - :jenkins_url, - :jira_issue_transition_automatic, - :jira_issue_transition_id, - :manual_configuration, - :merge_requests_events, - :mock_service_url, - :namespace, - :new_issue_url, - :notify, - :notify_only_broken_pipelines, - :password, - :priority, - :project_key, - :project_name, - :project_url, - :recipients, - :restrict_to_branch, - :room, - :send_from_committer_email, - :server, - :server_host, - :server_port, - :sound, - :subdomain, - :teamcity_url, - :token, - :type, - :url, - :user_key, - :username, - :webhook - ].freeze - - # Parameters to ignore if no value is specified - FILTER_BLANK_PARAMS = [:password].freeze - - def service_params - dynamic_params = @service.event_channel_names + @service.event_names # rubocop:disable Gitlab/ModuleWithInstanceVariables - service_params = params.permit(:id, service: allowed_service_params + dynamic_params) - - if service_params[:service].is_a?(ActionController::Parameters) - FILTER_BLANK_PARAMS.each do |param| - service_params[:service].delete(param) if service_params[:service][param].blank? - end - end - - service_params - end - - def allowed_service_params - ALLOWED_PARAMS_CE - end -end - -ServiceParams.prepend_if_ee('EE::ServiceParams') diff --git a/app/controllers/concerns/wiki_actions.rb b/app/controllers/concerns/wiki_actions.rb index 60ff0a12d0c..fc4f9aa3409 100644 --- a/app/controllers/concerns/wiki_actions.rb +++ b/app/controllers/concerns/wiki_actions.rb @@ -115,9 +115,6 @@ module WikiActions @error = response.message render 'shared/wikis/edit' end - rescue WikiPage::PageChangedError, WikiPage::PageRenameError => e - @error = e.message - render 'shared/wikis/edit' end # rubocop:enable Gitlab/ModuleWithInstanceVariables @@ -141,8 +138,8 @@ module WikiActions # rubocop:disable Gitlab/ModuleWithInstanceVariables def history if page - @page_versions = Kaminari.paginate_array(page.versions(page: params[:page].to_i), - total_count: page.count_versions) + @commits = Kaminari.paginate_array(page.versions(page: params[:page].to_i), + total_count: page.count_versions) .page(params[:page]) render 'shared/wikis/history' diff --git a/app/controllers/concerns/with_performance_bar.rb b/app/controllers/concerns/with_performance_bar.rb index 93ded59900d..dc2265e063a 100644 --- a/app/controllers/concerns/with_performance_bar.rb +++ b/app/controllers/concerns/with_performance_bar.rb @@ -20,12 +20,12 @@ module WithPerformanceBar end def cookie_or_default_value - return false unless Gitlab::PerformanceBar.enabled_for_user?(current_user) + cookie_enabled = if cookies[:perf_bar_enabled].present? + cookies[:perf_bar_enabled] == 'true' + else + cookies[:perf_bar_enabled] = 'true' if Rails.env.development? + end - if cookies[:perf_bar_enabled].present? - cookies[:perf_bar_enabled] == 'true' - else - cookies[:perf_bar_enabled] = 'true' if Rails.env.development? - end + cookie_enabled && Gitlab::PerformanceBar.allowed_for_user?(current_user) end end |