Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-10-18 18:10:24 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-10-18 18:10:24 +0300
commitb81ffd93854bcc57c493745137578f141ac8a78f (patch)
tree3ceaaffa155813c40272927c6aef0dfdf04ac155 /app
parent91ca0550e00347bb6db5aba9f039be9137f3a254 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/prometheus/metrics_controller.rb137
-rw-r--r--app/graphql/mutations/work_items/update.rb2
-rw-r--r--app/helpers/projects/ml/experiments_helper.rb15
-rw-r--r--app/services/concerns/users/participable_service.rb2
-rw-r--r--app/services/import/validate_remote_git_endpoint_service.rb81
-rw-r--r--app/services/projects/participants_service.rb4
-rw-r--r--app/workers/issuable/related_links_create_worker.rb4
7 files changed, 70 insertions, 175 deletions
diff --git a/app/controllers/projects/prometheus/metrics_controller.rb b/app/controllers/projects/prometheus/metrics_controller.rb
deleted file mode 100644
index 396841e667d..00000000000
--- a/app/controllers/projects/prometheus/metrics_controller.rb
+++ /dev/null
@@ -1,137 +0,0 @@
-# frozen_string_literal: true
-
-module Projects
- module Prometheus
- class MetricsController < Projects::ApplicationController
- before_action :check_feature_availability!
- before_action :authorize_admin_project!
- before_action :require_prometheus_metrics!
-
- feature_category :metrics
- urgency :low
-
- def active_common
- respond_to do |format|
- format.json do
- matched_metrics = prometheus_adapter.query(:matched_metrics) || {}
-
- if matched_metrics.any?
- render json: matched_metrics
- else
- head :no_content
- end
- end
- end
- end
-
- def validate_query
- respond_to do |format|
- format.json do
- result = prometheus_adapter.query(:validate, params[:query])
-
- if result
- render json: result
- else
- head :accepted
- end
- end
- end
- end
-
- def new
- @metric = project.prometheus_metrics.new
- end
-
- def index
- respond_to do |format|
- format.json do
- metrics = ::PrometheusMetricsFinder.new(
- project: project,
- ordered: true
- ).execute.to_a
-
- response = {}
- if metrics.any?
- response[:metrics] = ::PrometheusMetricSerializer
- .new(project: project)
- .represent(metrics)
- end
-
- render json: response
- end
- end
- end
-
- def create
- @metric = project.prometheus_metrics.create(
- metrics_params.to_h.symbolize_keys
- )
-
- if @metric.persisted?
- redirect_to edit_project_settings_integration_path(project, ::Integrations::Prometheus),
- notice: _('Metric was successfully added.')
- else
- render 'new'
- end
- end
-
- def update
- @metric = prometheus_metric
-
- if @metric.update(metrics_params)
- redirect_to edit_project_settings_integration_path(project, ::Integrations::Prometheus),
- notice: _('Metric was successfully updated.')
- else
- render 'edit'
- end
- end
-
- def edit
- @metric = prometheus_metric
- end
-
- def destroy
- destroy_metrics_service(prometheus_metric).execute
-
- respond_to do |format|
- format.html do
- redirect_to edit_project_settings_integration_path(project, ::Integrations::Prometheus), status: :see_other
- end
- format.json do
- head :ok
- end
- end
- end
-
- private
-
- def prometheus_adapter
- @prometheus_adapter ||= ::Gitlab::Prometheus::Adapter.new(project, project.deployment_platform&.cluster).prometheus_adapter
- end
-
- def require_prometheus_metrics!
- render_404 unless prometheus_adapter&.can_query?
- end
-
- def prometheus_metric
- @prometheus_metric ||= ::PrometheusMetricsFinder.new(id: params[:id]).execute.first
- end
-
- def update_metrics_service(metric)
- ::Projects::Prometheus::Metrics::UpdateService.new(metric, metrics_params)
- end
-
- def destroy_metrics_service(metric)
- ::Projects::Prometheus::Metrics::DestroyService.new(metric)
- end
-
- def metrics_params
- params.require(:prometheus_metric).permit(:title, :query, :y_label, :unit, :legend, :group)
- end
-
- def check_feature_availability!
- render_404 if Feature.enabled?(:remove_monitor_metrics)
- end
- end
- end
-end
diff --git a/app/graphql/mutations/work_items/update.rb b/app/graphql/mutations/work_items/update.rb
index 1115dc74a9b..228a9e52355 100644
--- a/app/graphql/mutations/work_items/update.rb
+++ b/app/graphql/mutations/work_items/update.rb
@@ -28,7 +28,7 @@ module Mutations
raise_resource_not_available_error! unless attributes.empty? || can_update?(work_item)
update_result = ::WorkItems::UpdateService.new(
- container: work_item.project,
+ container: work_item.resource_parent,
current_user: current_user,
params: attributes,
widget_params: widget_params,
diff --git a/app/helpers/projects/ml/experiments_helper.rb b/app/helpers/projects/ml/experiments_helper.rb
index d5b2c3cd36a..6c7b6eb6fbc 100644
--- a/app/helpers/projects/ml/experiments_helper.rb
+++ b/app/helpers/projects/ml/experiments_helper.rb
@@ -14,17 +14,17 @@ module Projects
Gitlab::Json.generate(data)
end
- def candidates_table_items(candidates, user)
+ def candidates_table_items(candidates, current_user)
items = candidates.map do |candidate|
{
**candidate.params.to_h { |p| [p.name, p.value] },
**candidate.latest_metrics.to_h { |m| [m.name, number_with_precision(m.value, precision: 4)] },
- ci_job: job_info(candidate, user),
+ ci_job: job_info(candidate, current_user),
artifact: link_to_artifact(candidate),
details: link_to_details(candidate),
name: candidate.name,
created_at: candidate.created_at,
- user: user_info(candidate)
+ user: user_info(candidate, current_user)
}
end
@@ -87,8 +87,13 @@ module Projects
project_ml_experiment_path(project, experiment.iid)
end
- def user_info(candidate)
- user = candidate.user
+ def user_info(candidate, current_user)
+ user =
+ if candidate.from_ci?
+ candidate.ci_build.user if can?(current_user, :read_build, candidate.ci_build)
+ else
+ candidate.user
+ end
return unless user.present?
diff --git a/app/services/concerns/users/participable_service.rb b/app/services/concerns/users/participable_service.rb
index 1a03b444b68..a54c4947b0b 100644
--- a/app/services/concerns/users/participable_service.rb
+++ b/app/services/concerns/users/participable_service.rb
@@ -34,7 +34,7 @@ module Users
def groups
return [] unless current_user
- current_user.authorized_groups.with_route.sort_by(&:path)
+ current_user.authorized_groups.with_route.sort_by(&:full_path)
end
def render_participants_as_hash(participants)
diff --git a/app/services/import/validate_remote_git_endpoint_service.rb b/app/services/import/validate_remote_git_endpoint_service.rb
index a994072c4aa..2177238fddf 100644
--- a/app/services/import/validate_remote_git_endpoint_service.rb
+++ b/app/services/import/validate_remote_git_endpoint_service.rb
@@ -13,6 +13,8 @@ module Import
GIT_PROTOCOL_PKT_LEN = 4
GIT_MINIMUM_RESPONSE_LENGTH = GIT_PROTOCOL_PKT_LEN + GIT_EXPECTED_FIRST_PACKET_LINE.length
EXPECTED_CONTENT_TYPE = "application/x-#{GIT_SERVICE_NAME}-advertisement"
+ INVALID_BODY_MESSAGE = 'Not a git repository: Invalid response body'
+ INVALID_CONTENT_TYPE_MESSAGE = 'Not a git repository: Invalid content-type'
def initialize(params)
@params = params
@@ -30,32 +32,35 @@ module Import
uri.fragment = nil
url = Gitlab::Utils.append_path(uri.to_s, "/info/refs?service=#{GIT_SERVICE_NAME}")
- response_body = ''
- result = nil
- Gitlab::HTTP.try_get(url, stream_body: true, follow_redirects: false, basic_auth: auth) do |fragment|
- response_body += fragment
- next if response_body.length < GIT_MINIMUM_RESPONSE_LENGTH
-
- result = if status_code_is_valid(fragment) && content_type_is_valid(fragment) && response_body_is_valid(response_body)
- :success
- else
- :error
- end
-
- # We are interested only in the first chunks of the response
- # So we're using stream_body: true and breaking when receive enough body
- break
- end
+ response, response_body = http_get_and_extract_first_chunks(url)
- if result == :success
- ServiceResponse.success
- else
- ServiceResponse.error(message: "#{uri} is not a valid HTTP Git repository")
- end
+ validate(uri, response, response_body)
+ rescue *Gitlab::HTTP::HTTP_ERRORS => err
+ error_result("HTTP #{err.class.name.underscore} error: #{err.message}")
+ rescue StandardError => err
+ ServiceResponse.error(
+ message: "Internal #{err.class.name.underscore} error: #{err.message}",
+ reason: 500
+ )
end
private
+ def http_get_and_extract_first_chunks(url)
+ # We are interested only in the first chunks of the response
+ # So we're using stream_body: true and breaking when receive enough body
+ response = nil
+ response_body = ''
+
+ Gitlab::HTTP.get(url, stream_body: true, follow_redirects: false, basic_auth: auth) do |response_chunk|
+ response = response_chunk
+ response_body += response_chunk
+ break if GIT_MINIMUM_RESPONSE_LENGTH <= response_body.length
+ end
+
+ [response, response_body]
+ end
+
def auth
unless @params[:user].to_s.blank?
{
@@ -65,16 +70,38 @@ module Import
end
end
- def status_code_is_valid(fragment)
- fragment.http_response.code == '200'
+ def validate(uri, response, response_body)
+ return status_code_error(uri, response) unless status_code_is_valid?(response)
+ return error_result(INVALID_CONTENT_TYPE_MESSAGE) unless content_type_is_valid?(response)
+ return error_result(INVALID_BODY_MESSAGE) unless response_body_is_valid?(response_body)
+
+ ServiceResponse.success
+ end
+
+ def status_code_error(uri, response)
+ http_code = response.http_response.code.to_i
+ message = response.http_response.message || Rack::Utils::HTTP_STATUS_CODES[http_code]
+
+ error_result(
+ "#{uri} endpoint error: #{http_code}#{message.presence&.prepend(' ')}",
+ http_code
+ )
+ end
+
+ def error_result(message, reason = nil)
+ ServiceResponse.error(message: message, reason: reason)
+ end
+
+ def status_code_is_valid?(response)
+ response.http_response.code == '200'
end
- def content_type_is_valid(fragment)
- fragment.http_response['content-type'] == EXPECTED_CONTENT_TYPE
+ def content_type_is_valid?(response)
+ response.http_response['content-type'] == EXPECTED_CONTENT_TYPE
end
- def response_body_is_valid(response_body)
- response_body.match?(GIT_BODY_MESSAGE_REGEXP)
+ def response_body_is_valid?(response_body)
+ response_body.length <= GIT_MINIMUM_RESPONSE_LENGTH && response_body.match?(GIT_BODY_MESSAGE_REGEXP)
end
end
end
diff --git a/app/services/projects/participants_service.rb b/app/services/projects/participants_service.rb
index 458eaec4e2e..fe19d1f051d 100644
--- a/app/services/projects/participants_service.rb
+++ b/app/services/projects/participants_service.rb
@@ -11,8 +11,8 @@ module Projects
noteable_owner +
participants_in_noteable +
all_members +
- groups +
- project_members
+ project_members +
+ groups
render_participants_as_hash(participants.uniq)
end
diff --git a/app/workers/issuable/related_links_create_worker.rb b/app/workers/issuable/related_links_create_worker.rb
index a306c23ec3e..7cbf70fd5ab 100644
--- a/app/workers/issuable/related_links_create_worker.rb
+++ b/app/workers/issuable/related_links_create_worker.rb
@@ -13,8 +13,8 @@ module Issuable
urgency :high
idempotent!
- def perform(params)
- @params = params.with_indifferent_access
+ def perform(args)
+ @params = args.with_indifferent_access
@user = User.find_by_id(params[:user_id])
@issuable = issuable_class.find_by_id(params[:issuable_id])
@links = issuable_class.related_link_class&.where(id: params[:link_ids])