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>2020-01-09 18:07:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-09 18:07:42 +0300
commit263f926c770163788f78af03ab69689c94f57360 (patch)
tree4e1027e596629106d25fa461a1cf3d613749d279 /app
parentcddaddb86bf6d4d277d206c42a9138a2d660ea56 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/performance_monitoring/dashboards_controller.rb96
-rw-r--r--app/models/project.rb1
2 files changed, 97 insertions, 0 deletions
diff --git a/app/controllers/projects/performance_monitoring/dashboards_controller.rb b/app/controllers/projects/performance_monitoring/dashboards_controller.rb
new file mode 100644
index 00000000000..c873fcd6c8a
--- /dev/null
+++ b/app/controllers/projects/performance_monitoring/dashboards_controller.rb
@@ -0,0 +1,96 @@
+# frozen_string_literal: true
+
+module Projects
+ module PerformanceMonitoring
+ class DashboardsController < ::Projects::ApplicationController
+ include BlobHelper
+
+ before_action :check_repository_available!
+ before_action :validate_required_params!
+ before_action :validate_dashboard_template!
+ before_action :authorize_push!
+
+ USER_DASHBOARDS_DIR = ::Metrics::Dashboard::ProjectDashboardService::DASHBOARD_ROOT
+ DASHBOARD_TEMPLATES = {
+ ::Metrics::Dashboard::SystemDashboardService::DASHBOARD_PATH => ::Metrics::Dashboard::SystemDashboardService::DASHBOARD_PATH
+ }.freeze
+
+ def create
+ result = ::Files::CreateService.new(project, current_user, dashboard_attrs).execute
+
+ if result[:status] == :success
+ respond_success
+ else
+ respond_error(result[:message])
+ end
+ end
+
+ private
+
+ def respond_success
+ respond_to do |format|
+ format.html { redirect_to ide_edit_path(project, redirect_safe_branch_name, new_dashboard_path) }
+ format.json { render json: { redirect_to: ide_edit_path(project, redirect_safe_branch_name, new_dashboard_path) }, status: :created }
+ end
+ end
+
+ def respond_error(message)
+ flash[:alert] = message
+
+ respond_to do |format|
+ format.html { redirect_back_or_default(default: namespace_project_environments_path) }
+ format.json { render json: { error: message }, status: :bad_request }
+ end
+ end
+
+ def authorize_push!
+ access_denied!(%q(You can't commit to this project)) unless user_access(project).can_push_to_branch?(params[:branch])
+ end
+
+ def validate_required_params!
+ params.require(%i(branch file_name dashboard))
+ end
+
+ def validate_dashboard_template!
+ access_denied! unless dashboard_template
+ end
+
+ def dashboard_attrs
+ {
+ commit_message: commit_message,
+ file_path: new_dashboard_path,
+ file_content: new_dashboard_content,
+ encoding: 'text',
+ branch_name: params[:branch],
+ start_branch: repository.branch_exists?(params[:branch]) ? params[:branch] : project.default_branch
+ }
+ end
+
+ def commit_message
+ params[:commit_message] || "Create custom dashboard #{params[:file_name]}"
+ end
+
+ def new_dashboard_path
+ File.join(USER_DASHBOARDS_DIR, params[:file_name])
+ end
+
+ def new_dashboard_content
+ File.read(Rails.root.join(dashboard_template))
+ end
+
+ def dashboard_template
+ dashboard_templates[params[:dashboard]]
+ end
+
+ def dashboard_templates
+ DASHBOARD_TEMPLATES
+ end
+
+ def redirect_safe_branch_name
+ repository.find_branch(params[:branch]).name
+ end
+ end
+ end
+end
+
+Projects::PerformanceMonitoring::DashboardsController.prepend_if_ee('EE::Projects::PerformanceMonitoring::DashboardsController')
diff --git a/app/models/project.rb b/app/models/project.rb
index 25819bc2b85..6858d03098c 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1932,6 +1932,7 @@ class Project < ApplicationRecord
Gitlab::Ci::Variables::Collection.new
.append(key: 'CI', value: 'true')
.append(key: 'GITLAB_CI', value: 'true')
+ .append(key: 'CI_SERVER_URL', value: Gitlab.config.gitlab.url)
.append(key: 'CI_SERVER_HOST', value: Gitlab.config.gitlab.host)
.append(key: 'CI_SERVER_NAME', value: 'GitLab')
.append(key: 'CI_SERVER_VERSION', value: Gitlab::VERSION)