diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/concerns/sends_blob.rb | 14 | ||||
-rw-r--r-- | app/controllers/concerns/snippets_actions.rb | 31 | ||||
-rw-r--r-- | app/controllers/projects/avatars_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/projects/import/jira_controller.rb | 20 | ||||
-rw-r--r-- | app/controllers/projects/raw_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/projects/wikis_controller.rb | 2 |
6 files changed, 35 insertions, 36 deletions
diff --git a/app/controllers/concerns/sends_blob.rb b/app/controllers/concerns/sends_blob.rb index 8ecdaced9f5..9bba61fda84 100644 --- a/app/controllers/concerns/sends_blob.rb +++ b/app/controllers/concerns/sends_blob.rb @@ -8,16 +8,16 @@ module SendsBlob include SendFileUpload end - def send_blob(repository, blob, params = {}) + def send_blob(repository, blob, inline: true, allow_caching: false) if blob headers['X-Content-Type-Options'] = 'nosniff' - return if cached_blob?(blob) + return if cached_blob?(blob, allow_caching: allow_caching) if blob.stored_externally? - send_lfs_object(blob) + send_lfs_object(blob, repository.project) else - send_git_blob(repository, blob, params) + send_git_blob(repository, blob, inline: inline) end else render_404 @@ -26,11 +26,11 @@ module SendsBlob private - def cached_blob?(blob) + def cached_blob?(blob, allow_caching: false) stale = stale?(etag: blob.id) # The #stale? method sets cache headers. # Because we are opinionated we set the cache headers ourselves. - response.cache_control[:public] = project.public? + response.cache_control[:public] = allow_caching response.cache_control[:max_age] = if @ref && @commit && @ref == @commit.id # rubocop:disable Gitlab/ModuleWithInstanceVariables @@ -48,7 +48,7 @@ module SendsBlob !stale end - def send_lfs_object(blob) + def send_lfs_object(blob, project) lfs_object = find_lfs_object(blob) if lfs_object && lfs_object.project_allowed_access?(project) diff --git a/app/controllers/concerns/snippets_actions.rb b/app/controllers/concerns/snippets_actions.rb index 749afb71923..b12aee346ed 100644 --- a/app/controllers/concerns/snippets_actions.rb +++ b/app/controllers/concerns/snippets_actions.rb @@ -2,6 +2,7 @@ module SnippetsActions extend ActiveSupport::Concern + include SendsBlob def edit # We need to load some info from the existing blob @@ -12,16 +13,26 @@ module SnippetsActions end def raw - disposition = params[:inline] == 'false' ? 'attachment' : 'inline' - workhorse_set_content_type! - send_data( - convert_line_endings(blob.data), - type: 'text/plain; charset=utf-8', - disposition: disposition, - filename: Snippet.sanitized_file_name(blob.name) - ) + # Until we don't migrate all snippets to version + # snippets we need to support old `SnippetBlob` + # blobs + if defined?(blob.snippet) + send_data( + convert_line_endings(blob.data), + type: 'text/plain; charset=utf-8', + disposition: content_disposition, + filename: Snippet.sanitized_file_name(blob.name) + ) + else + send_blob( + snippet.repository, + blob, + inline: content_disposition == 'inline', + allow_caching: snippet.public? + ) + end end def js_request? @@ -30,6 +41,10 @@ module SnippetsActions private + def content_disposition + @disposition ||= params[:inline] == 'false' ? 'attachment' : 'inline' + end + # rubocop:disable Gitlab/ModuleWithInstanceVariables def blob return unless snippet diff --git a/app/controllers/projects/avatars_controller.rb b/app/controllers/projects/avatars_controller.rb index 1f4a25f82e9..6e6bf09a32a 100644 --- a/app/controllers/projects/avatars_controller.rb +++ b/app/controllers/projects/avatars_controller.rb @@ -8,7 +8,7 @@ class Projects::AvatarsController < Projects::ApplicationController def show @blob = @repository.blob_at_branch(@repository.root_ref, @project.avatar_in_git) - send_blob(@repository, @blob) + send_blob(@repository, @blob, allow_caching: @project.public?) end def destroy diff --git a/app/controllers/projects/import/jira_controller.rb b/app/controllers/projects/import/jira_controller.rb index d38d9e27347..e88d28e9db4 100644 --- a/app/controllers/projects/import/jira_controller.rb +++ b/app/controllers/projects/import/jira_controller.rb @@ -16,9 +16,8 @@ module Projects end def import - import_state = @project.import_state || @project.create_import_state - - schedule_import(jira_import_params) unless import_state.in_progress? + response = ::JiraImport::StartImportService.new(current_user, @project, jira_import_params[:jira_project_key]).execute + flash[:notice] = response.message if response.message.present? redirect_to project_import_jira_path(@project) end @@ -39,21 +38,6 @@ module Projects redirect_to project_issues_path(@project) end - def schedule_import(params) - import_data = @project.create_or_update_import_data(data: {}).becomes(JiraImportData) - - jira_project_details = JiraImportData::JiraProjectDetails.new( - params[:jira_project_key], - Time.now.strftime('%Y-%m-%d %H:%M:%S'), - { user_id: current_user.id, name: current_user.name } - ) - import_data << jira_project_details - import_data.force_import! - - @project.import_type = 'jira' - @project.import_state.schedule if @project.save - end - def jira_import_params params.permit(:jira_project_key) end diff --git a/app/controllers/projects/raw_controller.rb b/app/controllers/projects/raw_controller.rb index f7bc6898112..69a3898af55 100644 --- a/app/controllers/projects/raw_controller.rb +++ b/app/controllers/projects/raw_controller.rb @@ -17,7 +17,7 @@ class Projects::RawController < Projects::ApplicationController def show @blob = @repository.blob_at(@commit.id, @path) - send_blob(@repository, @blob, inline: (params[:inline] != 'false')) + send_blob(@repository, @blob, inline: (params[:inline] != 'false'), allow_caching: @project.public?) end private diff --git a/app/controllers/projects/wikis_controller.rb b/app/controllers/projects/wikis_controller.rb index cfc0925d9e1..90ff798077a 100644 --- a/app/controllers/projects/wikis_controller.rb +++ b/app/controllers/projects/wikis_controller.rb @@ -45,7 +45,7 @@ class Projects::WikisController < Projects::ApplicationController render 'show' elsif file_blob - send_blob(@project_wiki.repository, file_blob) + send_blob(@project_wiki.repository, file_blob, allow_caching: @project.public?) elsif show_create_form? # Assign a title to the WikiPage unless `id` is a randomly generated slug from #new title = params[:id] unless params[:random_title].present? |