Commit dd785467 authored by Alexis Reigel's avatar Alexis Reigel

project#group_runner_enabled -> project_settings

parent a2a7ad29
...@@ -53,7 +53,7 @@ class Projects::RunnersController < Projects::ApplicationController ...@@ -53,7 +53,7 @@ class Projects::RunnersController < Projects::ApplicationController
end end
def toggle_group_runners def toggle_group_runners
project.toggle!(:group_runners_enabled) project.toggle_settings!(:group_runners_enabled)
redirect_to project_settings_ci_cd_path(@project) redirect_to project_settings_ci_cd_path(@project)
end end
......
...@@ -249,6 +249,7 @@ class Project < ActiveRecord::Base ...@@ -249,6 +249,7 @@ class Project < ActiveRecord::Base
delegate :members, to: :team, prefix: true delegate :members, to: :team, prefix: true
delegate :add_user, :add_users, to: :team delegate :add_user, :add_users, to: :team
delegate :add_guest, :add_reporter, :add_developer, :add_master, :add_role, to: :team delegate :add_guest, :add_reporter, :add_developer, :add_master, :add_role, to: :team
delegate :group_runners_enabled, :group_runners_enabled=, :group_runners_enabled?, to: :settings
# Validations # Validations
validates :creator, presence: true, on: :create validates :creator, presence: true, on: :create
...@@ -1893,6 +1894,10 @@ class Project < ActiveRecord::Base ...@@ -1893,6 +1894,10 @@ class Project < ActiveRecord::Base
[] []
end end
def toggle_settings!(settings_attribute)
settings.toggle!(settings_attribute)
end
private private
def storage def storage
......
class AddGroupRunnersEnabledToProjects < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_column_with_default :projects, :group_runners_enabled, :boolean, default: true
add_concurrent_index :projects, :group_runners_enabled
end
def down
remove_column :projects, :group_runners_enabled
end
end
...@@ -7,6 +7,8 @@ class CreateProjectSettings < ActiveRecord::Migration ...@@ -7,6 +7,8 @@ class CreateProjectSettings < ActiveRecord::Migration
def change def change
create_table :project_settings do |t| create_table :project_settings do |t|
t.references :project, index: true, foreign_key: { on_delete: :cascade } t.references :project, index: true, foreign_key: { on_delete: :cascade }
t.boolean :group_runners_enabled, default: true, index: true
end end
end end
end end
...@@ -1506,8 +1506,10 @@ ActiveRecord::Schema.define(version: 20180418053107) do ...@@ -1506,8 +1506,10 @@ ActiveRecord::Schema.define(version: 20180418053107) do
create_table "project_settings", force: :cascade do |t| create_table "project_settings", force: :cascade do |t|
t.integer "project_id" t.integer "project_id"
t.boolean "group_runners_enabled", default: true
end end
add_index "project_settings", ["group_runners_enabled"], name: "index_project_settings_on_group_runners_enabled", using: :btree
add_index "project_settings", ["project_id"], name: "index_project_settings_on_project_id", using: :btree add_index "project_settings", ["project_id"], name: "index_project_settings_on_project_id", using: :btree
create_table "project_statistics", force: :cascade do |t| create_table "project_statistics", force: :cascade do |t|
...@@ -1581,7 +1583,6 @@ ActiveRecord::Schema.define(version: 20180418053107) do ...@@ -1581,7 +1583,6 @@ ActiveRecord::Schema.define(version: 20180418053107) do
add_index "projects", ["created_at"], name: "index_projects_on_created_at", using: :btree add_index "projects", ["created_at"], name: "index_projects_on_created_at", using: :btree
add_index "projects", ["creator_id"], name: "index_projects_on_creator_id", using: :btree add_index "projects", ["creator_id"], name: "index_projects_on_creator_id", using: :btree
add_index "projects", ["description"], name: "index_projects_on_description_trigram", using: :gin, opclasses: {"description"=>"gin_trgm_ops"} add_index "projects", ["description"], name: "index_projects_on_description_trigram", using: :gin, opclasses: {"description"=>"gin_trgm_ops"}
add_index "projects", ["group_runners_enabled"], name: "index_projects_on_group_runners_enabled", using: :btree
add_index "projects", ["id"], name: "index_projects_on_id_partial_for_visibility", unique: true, where: "(visibility_level = ANY (ARRAY[10, 20]))", using: :btree add_index "projects", ["id"], name: "index_projects_on_id_partial_for_visibility", unique: true, where: "(visibility_level = ANY (ARRAY[10, 20]))", using: :btree
add_index "projects", ["last_activity_at"], name: "index_projects_on_last_activity_at", using: :btree add_index "projects", ["last_activity_at"], name: "index_projects_on_last_activity_at", using: :btree
add_index "projects", ["last_repository_check_failed"], name: "index_projects_on_last_repository_check_failed", using: :btree add_index "projects", ["last_repository_check_failed"], name: "index_projects_on_last_repository_check_failed", using: :btree
......
...@@ -15,14 +15,18 @@ FactoryBot.define do ...@@ -15,14 +15,18 @@ FactoryBot.define do
namespace namespace
creator { group ? create(:user) : namespace&.owner } creator { group ? create(:user) : namespace&.owner }
# Nest Project Feature attributes
transient do transient do
# Nest Project Feature attributes
wiki_access_level ProjectFeature::ENABLED wiki_access_level ProjectFeature::ENABLED
builds_access_level ProjectFeature::ENABLED builds_access_level ProjectFeature::ENABLED
snippets_access_level ProjectFeature::ENABLED snippets_access_level ProjectFeature::ENABLED
issues_access_level ProjectFeature::ENABLED issues_access_level ProjectFeature::ENABLED
merge_requests_access_level ProjectFeature::ENABLED merge_requests_access_level ProjectFeature::ENABLED
repository_access_level ProjectFeature::ENABLED repository_access_level ProjectFeature::ENABLED
# we can't assign the delegated `#settings` attributes directly, as the
# `#settings` relation needs to be created first
group_runners_enabled nil
end end
after(:create) do |project, evaluator| after(:create) do |project, evaluator|
...@@ -47,6 +51,9 @@ FactoryBot.define do ...@@ -47,6 +51,9 @@ FactoryBot.define do
end end
project.group&.refresh_members_authorized_projects project.group&.refresh_members_authorized_projects
# assign the delegated `#settings` attributes after create
project.reload.group_runners_enabled = evaluator.group_runners_enabled unless evaluator.group_runners_enabled.nil?
end end
trait :public do trait :public do
......
...@@ -3640,4 +3640,16 @@ describe Project do ...@@ -3640,4 +3640,16 @@ describe Project do
it { is_expected.not_to be_valid } it { is_expected.not_to be_valid }
end end
end end
describe '#toggle_settings!' do
it 'toggles the value on #settings' do
project = create :project, group_runners_enabled: false
expect(project.group_runners_enabled).to be false
project.toggle_settings!(:group_runners_enabled)
expect(project.group_runners_enabled).to be true
end
end
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