diff options
Diffstat (limited to 'app/controllers/concerns')
-rw-r--r-- | app/controllers/concerns/authenticates_with_two_factor.rb | 12 | ||||
-rw-r--r-- | app/controllers/concerns/checks_collaboration.rb | 2 | ||||
-rw-r--r-- | app/controllers/concerns/graceful_timeout_handling.rb | 15 | ||||
-rw-r--r-- | app/controllers/concerns/integrations_actions.rb | 3 | ||||
-rw-r--r-- | app/controllers/concerns/issuable_collections.rb | 2 | ||||
-rw-r--r-- | app/controllers/concerns/packages_access.rb | 20 | ||||
-rw-r--r-- | app/controllers/concerns/paginated_collection.rb | 2 | ||||
-rw-r--r-- | app/controllers/concerns/renders_blob.rb | 8 | ||||
-rw-r--r-- | app/controllers/concerns/send_file_upload.rb | 21 | ||||
-rw-r--r-- | app/controllers/concerns/snippets_actions.rb | 22 | ||||
-rw-r--r-- | app/controllers/concerns/wiki_actions.rb | 10 |
11 files changed, 95 insertions, 22 deletions
diff --git a/app/controllers/concerns/authenticates_with_two_factor.rb b/app/controllers/concerns/authenticates_with_two_factor.rb index b885e55f902..4b4bcc8d37e 100644 --- a/app/controllers/concerns/authenticates_with_two_factor.rb +++ b/app/controllers/concerns/authenticates_with_two_factor.rb @@ -33,9 +33,7 @@ module AuthenticatesWithTwoFactor end def locked_user_redirect(user) - flash.now[:alert] = locked_user_redirect_alert(user) - - render 'devise/sessions/new' + redirect_to new_user_session_path, alert: locked_user_redirect_alert(user) end def authenticate_with_two_factor @@ -54,7 +52,13 @@ module AuthenticatesWithTwoFactor private def locked_user_redirect_alert(user) - user.access_locked? ? _('Your account is locked.') : _('Invalid Login or password') + if user.access_locked? + _('Your account is locked.') + elsif !user.confirmed? + I18n.t('devise.failure.unconfirmed') + else + _('Invalid Login or password') + end end def clear_two_factor_attempt! diff --git a/app/controllers/concerns/checks_collaboration.rb b/app/controllers/concerns/checks_collaboration.rb index 1fa82f7dcd4..87239facdeb 100644 --- a/app/controllers/concerns/checks_collaboration.rb +++ b/app/controllers/concerns/checks_collaboration.rb @@ -17,7 +17,7 @@ module ChecksCollaboration # used across multiple calls in the view def user_access(project) @user_access ||= {} - @user_access[project] ||= Gitlab::UserAccess.new(current_user, project: project) + @user_access[project] ||= Gitlab::UserAccess.new(current_user, container: project) end # rubocop:enable Gitlab/ModuleWithInstanceVariables end diff --git a/app/controllers/concerns/graceful_timeout_handling.rb b/app/controllers/concerns/graceful_timeout_handling.rb new file mode 100644 index 00000000000..490c0ec3b1d --- /dev/null +++ b/app/controllers/concerns/graceful_timeout_handling.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module GracefulTimeoutHandling + extend ActiveSupport::Concern + + included do + rescue_from ActiveRecord::QueryCanceled do |exception| + raise exception unless request.format.json? + + log_exception(exception) + + render json: { error: _('There is too much data to calculate. Please change your selection.') } + end + end +end diff --git a/app/controllers/concerns/integrations_actions.rb b/app/controllers/concerns/integrations_actions.rb index 46febc44807..9a8e5d14123 100644 --- a/app/controllers/concerns/integrations_actions.rb +++ b/app/controllers/concerns/integrations_actions.rb @@ -8,9 +8,6 @@ module IntegrationsActions before_action :not_found, unless: :integrations_enabled? before_action :integration, only: [:edit, :update, :test] - before_action only: :edit do - push_frontend_feature_flag(:integration_form_refactor, default_enabled: true) - end end def edit diff --git a/app/controllers/concerns/issuable_collections.rb b/app/controllers/concerns/issuable_collections.rb index 4f61e5ed711..89ba2175b60 100644 --- a/app/controllers/concerns/issuable_collections.rb +++ b/app/controllers/concerns/issuable_collections.rb @@ -65,7 +65,7 @@ module IssuableCollections def page_count_for_relation(relation, row_count) limit = relation.limit_value.to_f - return 1 if limit.zero? + return 1 if limit == 0 (row_count.to_f / limit).ceil end diff --git a/app/controllers/concerns/packages_access.rb b/app/controllers/concerns/packages_access.rb new file mode 100644 index 00000000000..6df2e064bb2 --- /dev/null +++ b/app/controllers/concerns/packages_access.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module PackagesAccess + extend ActiveSupport::Concern + + included do + before_action :verify_packages_enabled! + before_action :verify_read_package! + end + + private + + def verify_packages_enabled! + render_404 unless Gitlab.config.packages.enabled + end + + def verify_read_package! + authorize_read_package!(project) + end +end diff --git a/app/controllers/concerns/paginated_collection.rb b/app/controllers/concerns/paginated_collection.rb index be84215a9e2..fcee4493314 100644 --- a/app/controllers/concerns/paginated_collection.rb +++ b/app/controllers/concerns/paginated_collection.rb @@ -6,7 +6,7 @@ module PaginatedCollection private def redirect_out_of_range(collection, total_pages = collection.total_pages) - return false if total_pages.zero? + return false if total_pages == 0 out_of_range = collection.current_page > total_pages diff --git a/app/controllers/concerns/renders_blob.rb b/app/controllers/concerns/renders_blob.rb index b8026c7a01d..a15bf27a22f 100644 --- a/app/controllers/concerns/renders_blob.rb +++ b/app/controllers/concerns/renders_blob.rb @@ -29,6 +29,12 @@ module RendersBlob end def conditionally_expand_blob(blob) - blob.expand! if params[:expanded] == 'true' + conditionally_expand_blobs([blob]) + end + + def conditionally_expand_blobs(blobs) + return unless params[:expanded] == 'true' + + blobs.each { |blob| blob.expand! } end end diff --git a/app/controllers/concerns/send_file_upload.rb b/app/controllers/concerns/send_file_upload.rb index 2f5dc09be4a..7cb19fc7e58 100644 --- a/app/controllers/concerns/send_file_upload.rb +++ b/app/controllers/concerns/send_file_upload.rb @@ -18,7 +18,11 @@ module SendFileUpload send_params.merge!(filename: attachment, disposition: disposition) end - if file_upload.file_storage? + if image_scaling_request?(file_upload) + location = file_upload.file_storage? ? file_upload.path : file_upload.url + headers.store(*Gitlab::Workhorse.send_scaled_image(location, params[:width].to_i)) + head :ok + elsif file_upload.file_storage? send_file file_upload.path, send_params elsif file_upload.class.proxy_download_enabled? || proxy headers.store(*Gitlab::Workhorse.send_url(file_upload.url(**redirect_params))) @@ -37,4 +41,19 @@ module SendFileUpload "application/octet-stream" end end + + private + + def image_scaling_request?(file_upload) + avatar_image_upload?(file_upload) && valid_image_scaling_width? && current_user && + Feature.enabled?(:dynamic_image_resizing, current_user) + end + + def avatar_image_upload?(file_upload) + file_upload.try(:image?) && file_upload.try(:mounted_as)&.to_sym == :avatar + end + + def valid_image_scaling_width? + Avatarable::ALLOWED_IMAGE_SCALER_WIDTHS.include?(params[:width]&.to_i) + end end diff --git a/app/controllers/concerns/snippets_actions.rb b/app/controllers/concerns/snippets_actions.rb index 048b18c5c61..5552fd663f7 100644 --- a/app/controllers/concerns/snippets_actions.rb +++ b/app/controllers/concerns/snippets_actions.rb @@ -55,10 +55,9 @@ module SnippetsActions # rubocop:disable Gitlab/ModuleWithInstanceVariables def show - conditionally_expand_blob(blob) - respond_to do |format| format.html do + conditionally_expand_blob(blob) @note = Note.new(noteable: @snippet, project: @snippet.project) @noteable = @snippet @@ -68,11 +67,14 @@ module SnippetsActions end format.json do + conditionally_expand_blob(blob) render_blob_json(blob) end format.js do if @snippet.embeddable? + conditionally_expand_blobs(blobs) + render 'shared/snippets/show' else head :not_found @@ -109,13 +111,15 @@ module SnippetsActions # rubocop:disable Gitlab/ModuleWithInstanceVariables def blob - return unless snippet + @blob ||= blobs.first + end - @blob ||= if snippet.empty_repo? - snippet.blob - else - snippet.blobs.first - end + def blobs + @blobs ||= if snippet.empty_repo? + [snippet.blob] + else + snippet.blobs + end end # rubocop:enable Gitlab/ModuleWithInstanceVariables @@ -132,6 +136,8 @@ module SnippetsActions end def redirect_if_binary + return if Feature.enabled?(:snippets_binary_blob) + redirect_to gitlab_snippet_path(snippet) if blob&.binary? end end diff --git a/app/controllers/concerns/wiki_actions.rb b/app/controllers/concerns/wiki_actions.rb index a5182000f5b..5b953fe37d6 100644 --- a/app/controllers/concerns/wiki_actions.rb +++ b/app/controllers/concerns/wiki_actions.rb @@ -8,6 +8,8 @@ module WikiActions extend ActiveSupport::Concern included do + before_action { respond_to :html } + before_action :authorize_read_wiki! before_action :authorize_create_wiki!, only: [:edit, :create] before_action :authorize_admin_wiki!, only: :destroy @@ -65,6 +67,8 @@ module WikiActions @ref = params[:version_id] @path = page.path + Gitlab::UsageDataCounters::WikiPageCounter.count(:view) + render 'shared/wikis/show' elsif file_blob send_blob(wiki.repository, file_blob) @@ -107,14 +111,16 @@ module WikiActions # rubocop:disable Gitlab/ModuleWithInstanceVariables def create - @page = WikiPages::CreateService.new(container: container, current_user: current_user, params: wiki_params).execute + response = WikiPages::CreateService.new(container: container, current_user: current_user, params: wiki_params).execute + @page = response.payload[:page] - if page.persisted? + if response.success? redirect_to( wiki_page_path(wiki, page), notice: _('Wiki was successfully updated.') ) else + flash[:alert] = response.message render 'shared/wikis/edit' end rescue Gitlab::Git::Wiki::OperationError => e |