From 3b874414c06156767117b7aa7ae705c7342d887c Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 5 Sep 2017 12:27:40 +0200 Subject: Do not use artifacts metadata to access single artifact --- app/controllers/projects/artifacts_controller.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/projects/artifacts_controller.rb b/app/controllers/projects/artifacts_controller.rb index f637a9a803b..eb010923466 100644 --- a/app/controllers/projects/artifacts_controller.rb +++ b/app/controllers/projects/artifacts_controller.rb @@ -7,7 +7,7 @@ class Projects::ArtifactsController < Projects::ApplicationController before_action :authorize_update_build!, only: [:keep] before_action :extract_ref_name_and_path before_action :validate_artifacts! - before_action :set_path_and_entry, only: [:file, :raw] + before_action :entry, only: [:file] def download if artifacts_file.file_storage? @@ -41,7 +41,10 @@ class Projects::ArtifactsController < Projects::ApplicationController end def raw - send_artifacts_entry(build, @entry) + path = Gitlab::Ci::Build::Artifacts::Path + .new(params[:path]) + + send_artifacts_entry(build, path) end def keep @@ -93,9 +96,8 @@ class Projects::ArtifactsController < Projects::ApplicationController @artifacts_file ||= build.artifacts_file end - def set_path_and_entry - @path = params[:path] - @entry = build.artifacts_metadata_entry(@path) + def entry + @entry = build.artifacts_metadata_entry(params[:path]) render_404 unless @entry.exists? end -- cgit v1.2.1 From 966b1128d884a318dad4277e23368334fe67e836 Mon Sep 17 00:00:00 2001 From: "micael.bergeron" Date: Sat, 29 Jul 2017 11:04:42 -0400 Subject: WIP: refactor the first-contributor to Issuable this will remove the need make N queries (per-note) at the cost of having to mark notes with an attribute this opens up the possibility for other special roles for notes --- app/controllers/concerns/renders_notes.rb | 9 ++++++++- app/controllers/projects/commit_controller.rb | 2 +- app/controllers/projects/issues_controller.rb | 2 +- app/controllers/projects/merge_requests/diffs_controller.rb | 2 +- app/controllers/projects/merge_requests_controller.rb | 6 +++--- app/controllers/projects/snippets_controller.rb | 2 +- app/controllers/snippets_controller.rb | 2 +- 7 files changed, 16 insertions(+), 9 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/concerns/renders_notes.rb b/app/controllers/concerns/renders_notes.rb index 41c3114ad1e..cdcfefd90c9 100644 --- a/app/controllers/concerns/renders_notes.rb +++ b/app/controllers/concerns/renders_notes.rb @@ -1,7 +1,8 @@ module RendersNotes - def prepare_notes_for_rendering(notes) + def prepare_notes_for_rendering(notes, noteable=nil) preload_noteable_for_regular_notes(notes) preload_max_access_for_authors(notes, @project) + preload_first_time_contribution_for_authors(noteable, notes) if noteable.is_a?(Issuable) Banzai::NoteRenderer.render(notes, @project, current_user) notes @@ -19,4 +20,10 @@ module RendersNotes def preload_noteable_for_regular_notes(notes) ActiveRecord::Associations::Preloader.new.preload(notes.reject(&:for_commit?), :noteable) end + + def preload_first_time_contribution_for_authors(issuable, notes) + return unless issuable.first_contribution? + same_author = lambda {|n| n.author_id == issuable.author_id} + notes.select(&same_author).each {|note| note.special_role = :first_time_contributor} + end end diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index 6de125e7e80..1a775def506 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -127,7 +127,7 @@ class Projects::CommitController < Projects::ApplicationController @discussions = commit.discussions @notes = (@grouped_diff_discussions.values.flatten + @discussions).flat_map(&:notes) - @notes = prepare_notes_for_rendering(@notes) + @notes = prepare_notes_for_rendering(@notes, @commit) end def assign_change_commit_vars diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb index dc9e6f71152..ab9f132b502 100644 --- a/app/controllers/projects/issues_controller.rb +++ b/app/controllers/projects/issues_controller.rb @@ -85,7 +85,7 @@ class Projects::IssuesController < Projects::ApplicationController @note = @project.notes.new(noteable: @issue) @discussions = @issue.discussions - @notes = prepare_notes_for_rendering(@discussions.flat_map(&:notes)) + @notes = prepare_notes_for_rendering(@discussions.flat_map(&:notes), @noteable) respond_to do |format| format.html diff --git a/app/controllers/projects/merge_requests/diffs_controller.rb b/app/controllers/projects/merge_requests/diffs_controller.rb index 330b7df4541..109418c73f7 100644 --- a/app/controllers/projects/merge_requests/diffs_controller.rb +++ b/app/controllers/projects/merge_requests/diffs_controller.rb @@ -61,6 +61,6 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic @use_legacy_diff_notes = !@merge_request.has_complete_diff_refs? @grouped_diff_discussions = @merge_request.grouped_diff_discussions(@compare.diff_refs) - @notes = prepare_notes_for_rendering(@grouped_diff_discussions.values.flatten.flat_map(&:notes)) + @notes = prepare_notes_for_rendering(@grouped_diff_discussions.values.flatten.flat_map(&:notes), @merge_request) end end diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 5095d7fd445..6c4a783e11a 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -60,12 +60,12 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo # Build a note object for comment form @note = @project.notes.new(noteable: @merge_request) - @discussions = @merge_request.discussions - @notes = prepare_notes_for_rendering(@discussions.flat_map(&:notes)) - @noteable = @merge_request @commits_count = @merge_request.commits_count + @discussions = @merge_request.discussions + @notes = prepare_notes_for_rendering(@discussions.flat_map(&:notes), @noteable) + labels set_pipeline_variables diff --git a/app/controllers/projects/snippets_controller.rb b/app/controllers/projects/snippets_controller.rb index d07143d294f..7c19aa7bb23 100644 --- a/app/controllers/projects/snippets_controller.rb +++ b/app/controllers/projects/snippets_controller.rb @@ -64,7 +64,7 @@ class Projects::SnippetsController < Projects::ApplicationController @noteable = @snippet @discussions = @snippet.discussions - @notes = prepare_notes_for_rendering(@discussions.flat_map(&:notes)) + @notes = prepare_notes_for_rendering(@discussions.flat_map(&:notes), @noteable) render 'show' end diff --git a/app/controllers/snippets_controller.rb b/app/controllers/snippets_controller.rb index 8c3abd0a085..c1cdc7c9831 100644 --- a/app/controllers/snippets_controller.rb +++ b/app/controllers/snippets_controller.rb @@ -66,7 +66,7 @@ class SnippetsController < ApplicationController @noteable = @snippet @discussions = @snippet.discussions - @notes = prepare_notes_for_rendering(@discussions.flat_map(&:notes)) + @notes = prepare_notes_for_rendering(@discussions.flat_map(&:notes), @noteable) respond_to do |format| format.html do -- cgit v1.2.1 From 45b83ed99afc5cfe24a8d84869894124d93d5b51 Mon Sep 17 00:00:00 2001 From: "micael.bergeron" Date: Wed, 2 Aug 2017 10:06:28 -0400 Subject: round of fixes after code review --- app/controllers/concerns/renders_notes.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/concerns/renders_notes.rb b/app/controllers/concerns/renders_notes.rb index cdcfefd90c9..b6cf366c05c 100644 --- a/app/controllers/concerns/renders_notes.rb +++ b/app/controllers/concerns/renders_notes.rb @@ -1,5 +1,5 @@ module RendersNotes - def prepare_notes_for_rendering(notes, noteable=nil) + def prepare_notes_for_rendering(notes, noteable = nil) preload_noteable_for_regular_notes(notes) preload_max_access_for_authors(notes, @project) preload_first_time_contribution_for_authors(noteable, notes) if noteable.is_a?(Issuable) @@ -23,7 +23,10 @@ module RendersNotes def preload_first_time_contribution_for_authors(issuable, notes) return unless issuable.first_contribution? + same_author = lambda {|n| n.author_id == issuable.author_id} - notes.select(&same_author).each {|note| note.special_role = :first_time_contributor} + notes.each do |note| + note.specialize!(Note::SpecialRole::FIRST_TIME_CONTRIBUTOR, &same_author) + end end end -- cgit v1.2.1 From b44a1bcd0b94a68f680c24d0dfd6d3402af9a881 Mon Sep 17 00:00:00 2001 From: "micael.bergeron" Date: Tue, 15 Aug 2017 09:21:27 -0400 Subject: rework the contributor badge - only show in merge-requests - show as a little glyph --- app/controllers/concerns/renders_notes.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/concerns/renders_notes.rb b/app/controllers/concerns/renders_notes.rb index b6cf366c05c..4791bc561a4 100644 --- a/app/controllers/concerns/renders_notes.rb +++ b/app/controllers/concerns/renders_notes.rb @@ -2,7 +2,7 @@ module RendersNotes def prepare_notes_for_rendering(notes, noteable = nil) preload_noteable_for_regular_notes(notes) preload_max_access_for_authors(notes, @project) - preload_first_time_contribution_for_authors(noteable, notes) if noteable.is_a?(Issuable) + preload_first_time_contribution_for_authors(noteable, notes) Banzai::NoteRenderer.render(notes, @project, current_user) notes @@ -21,12 +21,9 @@ module RendersNotes ActiveRecord::Associations::Preloader.new.preload(notes.reject(&:for_commit?), :noteable) end - def preload_first_time_contribution_for_authors(issuable, notes) - return unless issuable.first_contribution? + def preload_first_time_contribution_for_authors(noteable, notes) + return unless noteable.is_a?(Issuable) && noteable.first_contribution? - same_author = lambda {|n| n.author_id == issuable.author_id} - notes.each do |note| - note.specialize!(Note::SpecialRole::FIRST_TIME_CONTRIBUTOR, &same_author) - end + notes.each {|n| n.specialize_for_first_contribution!(noteable)} end end -- cgit v1.2.1 From ddf892b9f26138c0fd43bbfa3b5d602ed954f59b Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Wed, 6 Sep 2017 15:05:35 +0200 Subject: Put loggers in before_action for easier overriding in EE Make it easier to override the set of loggers, by putting them in a separate method. Also modify spec so it tests for links, instead of checking for regular text. --- app/controllers/admin/logs_controller.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'app/controllers') diff --git a/app/controllers/admin/logs_controller.rb b/app/controllers/admin/logs_controller.rb index bdc4332ae69..12a27cede75 100644 --- a/app/controllers/admin/logs_controller.rb +++ b/app/controllers/admin/logs_controller.rb @@ -1,6 +1,13 @@ class Admin::LogsController < Admin::ApplicationController + before_action :loggers + def show - @loggers = [ + end + + private + + def loggers + @loggers ||= [ Gitlab::AppLogger, Gitlab::GitLogger, Gitlab::EnvironmentLogger, -- cgit v1.2.1 From dd7434e398d26e5f4c92f73dce4bcf9b7e47e193 Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Wed, 23 Aug 2017 12:10:36 +0100 Subject: Adds CommitDescriptionRenderer --- app/controllers/concerns/renders_commit_description.rb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 app/controllers/concerns/renders_commit_description.rb (limited to 'app/controllers') diff --git a/app/controllers/concerns/renders_commit_description.rb b/app/controllers/concerns/renders_commit_description.rb new file mode 100644 index 00000000000..ada80eda230 --- /dev/null +++ b/app/controllers/concerns/renders_commit_description.rb @@ -0,0 +1,7 @@ +module RendersCommitDescription + def prepare_commit_descriptions_for_rendering(commit_descriptions) + Banzai::CommitDescriptionRenderer.render(commit_descriptions, @project, current_user) + + commit_descriptions + end +end -- cgit v1.2.1 From 4df54f260751a832ebf0b8c18524020d6604994b Mon Sep 17 00:00:00 2001 From: Alexander Keramidas Date: Tue, 29 Aug 2017 11:57:41 +0300 Subject: Profile updates from providers --- app/controllers/profiles_controller.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index 076076fd1b3..d83824fef06 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -9,8 +9,6 @@ class ProfilesController < Profiles::ApplicationController end def update - user_params.except!(:email) if @user.external_email? - respond_to do |format| result = Users::UpdateService.new(@user, user_params).execute -- cgit v1.2.1 From 6d8e102c740b75ac9e1d168a84f532f6d9ebaa65 Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Wed, 23 Aug 2017 17:53:29 +0100 Subject: Adds cacheless render to Banzai object render --- app/controllers/concerns/renders_commit_description.rb | 7 ------- app/controllers/concerns/renders_commits.rb | 7 +++++++ app/controllers/projects/commits_controller.rb | 3 +++ app/controllers/projects/compare_controller.rb | 3 ++- app/controllers/projects/merge_requests/creations_controller.rb | 3 ++- app/controllers/projects/merge_requests_controller.rb | 3 ++- app/controllers/search_controller.rb | 7 +++++++ 7 files changed, 23 insertions(+), 10 deletions(-) delete mode 100644 app/controllers/concerns/renders_commit_description.rb create mode 100644 app/controllers/concerns/renders_commits.rb (limited to 'app/controllers') diff --git a/app/controllers/concerns/renders_commit_description.rb b/app/controllers/concerns/renders_commit_description.rb deleted file mode 100644 index ada80eda230..00000000000 --- a/app/controllers/concerns/renders_commit_description.rb +++ /dev/null @@ -1,7 +0,0 @@ -module RendersCommitDescription - def prepare_commit_descriptions_for_rendering(commit_descriptions) - Banzai::CommitDescriptionRenderer.render(commit_descriptions, @project, current_user) - - commit_descriptions - end -end diff --git a/app/controllers/concerns/renders_commits.rb b/app/controllers/concerns/renders_commits.rb new file mode 100644 index 00000000000..bb2c1dfa00a --- /dev/null +++ b/app/controllers/concerns/renders_commits.rb @@ -0,0 +1,7 @@ +module RendersCommits + def prepare_commits_for_rendering(commits) + Banzai::CommitRenderer.render(commits, @project, current_user) + + commits + end +end diff --git a/app/controllers/projects/commits_controller.rb b/app/controllers/projects/commits_controller.rb index 2de9900d449..4a841bf2073 100644 --- a/app/controllers/projects/commits_controller.rb +++ b/app/controllers/projects/commits_controller.rb @@ -2,6 +2,7 @@ require "base64" class Projects::CommitsController < Projects::ApplicationController include ExtractsPath + include RendersCommits before_action :require_non_empty_project before_action :assign_ref_vars @@ -56,5 +57,7 @@ class Projects::CommitsController < Projects::ApplicationController else @repository.commits(@ref, path: @path, limit: @limit, offset: @offset) end + + @commits = prepare_commits_for_rendering(@commits) end end diff --git a/app/controllers/projects/compare_controller.rb b/app/controllers/projects/compare_controller.rb index c8613c0d634..193549663ac 100644 --- a/app/controllers/projects/compare_controller.rb +++ b/app/controllers/projects/compare_controller.rb @@ -3,6 +3,7 @@ require 'addressable/uri' class Projects::CompareController < Projects::ApplicationController include DiffForPath include DiffHelper + include RendersCommits # Authorize before_action :require_non_empty_project @@ -50,7 +51,7 @@ class Projects::CompareController < Projects::ApplicationController .execute(@project, @start_ref) if @compare - @commits = @compare.commits + @commits = prepare_commits_for_rendering(@compare.commits) @diffs = @compare.diffs(diff_options) environment_params = @repository.branch_exists?(@head_ref) ? { ref: @head_ref } : { commit: @compare.commit } diff --git a/app/controllers/projects/merge_requests/creations_controller.rb b/app/controllers/projects/merge_requests/creations_controller.rb index f35d53896ba..1096afbb798 100644 --- a/app/controllers/projects/merge_requests/creations_controller.rb +++ b/app/controllers/projects/merge_requests/creations_controller.rb @@ -1,6 +1,7 @@ class Projects::MergeRequests::CreationsController < Projects::MergeRequests::ApplicationController include DiffForPath include DiffHelper + include RendersCommits skip_before_action :merge_request skip_before_action :ensure_ref_fetched @@ -107,7 +108,7 @@ class Projects::MergeRequests::CreationsController < Projects::MergeRequests::Ap @target_project = @merge_request.target_project @source_project = @merge_request.source_project - @commits = @merge_request.commits + @commits = prepare_commits_for_rendering(@merge_request.commits) @commit = @merge_request.diff_head_commit @note_counts = Note.where(commit_id: @commits.map(&:id)) diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 5095d7fd445..dc7a94d824a 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -2,6 +2,7 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo include ToggleSubscriptionAction include IssuableActions include RendersNotes + include RendersCommits include ToggleAwardEmoji include IssuableCollections @@ -94,7 +95,7 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo def commits # Get commits from repository # or from cache if already merged - @commits = @merge_request.commits + @commits = prepare_commits_for_rendering(@merge_request.commits) @note_counts = Note.where(commit_id: @commits.map(&:id)) .group(:commit_id).count diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index d58c8d14a75..fbad9ba7db8 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -2,6 +2,7 @@ class SearchController < ApplicationController skip_before_action :authenticate_user! include SearchHelper + include RendersCommits layout 'search' @@ -20,6 +21,8 @@ class SearchController < ApplicationController @search_results = search_service.search_results @search_objects = search_service.search_objects + render_commits if @scope == 'commits' + check_single_commit_result end @@ -38,6 +41,10 @@ class SearchController < ApplicationController private + def render_commits + @search_objects = prepare_commits_for_rendering(@search_objects) + end + def check_single_commit_result if @search_results.single_commit_result? only_commit = @search_results.objects('commits').first -- cgit v1.2.1