diff options
Diffstat (limited to 'app/controllers/concerns')
43 files changed, 128 insertions, 14 deletions
diff --git a/app/controllers/concerns/accepts_pending_invitations.rb b/app/controllers/concerns/accepts_pending_invitations.rb index 6e8aef52b52..cb66c1a055d 100644 --- a/app/controllers/concerns/accepts_pending_invitations.rb +++ b/app/controllers/concerns/accepts_pending_invitations.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module AcceptsPendingInvitations extend ActiveSupport::Concern diff --git a/app/controllers/concerns/authenticates_with_two_factor.rb b/app/controllers/concerns/authenticates_with_two_factor.rb index 961f121548b..5507328f8ae 100644 --- a/app/controllers/concerns/authenticates_with_two_factor.rb +++ b/app/controllers/concerns/authenticates_with_two_factor.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # == AuthenticatesWithTwoFactor # # Controller concern to handle two-factor authentication diff --git a/app/controllers/concerns/boards_responses.rb b/app/controllers/concerns/boards_responses.rb index da830ec2cb1..b7e4f9b81f1 100644 --- a/app/controllers/concerns/boards_responses.rb +++ b/app/controllers/concerns/boards_responses.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module BoardsResponses include Gitlab::Utils::StrongMemoize diff --git a/app/controllers/concerns/checks_collaboration.rb b/app/controllers/concerns/checks_collaboration.rb index 81367663a06..1fa82f7dcd4 100644 --- a/app/controllers/concerns/checks_collaboration.rb +++ b/app/controllers/concerns/checks_collaboration.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ChecksCollaboration def can_collaborate_with_project?(project, ref: nil) return true if can?(current_user, :push_code, project) diff --git a/app/controllers/concerns/continue_params.rb b/app/controllers/concerns/continue_params.rb index 8b7355974df..f0e6adf4dec 100644 --- a/app/controllers/concerns/continue_params.rb +++ b/app/controllers/concerns/continue_params.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ContinueParams include InternalRedirect extend ActiveSupport::Concern diff --git a/app/controllers/concerns/controller_with_cross_project_access_check.rb b/app/controllers/concerns/controller_with_cross_project_access_check.rb index a45c3384578..3f72f092683 100644 --- a/app/controllers/concerns/controller_with_cross_project_access_check.rb +++ b/app/controllers/concerns/controller_with_cross_project_access_check.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ControllerWithCrossProjectAccessCheck extend ActiveSupport::Concern diff --git a/app/controllers/concerns/creates_commit.rb b/app/controllers/concerns/creates_commit.rb index 709c8aaf337..b3777fd2b0f 100644 --- a/app/controllers/concerns/creates_commit.rb +++ b/app/controllers/concerns/creates_commit.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CreatesCommit extend ActiveSupport::Concern include Gitlab::Utils::StrongMemoize @@ -65,7 +67,7 @@ module CreatesCommit flash[:notice] = nil else target = different_project? ? "project" : "branch" - flash[:notice] << " You can now submit a merge request to get this change into the original #{target}." + flash[:notice] = flash[:notice] + " You can now submit a merge request to get this change into the original #{target}." end end end diff --git a/app/controllers/concerns/cycle_analytics_params.rb b/app/controllers/concerns/cycle_analytics_params.rb index 1ab107168c0..c1ef848e1e7 100644 --- a/app/controllers/concerns/cycle_analytics_params.rb +++ b/app/controllers/concerns/cycle_analytics_params.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CycleAnalyticsParams extend ActiveSupport::Concern diff --git a/app/controllers/concerns/diff_for_path.rb b/app/controllers/concerns/diff_for_path.rb index d5388c4cd20..6be7a2a18a2 100644 --- a/app/controllers/concerns/diff_for_path.rb +++ b/app/controllers/concerns/diff_for_path.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DiffForPath extend ActiveSupport::Concern diff --git a/app/controllers/concerns/enforces_two_factor_authentication.rb b/app/controllers/concerns/enforces_two_factor_authentication.rb index 69e5cbed343..71bdef8ce03 100644 --- a/app/controllers/concerns/enforces_two_factor_authentication.rb +++ b/app/controllers/concerns/enforces_two_factor_authentication.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # == EnforcesTwoFactorAuthentication # # Controller concern to enforce two-factor authentication requirements diff --git a/app/controllers/concerns/group_tree.rb b/app/controllers/concerns/group_tree.rb index c363cad0ffa..4f56346832c 100644 --- a/app/controllers/concerns/group_tree.rb +++ b/app/controllers/concerns/group_tree.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module GroupTree # rubocop:disable Gitlab/ModuleWithInstanceVariables # rubocop: disable CodeReuse/ActiveRecord diff --git a/app/controllers/concerns/hooks_execution.rb b/app/controllers/concerns/hooks_execution.rb index a22e46b4860..e8add1f4055 100644 --- a/app/controllers/concerns/hooks_execution.rb +++ b/app/controllers/concerns/hooks_execution.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module HooksExecution extend ActiveSupport::Concern diff --git a/app/controllers/concerns/internal_redirect.rb b/app/controllers/concerns/internal_redirect.rb index 10b9852e329..6785e6972d0 100644 --- a/app/controllers/concerns/internal_redirect.rb +++ b/app/controllers/concerns/internal_redirect.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module InternalRedirect extend ActiveSupport::Concern @@ -36,4 +38,10 @@ module InternalRedirect path_with_query = [uri.path, uri.query].compact.join('?') [path_with_query, uri.fragment].compact.join("#") end + + def referer_path(request) + return unless request.referer.presence + + URI(request.referer).path + end end diff --git a/app/controllers/concerns/issuable_actions.rb b/app/controllers/concerns/issuable_actions.rb index e723107bd7f..07e01e903ea 100644 --- a/app/controllers/concerns/issuable_actions.rb +++ b/app/controllers/concerns/issuable_actions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module IssuableActions extend ActiveSupport::Concern diff --git a/app/controllers/concerns/issuable_collections.rb b/app/controllers/concerns/issuable_collections.rb index d29154d5c60..5217b4be928 100644 --- a/app/controllers/concerns/issuable_collections.rb +++ b/app/controllers/concerns/issuable_collections.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module IssuableCollections extend ActiveSupport::Concern include CookiesHelper diff --git a/app/controllers/concerns/issues_action.rb b/app/controllers/concerns/issues_action.rb index 9d58656773d..a75590457d6 100644 --- a/app/controllers/concerns/issues_action.rb +++ b/app/controllers/concerns/issues_action.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module IssuesAction extend ActiveSupport::Concern include IssuableCollections diff --git a/app/controllers/concerns/issues_calendar.rb b/app/controllers/concerns/issues_calendar.rb index 76e1d1ff4e8..1fdfde4c869 100644 --- a/app/controllers/concerns/issues_calendar.rb +++ b/app/controllers/concerns/issues_calendar.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module IssuesCalendar extend ActiveSupport::Concern diff --git a/app/controllers/concerns/lfs_request.rb b/app/controllers/concerns/lfs_request.rb index 4584ff782a3..9576eb14fdd 100644 --- a/app/controllers/concerns/lfs_request.rb +++ b/app/controllers/concerns/lfs_request.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This concern assumes: # - a `#project` accessor # - a `#user` accessor diff --git a/app/controllers/concerns/members_presentation.rb b/app/controllers/concerns/members_presentation.rb index e146e7574aa..c6c3598a976 100644 --- a/app/controllers/concerns/members_presentation.rb +++ b/app/controllers/concerns/members_presentation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module MembersPresentation extend ActiveSupport::Concern diff --git a/app/controllers/concerns/membership_actions.rb b/app/controllers/concerns/membership_actions.rb index 94a352c0bcc..ca713192c9e 100644 --- a/app/controllers/concerns/membership_actions.rb +++ b/app/controllers/concerns/membership_actions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module MembershipActions include MembersPresentation extend ActiveSupport::Concern diff --git a/app/controllers/concerns/merge_requests_action.rb b/app/controllers/concerns/merge_requests_action.rb index b70db99b157..285f2c3a8a0 100644 --- a/app/controllers/concerns/merge_requests_action.rb +++ b/app/controllers/concerns/merge_requests_action.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module MergeRequestsAction extend ActiveSupport::Concern include IssuableCollections diff --git a/app/controllers/concerns/milestone_actions.rb b/app/controllers/concerns/milestone_actions.rb index d92cf8b4894..eccbe35577b 100644 --- a/app/controllers/concerns/milestone_actions.rb +++ b/app/controllers/concerns/milestone_actions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module MilestoneActions extend ActiveSupport::Concern diff --git a/app/controllers/concerns/notes_actions.rb b/app/controllers/concerns/notes_actions.rb index b63f2eb85f0..3a45d6205ab 100644 --- a/app/controllers/concerns/notes_actions.rb +++ b/app/controllers/concerns/notes_actions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module NotesActions include RendersNotes include Gitlab::Utils::StrongMemoize @@ -41,12 +43,26 @@ module NotesActions @note = Notes::CreateService.new(note_project, current_user, create_params).execute - if @note.is_a?(Note) - prepare_notes_for_rendering([@note], noteable) - end - respond_to do |format| - format.json { render json: note_json(@note) } + format.json do + json = { + commands_changes: @note.commands_changes + } + + if @note.persisted? && return_discussion? + json[:valid] = true + + discussion = @note.discussion + prepare_notes_for_rendering(discussion.notes) + json[:discussion] = discussion_serializer.represent(discussion, context: self) + else + prepare_notes_for_rendering([@note]) + + json.merge!(note_json(@note)) + end + + render json: json + end format.html { redirect_back_or_default } end end @@ -55,10 +71,7 @@ module NotesActions # rubocop:disable Gitlab/ModuleWithInstanceVariables def update @note = Notes::UpdateService.new(project, current_user, note_params).execute(note) - - if @note.is_a?(Note) - prepare_notes_for_rendering([@note]) - end + prepare_notes_for_rendering([@note]) respond_to do |format| format.json { render json: note_json(@note) } @@ -89,14 +102,17 @@ module NotesActions end def note_json(note) - attrs = { - commands_changes: note.commands_changes - } + attrs = {} if note.persisted? attrs[:valid] = true - if use_note_serializer? + if return_discussion? + discussion = note.discussion + prepare_notes_for_rendering(discussion.notes) + + attrs[:discussion] = discussion_serializer.represent(discussion, context: self) + elsif use_note_serializer? attrs.merge!(note_serializer.represent(note)) else attrs.merge!( @@ -216,6 +232,10 @@ module NotesActions ProjectNoteSerializer.new(project: project, noteable: noteable, current_user: current_user) end + def discussion_serializer + DiscussionSerializer.new(project: project, noteable: noteable, current_user: current_user, note_entity: ProjectNoteEntity) + end + def note_project strong_memoize(:note_project) do next nil unless project @@ -235,6 +255,10 @@ module NotesActions end end + def return_discussion? + Gitlab::Utils.to_boolean(params[:return_discussion]) + end + def use_note_serializer? return false if params['html'] diff --git a/app/controllers/concerns/oauth_applications.rb b/app/controllers/concerns/oauth_applications.rb index f0a68f23566..d97e22df472 100644 --- a/app/controllers/concerns/oauth_applications.rb +++ b/app/controllers/concerns/oauth_applications.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module OauthApplications extend ActiveSupport::Concern diff --git a/app/controllers/concerns/params_backward_compatibility.rb b/app/controllers/concerns/params_backward_compatibility.rb index b0e3d9c7b34..c972d6e3161 100644 --- a/app/controllers/concerns/params_backward_compatibility.rb +++ b/app/controllers/concerns/params_backward_compatibility.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ParamsBackwardCompatibility private diff --git a/app/controllers/concerns/preview_markdown.rb b/app/controllers/concerns/preview_markdown.rb index 99123fcb3b0..c61b9fabe9e 100644 --- a/app/controllers/concerns/preview_markdown.rb +++ b/app/controllers/concerns/preview_markdown.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module PreviewMarkdown extend ActiveSupport::Concern diff --git a/app/controllers/concerns/renders_blob.rb b/app/controllers/concerns/renders_blob.rb index ba7adcfea86..b8026c7a01d 100644 --- a/app/controllers/concerns/renders_blob.rb +++ b/app/controllers/concerns/renders_blob.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module RendersBlob extend ActiveSupport::Concern diff --git a/app/controllers/concerns/renders_commits.rb b/app/controllers/concerns/renders_commits.rb index b1c9b1e532f..f48e0586211 100644 --- a/app/controllers/concerns/renders_commits.rb +++ b/app/controllers/concerns/renders_commits.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module RendersCommits def limited_commits(commits) if commits.size > MergeRequestDiff::COMMITS_SAFE_SIZE diff --git a/app/controllers/concerns/renders_member_access.rb b/app/controllers/concerns/renders_member_access.rb index c5b77dacb26..955ac1a1bc8 100644 --- a/app/controllers/concerns/renders_member_access.rb +++ b/app/controllers/concerns/renders_member_access.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module RendersMemberAccess def prepare_groups_for_rendering(groups) preload_max_member_access_for_collection(Group, groups) diff --git a/app/controllers/concerns/renders_notes.rb b/app/controllers/concerns/renders_notes.rb index c5f23e33424..ce36da6b715 100644 --- a/app/controllers/concerns/renders_notes.rb +++ b/app/controllers/concerns/renders_notes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module RendersNotes # rubocop:disable Gitlab/ModuleWithInstanceVariables def prepare_notes_for_rendering(notes, noteable = nil) diff --git a/app/controllers/concerns/repository_settings_redirect.rb b/app/controllers/concerns/repository_settings_redirect.rb index f3db3cd563b..0f18735c29e 100644 --- a/app/controllers/concerns/repository_settings_redirect.rb +++ b/app/controllers/concerns/repository_settings_redirect.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module RepositorySettingsRedirect extend ActiveSupport::Concern diff --git a/app/controllers/concerns/requires_whitelisted_monitoring_client.rb b/app/controllers/concerns/requires_whitelisted_monitoring_client.rb index 88d1b34bb06..426f224d26b 100644 --- a/app/controllers/concerns/requires_whitelisted_monitoring_client.rb +++ b/app/controllers/concerns/requires_whitelisted_monitoring_client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module RequiresWhitelistedMonitoringClient extend ActiveSupport::Concern diff --git a/app/controllers/concerns/routable_actions.rb b/app/controllers/concerns/routable_actions.rb index 0931bdf4c04..88939b002b2 100644 --- a/app/controllers/concerns/routable_actions.rb +++ b/app/controllers/concerns/routable_actions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module RoutableActions extend ActiveSupport::Concern diff --git a/app/controllers/concerns/send_file_upload.rb b/app/controllers/concerns/send_file_upload.rb index 382ec91f771..0bb7b7efed0 100644 --- a/app/controllers/concerns/send_file_upload.rb +++ b/app/controllers/concerns/send_file_upload.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SendFileUpload def send_upload(file_upload, send_params: {}, redirect_params: {}, attachment: nil, disposition: 'attachment') if attachment diff --git a/app/controllers/concerns/service_params.rb b/app/controllers/concerns/service_params.rb index c1acb50b76c..8bd93a349ef 100644 --- a/app/controllers/concerns/service_params.rb +++ b/app/controllers/concerns/service_params.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ServiceParams extend ActiveSupport::Concern diff --git a/app/controllers/concerns/snippets_actions.rb b/app/controllers/concerns/snippets_actions.rb index 120614739aa..8c22490700c 100644 --- a/app/controllers/concerns/snippets_actions.rb +++ b/app/controllers/concerns/snippets_actions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SnippetsActions extend ActiveSupport::Concern diff --git a/app/controllers/concerns/spammable_actions.rb b/app/controllers/concerns/spammable_actions.rb index 922aa58a00f..c3a1b12af84 100644 --- a/app/controllers/concerns/spammable_actions.rb +++ b/app/controllers/concerns/spammable_actions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SpammableActions extend ActiveSupport::Concern diff --git a/app/controllers/concerns/todos_actions.rb b/app/controllers/concerns/todos_actions.rb index c0acdb3498d..78b65f7961b 100644 --- a/app/controllers/concerns/todos_actions.rb +++ b/app/controllers/concerns/todos_actions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module TodosActions extend ActiveSupport::Concern diff --git a/app/controllers/concerns/toggle_award_emoji.rb b/app/controllers/concerns/toggle_award_emoji.rb index ae0b815f85e..97b343f8b1a 100644 --- a/app/controllers/concerns/toggle_award_emoji.rb +++ b/app/controllers/concerns/toggle_award_emoji.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ToggleAwardEmoji extend ActiveSupport::Concern diff --git a/app/controllers/concerns/toggle_subscription_action.rb b/app/controllers/concerns/toggle_subscription_action.rb index 776583579e8..e613bfaeef2 100644 --- a/app/controllers/concerns/toggle_subscription_action.rb +++ b/app/controllers/concerns/toggle_subscription_action.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ToggleSubscriptionAction extend ActiveSupport::Concern diff --git a/app/controllers/concerns/uploads_actions.rb b/app/controllers/concerns/uploads_actions.rb index 56772df21d7..7a1c7abfb8f 100644 --- a/app/controllers/concerns/uploads_actions.rb +++ b/app/controllers/concerns/uploads_actions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module UploadsActions extend ActiveSupport::Concern diff --git a/app/controllers/concerns/with_performance_bar.rb b/app/controllers/concerns/with_performance_bar.rb index 6a8b1a4de7b..c12839c7bbd 100644 --- a/app/controllers/concerns/with_performance_bar.rb +++ b/app/controllers/concerns/with_performance_bar.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module WithPerformanceBar extend ActiveSupport::Concern diff --git a/app/controllers/concerns/workhorse_request.rb b/app/controllers/concerns/workhorse_request.rb index 43c0f1b173c..028f10e866a 100644 --- a/app/controllers/concerns/workhorse_request.rb +++ b/app/controllers/concerns/workhorse_request.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module WorkhorseRequest extend ActiveSupport::Concern |