diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /app/controllers/concerns | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'app/controllers/concerns')
-rw-r--r-- | app/controllers/concerns/boards_actions.rb | 3 | ||||
-rw-r--r-- | app/controllers/concerns/impersonation.rb | 43 | ||||
-rw-r--r-- | app/controllers/concerns/issuable_actions.rb | 3 | ||||
-rw-r--r-- | app/controllers/concerns/issuable_collections_action.rb | 4 | ||||
-rw-r--r-- | app/controllers/concerns/known_sign_in.rb | 31 | ||||
-rw-r--r-- | app/controllers/concerns/members_presentation.rb | 1 | ||||
-rw-r--r-- | app/controllers/concerns/metrics_dashboard.rb | 29 | ||||
-rw-r--r-- | app/controllers/concerns/notes_actions.rb | 2 | ||||
-rw-r--r-- | app/controllers/concerns/preview_markdown.rb | 2 | ||||
-rw-r--r-- | app/controllers/concerns/record_user_last_activity.rb | 1 | ||||
-rw-r--r-- | app/controllers/concerns/renders_ldap_servers.rb | 19 | ||||
-rw-r--r-- | app/controllers/concerns/service_params.rb | 1 | ||||
-rw-r--r-- | app/controllers/concerns/snippets_actions.rb | 15 | ||||
-rw-r--r-- | app/controllers/concerns/spammable_actions.rb | 2 |
14 files changed, 140 insertions, 16 deletions
diff --git a/app/controllers/concerns/boards_actions.rb b/app/controllers/concerns/boards_actions.rb index eb1080cb3d2..9d40b9e8c88 100644 --- a/app/controllers/concerns/boards_actions.rb +++ b/app/controllers/concerns/boards_actions.rb @@ -10,6 +10,9 @@ module BoardsActions before_action :boards, only: :index before_action :board, only: :show before_action :push_wip_limits, only: [:index, :show] + before_action do + push_frontend_feature_flag(:not_issuable_queries, parent, default_enabled: true) + end end def index diff --git a/app/controllers/concerns/impersonation.rb b/app/controllers/concerns/impersonation.rb new file mode 100644 index 00000000000..a4f2c263eb4 --- /dev/null +++ b/app/controllers/concerns/impersonation.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +module Impersonation + include Gitlab::Utils::StrongMemoize + + def current_user + user = super + + user.impersonator = impersonator if impersonator + + user + end + + protected + + def check_impersonation_availability + return unless session[:impersonator_id] + + unless Gitlab.config.gitlab.impersonation_enabled + stop_impersonation + access_denied! _('Impersonation has been disabled') + end + end + + def stop_impersonation + log_impersonation_event + + warden.set_user(impersonator, scope: :user) + session[:impersonator_id] = nil + + current_user + end + + def log_impersonation_event + Gitlab::AppLogger.info("User #{impersonator.username} has stopped impersonating #{current_user.username}") + end + + def impersonator + strong_memoize(:impersonator) do + User.find(session[:impersonator_id]) if session[:impersonator_id] + end + end +end diff --git a/app/controllers/concerns/issuable_actions.rb b/app/controllers/concerns/issuable_actions.rb index ca43bf42580..0b1b3f2bcba 100644 --- a/app/controllers/concerns/issuable_actions.rb +++ b/app/controllers/concerns/issuable_actions.rb @@ -11,6 +11,9 @@ module IssuableActions before_action only: :show do push_frontend_feature_flag(:scoped_labels, default_enabled: true) end + before_action do + push_frontend_feature_flag(:not_issuable_queries, @project, default_enabled: true) + end end def permitted_keys diff --git a/app/controllers/concerns/issuable_collections_action.rb b/app/controllers/concerns/issuable_collections_action.rb index 0a6f684a9fc..78b3c6771b3 100644 --- a/app/controllers/concerns/issuable_collections_action.rb +++ b/app/controllers/concerns/issuable_collections_action.rb @@ -32,6 +32,10 @@ module IssuableCollectionsAction private + def set_not_query_feature_flag(object = nil) + push_frontend_feature_flag(:not_issuable_queries, object, default_enabled: true) + end + def sorting_field case action_name when 'issues' diff --git a/app/controllers/concerns/known_sign_in.rb b/app/controllers/concerns/known_sign_in.rb new file mode 100644 index 00000000000..97883d8d08c --- /dev/null +++ b/app/controllers/concerns/known_sign_in.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module KnownSignIn + include Gitlab::Utils::StrongMemoize + + private + + def verify_known_sign_in + return unless current_user + + notify_user unless known_remote_ip? + end + + def known_remote_ip? + known_ip_addresses.include?(request.remote_ip) + end + + def sessions + strong_memoize(:session) do + ActiveSession.list(current_user).reject(&:is_impersonated) + end + end + + def known_ip_addresses + [current_user.last_sign_in_ip, sessions.map(&:ip_address)].flatten + end + + def notify_user + current_user.notification_service.unknown_sign_in(current_user, request.remote_ip) + end +end diff --git a/app/controllers/concerns/members_presentation.rb b/app/controllers/concerns/members_presentation.rb index 0a9d3d86245..ceccef8113f 100644 --- a/app/controllers/concerns/members_presentation.rb +++ b/app/controllers/concerns/members_presentation.rb @@ -5,6 +5,7 @@ module MembersPresentation def present_members(members) preload_associations(members) + Gitlab::View::Presenter::Factory.new( members, current_user: current_user, diff --git a/app/controllers/concerns/metrics_dashboard.rb b/app/controllers/concerns/metrics_dashboard.rb index fa79f3bc4e6..1aea0e294a5 100644 --- a/app/controllers/concerns/metrics_dashboard.rb +++ b/app/controllers/concerns/metrics_dashboard.rb @@ -18,7 +18,7 @@ module MetricsDashboard if result result[:all_dashboards] = all_dashboards if include_all_dashboards? - result[:metrics_data] = metrics_data(project_for_dashboard, environment_for_dashboard) if project_for_dashboard && environment_for_dashboard + result[:metrics_data] = metrics_data(project_for_dashboard, environment_for_dashboard) end respond_to do |format| @@ -35,10 +35,9 @@ module MetricsDashboard private def all_dashboards - dashboards = dashboard_finder.find_all_paths(project_for_dashboard) - dashboards.map do |dashboard| - amend_dashboard(dashboard) - end + dashboard_finder + .find_all_paths(project_for_dashboard) + .map(&method(:amend_dashboard)) end def amend_dashboard(dashboard) @@ -46,10 +45,16 @@ module MetricsDashboard dashboard[:can_edit] = project_dashboard ? can_edit?(dashboard) : false dashboard[:project_blob_path] = project_dashboard ? dashboard_project_blob_path(dashboard) : nil + dashboard[:starred] = starred_dashboards.include?(dashboard[:path]) + dashboard[:user_starred_path] = project_for_dashboard ? user_starred_path(project_for_dashboard, dashboard[:path]) : nil dashboard end + def user_starred_path(project, path) + expose_path(api_v4_projects_metrics_user_starred_dashboards_path(id: project.id, params: { dashboard_path: path })) + end + def dashboard_project_blob_path(dashboard) project_blob_path(project_for_dashboard, File.join(project_for_dashboard.default_branch, dashboard.fetch(:path, ""))) end @@ -73,6 +78,20 @@ module MetricsDashboard ::Gitlab::Metrics::Dashboard::Finder end + def starred_dashboards + @starred_dashboards ||= begin + if project_for_dashboard.present? + ::Metrics::UsersStarredDashboardsFinder + .new(user: current_user, project: project_for_dashboard) + .execute + .map(&:dashboard_path) + .to_set + else + Set.new + end + end + end + # Project is not defined for group and admin level clusters. def project_for_dashboard defined?(project) ? project : nil diff --git a/app/controllers/concerns/notes_actions.rb b/app/controllers/concerns/notes_actions.rb index 7dd2f6e5706..d4b0d3b2674 100644 --- a/app/controllers/concerns/notes_actions.rb +++ b/app/controllers/concerns/notes_actions.rb @@ -13,7 +13,7 @@ module NotesActions end def index - current_fetched_at = Time.now.to_i + current_fetched_at = Time.current.to_i notes_json = { notes: [], last_fetched_at: current_fetched_at } diff --git a/app/controllers/concerns/preview_markdown.rb b/app/controllers/concerns/preview_markdown.rb index c7c9f2e9b70..ba15d611c0d 100644 --- a/app/controllers/concerns/preview_markdown.rb +++ b/app/controllers/concerns/preview_markdown.rb @@ -37,7 +37,7 @@ module PreviewMarkdown when 'groups' then { group: group } when 'projects' then projects_filter_params else {} - end.merge(requested_path: params[:path]) + end.merge(requested_path: params[:path], ref: params[:ref]) end # rubocop:enable Gitlab/ModuleWithInstanceVariables diff --git a/app/controllers/concerns/record_user_last_activity.rb b/app/controllers/concerns/record_user_last_activity.rb index 4013596ba12..29164df4516 100644 --- a/app/controllers/concerns/record_user_last_activity.rb +++ b/app/controllers/concerns/record_user_last_activity.rb @@ -17,7 +17,6 @@ module RecordUserLastActivity def set_user_last_activity return unless request.get? - return unless Feature.enabled?(:set_user_last_activity, default_enabled: true) return if Gitlab::Database.read_only? if current_user && current_user.last_activity_on != Date.today diff --git a/app/controllers/concerns/renders_ldap_servers.rb b/app/controllers/concerns/renders_ldap_servers.rb new file mode 100644 index 00000000000..cc83ff47048 --- /dev/null +++ b/app/controllers/concerns/renders_ldap_servers.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module RendersLdapServers + extend ActiveSupport::Concern + + included do + helper_method :ldap_servers + end + + def ldap_servers + @ldap_servers ||= begin + if Gitlab::Auth::Ldap::Config.sign_in_enabled? + Gitlab::Auth::Ldap::Config.available_servers + else + [] + end + end + end +end diff --git a/app/controllers/concerns/service_params.rb b/app/controllers/concerns/service_params.rb index 3ccf227c431..e2c83f9a069 100644 --- a/app/controllers/concerns/service_params.rb +++ b/app/controllers/concerns/service_params.rb @@ -19,6 +19,7 @@ module ServiceParams :color, :colorize_messages, :comment_on_event_enabled, + :comment_detail, :confidential_issues_events, :default_irc_uri, :description, diff --git a/app/controllers/concerns/snippets_actions.rb b/app/controllers/concerns/snippets_actions.rb index 096c6efc0fc..e78723bdda2 100644 --- a/app/controllers/concerns/snippets_actions.rb +++ b/app/controllers/concerns/snippets_actions.rb @@ -53,10 +53,10 @@ module SnippetsActions def blob return unless snippet - @blob ||= if Feature.enabled?(:version_snippets, current_user) && !snippet.repository.empty? - snippet.blobs.first - else + @blob ||= if snippet.empty_repo? snippet.blob + else + snippet.blobs.first end end # rubocop:enable Gitlab/ModuleWithInstanceVariables @@ -65,11 +65,12 @@ module SnippetsActions params[:line_ending] == 'raw' ? content : content.gsub(/\r\n/, "\n") end - def check_repository_error - repository_errors = Array(snippet.errors.delete(:repository)) + def handle_repository_error(action) + errors = Array(snippet.errors.delete(:repository)) + + flash.now[:alert] = errors.first if errors.present? - flash.now[:alert] = repository_errors.first if repository_errors.present? - recaptcha_check_with_fallback(repository_errors.empty?) { render :edit } + recaptcha_check_with_fallback(errors.empty?) { render action } end def redirect_if_binary diff --git a/app/controllers/concerns/spammable_actions.rb b/app/controllers/concerns/spammable_actions.rb index 46ba270f328..50c93441dd4 100644 --- a/app/controllers/concerns/spammable_actions.rb +++ b/app/controllers/concerns/spammable_actions.rb @@ -82,6 +82,6 @@ module SpammableActions return false if spammable.errors.count > 1 # re-render "new" template in case there are other errors return false unless Gitlab::Recaptcha.enabled? - spammable.spam + spammable.needs_recaptcha? end end |