Commit 8b05abe8 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'allow-to-disable-ci' into 'master'

Allow to disable GitLab CI

Added simple config option to disable GitLab CI

It makes all CI related requests to return 404

/cc @dzaporozhets @jacobvosmaer @vsizov

See merge request !1340
parents 1eb3dde4 97fa9904
...@@ -56,6 +56,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController ...@@ -56,6 +56,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
:restricted_signup_domains_raw, :restricted_signup_domains_raw,
:version_check_enabled, :version_check_enabled,
:user_oauth_applications, :user_oauth_applications,
:ci_enabled,
restricted_visibility_levels: [], restricted_visibility_levels: [],
import_sources: [] import_sources: []
) )
......
module Ci module Ci
class ApplicationController < ::ApplicationController class ApplicationController < ::ApplicationController
before_action :check_enable_flag!
def self.railtie_helpers_paths def self.railtie_helpers_paths
"app/helpers/ci" "app/helpers/ci"
end end
...@@ -8,6 +10,13 @@ module Ci ...@@ -8,6 +10,13 @@ module Ci
private private
def check_enable_flag!
unless current_application_settings.ci_enabled
redirect_to(disabled_ci_projects_path)
return
end
end
def authenticate_public_page! def authenticate_public_page!
unless project.public unless project.public
authenticate_user! authenticate_user!
......
...@@ -5,13 +5,17 @@ module Ci ...@@ -5,13 +5,17 @@ module Ci
before_action :authenticate_user!, except: [:build, :badge, :index, :show] before_action :authenticate_user!, except: [:build, :badge, :index, :show]
before_action :authenticate_public_page!, only: :show before_action :authenticate_public_page!, only: :show
before_action :project, only: [:build, :integration, :show, :badge, :edit, :update, :destroy, :toggle_shared_runners, :dumped_yaml] before_action :project, only: [:build, :integration, :show, :badge, :edit, :update, :destroy, :toggle_shared_runners, :dumped_yaml]
before_action :authorize_access_project!, except: [:build, :badge, :index, :show, :new, :create] before_action :authorize_access_project!, except: [:build, :badge, :index, :show, :new, :create, :disabled]
before_action :authorize_manage_project!, only: [:edit, :integration, :update, :destroy, :toggle_shared_runners, :dumped_yaml] before_action :authorize_manage_project!, only: [:edit, :integration, :update, :destroy, :toggle_shared_runners, :dumped_yaml]
before_action :authenticate_token!, only: [:build] before_action :authenticate_token!, only: [:build]
before_action :no_cache, only: [:badge] before_action :no_cache, only: [:badge]
skip_before_action :check_enable_flag!, only: [:disabled]
protect_from_forgery except: :build protect_from_forgery except: :build
layout 'ci/project', except: :index layout 'ci/project', except: [:index, :disabled]
def disabled
end
def index def index
@limit, @offset = (params[:limit] || PROJECTS_BATCH).to_i, (params[:offset] || 0).to_i @limit, @offset = (params[:limit] || PROJECTS_BATCH).to_i, (params[:offset] || 0).to_i
......
...@@ -83,7 +83,8 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -83,7 +83,8 @@ class ApplicationSetting < ActiveRecord::Base
default_project_visibility: Settings.gitlab.default_projects_features['visibility_level'], default_project_visibility: Settings.gitlab.default_projects_features['visibility_level'],
default_snippet_visibility: Settings.gitlab.default_projects_features['visibility_level'], default_snippet_visibility: Settings.gitlab.default_projects_features['visibility_level'],
restricted_signup_domains: Settings.gitlab['restricted_signup_domains'], restricted_signup_domains: Settings.gitlab['restricted_signup_domains'],
import_sources: ['github','bitbucket','gitlab','gitorious','google_code','fogbugz','git'] import_sources: ['github','bitbucket','gitlab','gitorious','google_code','fogbugz','git'],
ci_enabled: Settings.gitlab_ci['enabled']
) )
end end
......
...@@ -124,5 +124,14 @@ ...@@ -124,5 +124,14 @@
= f.text_area :help_page_text, class: 'form-control', rows: 4 = f.text_area :help_page_text, class: 'form-control', rows: 4
.help-block Markdown enabled .help-block Markdown enabled
%fieldset
%legend Continuous Integration
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :ci_enabled do
= f.check_box :ci_enabled
Enable Continuous Integration
.form-actions .form-actions
= f.submit 'Save', class: 'btn btn-primary' = f.submit 'Save', class: 'btn btn-primary'
Continuous Integration has been disabled. Please ask your administrator to enable it.
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
%html{ lang: "en"} %html{ lang: "en"}
= render 'layouts/head' = render 'layouts/head'
%body{class: "ci-body #{user_application_theme}", 'data-page' => body_data_page} %body{class: "ci-body #{user_application_theme}", 'data-page' => body_data_page}
- header_title = "CI Projects" - header_title = "Continuous Integration"
- if current_user - if current_user
= render "layouts/header/default", title: header_title = render "layouts/header/default", title: header_title
- else - else
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
%span %span
Merge Requests Merge Requests
%span.count= current_user.assigned_merge_requests.opened.count %span.count= current_user.assigned_merge_requests.opened.count
= nav_link(path: 'ci/projects#index') do = nav_link(path: ['ci/projects#index', 'ci/projects#disabled']) do
= link_to ci_projects_path, title: 'Continuous Integration', data: {placement: 'right'} do = link_to ci_projects_path, title: 'Continuous Integration', data: {placement: 'right'} do
= icon('building fw') = icon('building fw')
%span %span
......
...@@ -178,6 +178,7 @@ Settings.gitlab['import_sources'] ||= ['github','bitbucket','gitlab','gitorious' ...@@ -178,6 +178,7 @@ Settings.gitlab['import_sources'] ||= ['github','bitbucket','gitlab','gitorious'
# CI # CI
# #
Settings['gitlab_ci'] ||= Settingslogic.new({}) Settings['gitlab_ci'] ||= Settingslogic.new({})
Settings.gitlab_ci['enabled'] = true if Settings.gitlab_ci['enabled'].nil?
Settings.gitlab_ci['all_broken_builds'] = true if Settings.gitlab_ci['all_broken_builds'].nil? Settings.gitlab_ci['all_broken_builds'] = true if Settings.gitlab_ci['all_broken_builds'].nil?
Settings.gitlab_ci['add_pusher'] = false if Settings.gitlab_ci['add_pusher'].nil? Settings.gitlab_ci['add_pusher'] = false if Settings.gitlab_ci['add_pusher'].nil?
Settings.gitlab_ci['url'] ||= Settings.send(:build_gitlab_ci_url) Settings.gitlab_ci['url'] ||= Settings.send(:build_gitlab_ci_url)
......
...@@ -12,7 +12,7 @@ Gitlab::Application.routes.draw do ...@@ -12,7 +12,7 @@ Gitlab::Application.routes.draw do
resources :projects do resources :projects do
collection do collection do
post :add post :add
get :gitlab get :disabled
end end
member do member do
......
class AddCiEnabledToApplicationSettings < ActiveRecord::Migration
def change
add_column :application_settings, :ci_enabled, :boolean, null: false, default: true
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150916145038) do ActiveRecord::Schema.define(version: 20150918084513) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
...@@ -46,6 +46,7 @@ ActiveRecord::Schema.define(version: 20150916145038) do ...@@ -46,6 +46,7 @@ ActiveRecord::Schema.define(version: 20150916145038) do
t.integer "session_expire_delay", default: 10080, null: false t.integer "session_expire_delay", default: 10080, null: false
t.text "import_sources" t.text "import_sources"
t.text "help_page_text" t.text "help_page_text"
t.boolean "ci_enabled", default: true, null: false
end end
create_table "audit_events", force: true do |t| create_table "audit_events", force: true do |t|
......
...@@ -23,6 +23,10 @@ module Ci ...@@ -23,6 +23,10 @@ module Ci
rack_response({ 'message' => '500 Internal Server Error' }, 500) rack_response({ 'message' => '500 Internal Server Error' }, 500)
end end
before do
check_enable_flag!
end
format :json format :json
helpers Helpers helpers Helpers
......
...@@ -3,6 +3,12 @@ module Ci ...@@ -3,6 +3,12 @@ module Ci
module Helpers module Helpers
UPDATE_RUNNER_EVERY = 60 UPDATE_RUNNER_EVERY = 60
def check_enable_flag!
unless current_application_settings.ci_enabled
render_api_error!('400 (Bad request) CI is disabled', 400)
end
end
def authenticate_runners! def authenticate_runners!
forbidden! unless params[:token] == GitlabCi::REGISTRATION_TOKEN forbidden! unless params[:token] == GitlabCi::REGISTRATION_TOKEN
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment