summaryrefslogtreecommitdiff
path: root/app/controllers/concerns
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 10:34:06 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 10:34:06 +0000
commit859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch)
treed7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /app/controllers/concerns
parent446d496a6d000c73a304be52587cd9bbc7493136 (diff)
downloadgitlab-ce-859a6fb938bb9ee2a317c46dfa4fcc1af49608f0.tar.gz
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'app/controllers/concerns')
-rw-r--r--app/controllers/concerns/boards_actions.rb14
-rw-r--r--app/controllers/concerns/boards_responses.rb6
-rw-r--r--app/controllers/concerns/comment_and_close_flag.rb11
-rw-r--r--app/controllers/concerns/integrations_actions.rb4
-rw-r--r--app/controllers/concerns/membership_actions.rb24
-rw-r--r--app/controllers/concerns/multiple_boards_actions.rb1
-rw-r--r--app/controllers/concerns/notes_actions.rb9
-rw-r--r--app/controllers/concerns/redis_tracking.rb16
-rw-r--r--app/controllers/concerns/service_params.rb1
-rw-r--r--app/controllers/concerns/snippets_actions.rb2
-rw-r--r--app/controllers/concerns/spammable_actions.rb57
-rw-r--r--app/controllers/concerns/wiki_actions.rb3
12 files changed, 76 insertions, 72 deletions
diff --git a/app/controllers/concerns/boards_actions.rb b/app/controllers/concerns/boards_actions.rb
index b382e338a78..79e6f027c2f 100644
--- a/app/controllers/concerns/boards_actions.rb
+++ b/app/controllers/concerns/boards_actions.rb
@@ -34,16 +34,26 @@ module BoardsActions
def boards
strong_memoize(:boards) do
- Boards::ListService.new(parent, current_user).execute
+ existing_boards = boards_finder.execute
+ if existing_boards.any?
+ existing_boards
+ else
+ # if no board exists, create one
+ [board_create_service.execute.payload]
+ end
end
end
def board
strong_memoize(:board) do
- boards.find(params[:id])
+ board_finder.execute.first
end
end
+ def board_type
+ board_klass.to_type
+ end
+
def serializer
BoardSerializer.new(current_user: current_user)
end
diff --git a/app/controllers/concerns/boards_responses.rb b/app/controllers/concerns/boards_responses.rb
index d8bc1320db4..6e6686f225c 100644
--- a/app/controllers/concerns/boards_responses.rb
+++ b/app/controllers/concerns/boards_responses.rb
@@ -66,7 +66,11 @@ module BoardsResponses
end
def respond_with_board
- respond_with(@board) # rubocop:disable Gitlab/ModuleWithInstanceVariables
+ # rubocop:disable Gitlab/ModuleWithInstanceVariables
+ return render_404 unless @board
+
+ respond_with(@board)
+ # rubocop:enable Gitlab/ModuleWithInstanceVariables
end
def serialize_as_json(resource)
diff --git a/app/controllers/concerns/comment_and_close_flag.rb b/app/controllers/concerns/comment_and_close_flag.rb
new file mode 100644
index 00000000000..e2f3272abbc
--- /dev/null
+++ b/app/controllers/concerns/comment_and_close_flag.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+module CommentAndCloseFlag
+ extend ActiveSupport::Concern
+
+ included do
+ before_action do
+ push_frontend_feature_flag(:remove_comment_close_reopen, @group)
+ end
+ end
+end
diff --git a/app/controllers/concerns/integrations_actions.rb b/app/controllers/concerns/integrations_actions.rb
index baebedb8e5d..a3ea39d9c3d 100644
--- a/app/controllers/concerns/integrations_actions.rb
+++ b/app/controllers/concerns/integrations_actions.rb
@@ -34,10 +34,6 @@ module IntegrationsActions
end
end
- def custom_integration_projects
- Project.with_custom_integration_compared_to(integration).page(params[:page]).per(20)
- end
-
def test
render json: {}, status: :ok
end
diff --git a/app/controllers/concerns/membership_actions.rb b/app/controllers/concerns/membership_actions.rb
index 816a93f14c6..9e3625d1b36 100644
--- a/app/controllers/concerns/membership_actions.rb
+++ b/app/controllers/concerns/membership_actions.rb
@@ -18,18 +18,26 @@ module MembershipActions
def update
update_params = params.require(root_params_key).permit(:access_level, :expires_at)
member = membershipable.members_and_requesters.find(params[:id])
- member = Members::UpdateService
+ result = Members::UpdateService
.new(current_user, update_params)
.execute(member)
- if member.expires?
- render json: {
- expires_in: helpers.distance_of_time_in_words_to_now(member.expires_at),
- expires_soon: member.expires_soon?,
- expires_at_formatted: member.expires_at.to_time.in_time_zone.to_s(:medium)
- }
+ member = result[:member]
+
+ member_data = if member.expires?
+ {
+ expires_in: helpers.distance_of_time_in_words_to_now(member.expires_at),
+ expires_soon: member.expires_soon?,
+ expires_at_formatted: member.expires_at.to_time.in_time_zone.to_s(:medium)
+ }
+ else
+ {}
+ end
+
+ if result[:status] == :success
+ render json: member_data
else
- render json: {}
+ render json: { message: result[:message] }, status: :unprocessable_entity
end
end
diff --git a/app/controllers/concerns/multiple_boards_actions.rb b/app/controllers/concerns/multiple_boards_actions.rb
index 370b8c72bfe..5206f5759d8 100644
--- a/app/controllers/concerns/multiple_boards_actions.rb
+++ b/app/controllers/concerns/multiple_boards_actions.rb
@@ -65,6 +65,7 @@ module MultipleBoardsActions
private
def redirect_to_recent_board
+ return unless board_type == Board.to_type
return if request.format.json? || !parent.multiple_issue_boards_available? || !latest_visited_board
redirect_to board_path(latest_visited_board.board)
diff --git a/app/controllers/concerns/notes_actions.rb b/app/controllers/concerns/notes_actions.rb
index bfa7a30bc65..036d95622ef 100644
--- a/app/controllers/concerns/notes_actions.rb
+++ b/app/controllers/concerns/notes_actions.rb
@@ -31,9 +31,9 @@ module NotesActions
# We know there's more data, so tell the frontend to poll again after 1ms
set_polling_interval_header(interval: 1) if meta[:more]
- # Only present an ETag for the empty response to ensure pagination works
- # as expected
- ::Gitlab::EtagCaching::Middleware.skip!(response) if notes.present?
+ # We might still want to investigate further adjusting ETag caching with paginated notes, but
+ # let's avoid ETag caching for now until we confirm the viability of paginated notes.
+ ::Gitlab::EtagCaching::Middleware.skip!(response)
render json: meta.merge(notes: notes)
end
@@ -243,7 +243,8 @@ module NotesActions
:type,
:note,
:line_code, # LegacyDiffNote
- :position # DiffNote
+ :position, # DiffNote
+ :confidential
).tap do |create_params|
create_params.merge!(
params.permit(:merge_request_diff_head_sha, :in_reply_to_discussion_id)
diff --git a/app/controllers/concerns/redis_tracking.rb b/app/controllers/concerns/redis_tracking.rb
index d71935356b8..a7e75f802a8 100644
--- a/app/controllers/concerns/redis_tracking.rb
+++ b/app/controllers/concerns/redis_tracking.rb
@@ -7,30 +7,26 @@
#
# include RedisTracking
#
-# track_redis_hll_event :index, :show, name: 'i_analytics_dev_ops_score', feature: :my_feature
-#
-# if the feature flag is enabled by default you should use
-# track_redis_hll_event :index, :show, name: 'i_analytics_dev_ops_score', feature: :my_feature, feature_default_enabled: true
+# track_redis_hll_event :index, :show, name: 'i_analytics_dev_ops_score'
#
# You can also pass custom conditions using `if:`, using the same format as with Rails callbacks.
module RedisTracking
extend ActiveSupport::Concern
class_methods do
- def track_redis_hll_event(*controller_actions, name:, feature:, feature_default_enabled: false, if: nil)
+ def track_redis_hll_event(*controller_actions, name:, if: nil)
custom_conditions = Array.wrap(binding.local_variable_get('if'))
conditions = [:trackable_request?, *custom_conditions]
after_action only: controller_actions, if: conditions do
- track_unique_redis_hll_event(name, feature, feature_default_enabled)
+ track_unique_redis_hll_event(name)
end
end
end
private
- def track_unique_redis_hll_event(event_name, feature, feature_default_enabled)
- return unless metric_feature_enabled?(feature, feature_default_enabled)
+ def track_unique_redis_hll_event(event_name)
return unless visitor_id
Gitlab::UsageDataCounters::HLLRedisCounter.track_event(event_name, values: visitor_id)
@@ -40,10 +36,6 @@ module RedisTracking
request.format.html? && request.headers['DNT'] != '1'
end
- def metric_feature_enabled?(feature, default_enabled)
- Feature.enabled?(feature, default_enabled: default_enabled)
- end
-
def visitor_id
return cookies[:visitor_id] if cookies[:visitor_id].present?
return unless current_user
diff --git a/app/controllers/concerns/service_params.rb b/app/controllers/concerns/service_params.rb
index c295290a123..3cab198c1f9 100644
--- a/app/controllers/concerns/service_params.rb
+++ b/app/controllers/concerns/service_params.rb
@@ -12,6 +12,7 @@ module ServiceParams
:api_version,
:bamboo_url,
:branches_to_be_notified,
+ :labels_to_be_notified,
:build_key,
:build_type,
:ca_pem,
diff --git a/app/controllers/concerns/snippets_actions.rb b/app/controllers/concerns/snippets_actions.rb
index c93e75b438b..0ee8d0c9307 100644
--- a/app/controllers/concerns/snippets_actions.rb
+++ b/app/controllers/concerns/snippets_actions.rb
@@ -15,7 +15,7 @@ module SnippetsActions
skip_before_action :verify_authenticity_token,
if: -> { action_name == 'show' && js_request? }
- track_redis_hll_event :show, name: 'i_snippets_show', feature: :usage_data_i_snippets_show, feature_default_enabled: true
+ track_redis_hll_event :show, name: 'i_snippets_show'
respond_to :html
end
diff --git a/app/controllers/concerns/spammable_actions.rb b/app/controllers/concerns/spammable_actions.rb
index 4ec561014a8..b285faee9bc 100644
--- a/app/controllers/concerns/spammable_actions.rb
+++ b/app/controllers/concerns/spammable_actions.rb
@@ -3,9 +3,6 @@
module SpammableActions
extend ActiveSupport::Concern
- include Recaptcha::Verify
- include Gitlab::Utils::StrongMemoize
-
included do
before_action :authorize_submit_spammable!, only: :mark_as_spam
end
@@ -20,17 +17,11 @@ module SpammableActions
private
- def ensure_spam_config_loaded!
- strong_memoize(:spam_config_loaded) do
- Gitlab::Recaptcha.load_configurations!
- end
- end
-
def recaptcha_check_with_fallback(should_redirect = true, &fallback)
if should_redirect && spammable.valid?
redirect_to spammable_path
- elsif render_recaptcha?
- ensure_spam_config_loaded!
+ elsif spammable.render_recaptcha?
+ Gitlab::Recaptcha.load_configurations!
respond_to do |format|
format.html do
@@ -50,33 +41,30 @@ module SpammableActions
end
def spammable_params
- default_params = { request: request }
-
- recaptcha_check = recaptcha_response &&
- ensure_spam_config_loaded! &&
- verify_recaptcha(response: recaptcha_response)
-
- return default_params unless recaptcha_check
-
- { recaptcha_verified: true,
- spam_log_id: params[:spam_log_id] }.merge(default_params)
- end
-
- def recaptcha_response
- # NOTE: This field name comes from `Recaptcha::ClientHelper#recaptcha_tags` in the recaptcha
- # gem, which is called from the HAML `_recaptcha_form.html.haml` form.
+ # NOTE: For the legacy reCAPTCHA implementation based on the HTML/HAML form, the
+ # 'g-recaptcha-response' field name comes from `Recaptcha::ClientHelper#recaptcha_tags` in the
+ # recaptcha gem, which is called from the HAML `_recaptcha_form.html.haml` form.
#
- # It is used in the `Recaptcha::Verify#verify_recaptcha` if the `response` option is not
- # passed explicitly.
+ # It is used in the `Recaptcha::Verify#verify_recaptcha` to extract the value from `params`,
+ # if the `response` option is not passed explicitly.
#
# Instead of relying on this behavior, we are extracting and passing it explicitly. This will
# make it consistent with the newer, modern reCAPTCHA verification process as it will be
# implemented via the GraphQL API and in Vue components via the native reCAPTCHA Javascript API,
# which requires that the recaptcha response param be obtained and passed explicitly.
#
- # After this newer GraphQL/JS API process is fully supported by the backend, we can remove this
- # (and other) HAML-specific support.
- params['g-recaptcha-response']
+ # It can also be expanded to multiple fields when we move to future alternative captcha
+ # implementations such as FriendlyCaptcha. See https://gitlab.com/gitlab-org/gitlab/-/issues/273480
+
+ # After this newer GraphQL/JS API process is fully supported by the backend, we can remove the
+ # check for the 'g-recaptcha-response' field and other HTML/HAML form-specific support.
+ captcha_response = params['g-recaptcha-response']
+
+ {
+ request: request,
+ spam_log_id: params[:spam_log_id],
+ captcha_response: captcha_response
+ }
end
def spammable
@@ -90,11 +78,4 @@ module SpammableActions
def authorize_submit_spammable!
access_denied! unless current_user.admin?
end
-
- def render_recaptcha?
- return false if spammable.errors.count > 1 # re-render "new" template in case there are other errors
- return false unless Gitlab::Recaptcha.enabled?
-
- spammable.needs_recaptcha?
- end
end
diff --git a/app/controllers/concerns/wiki_actions.rb b/app/controllers/concerns/wiki_actions.rb
index 1ae90edd8f7..4014e4f0024 100644
--- a/app/controllers/concerns/wiki_actions.rb
+++ b/app/controllers/concerns/wiki_actions.rb
@@ -36,8 +36,7 @@ module WikiActions
# NOTE: We want to include wiki page views in the same counter as the other
# Event-based wiki actions tracked through TrackUniqueEvents, so we use the same event name.
- track_redis_hll_event :show, name: Gitlab::UsageDataCounters::TrackUniqueEvents::WIKI_ACTION.to_s,
- feature: :track_unique_wiki_page_views, feature_default_enabled: true
+ track_redis_hll_event :show, name: Gitlab::UsageDataCounters::TrackUniqueEvents::WIKI_ACTION.to_s
helper_method :view_file_button, :diff_file_html_data