Commit ed9838cd authored by Felipe Artur's avatar Felipe Artur
Browse files

Create project feature when project is created

parent 0732ba881235
......@@ -25,6 +25,7 @@ Please view this file on the master branch, on stable branches it's out of date.
- Add an example for testing a phoenix application with Gitlab CI in the docs (Manthan Mallikarjun)
- Cancelled pipelines could be retried. !6927
- Updating verbiage on git basics to be more intuitive
- Fix project_feature record not generated on project creation
- Clarify documentation for Runners API (Gennady Trafimenkov)
- The instrumentation for Banzai::Renderer has been restored
- Change user & group landing page routing from /u/:username to /:username
......@@ -32,8 +32,8 @@ class BoardLimitExceeded < StandardError; end
default_value_for(:shared_runners_enabled) { current_application_settings.shared_runners_enabled }
after_create :ensure_dir_exist
after_create :create_project_feature, unless: :project_feature
after_save :ensure_dir_exist, if: :namespace_id_changed?
after_initialize :setup_project_feature
# set last_activity_at to the same as created_at
after_create :set_last_activity_at
......@@ -1310,11 +1310,6 @@ def pushes_since_gc_redis_key
# Prevents the creation of project_feature record for every project
def setup_project_feature
build_project_feature unless project_feature
def default_branch_protected?
current_application_settings.default_branch_protection == Gitlab::Access::PROTECTION_FULL ||
current_application_settings.default_branch_protection == Gitlab::Access::PROTECTION_DEV_CAN_MERGE
class GenerateProjectFeatureForProjects < ActiveRecord::Migration
Application was eager loading project_feature for all projects generating an extra query
everytime a project was fetched. We removed that behavior to avoid the extra query, this migration
makes sure all projects have a project_feature record associated.
def up
# Generate enabled values for each project feature 20, 20, 20, 20, 20
# All features are enabled by default
enabled_values = [ProjectFeature::ENABLED] * 5
execute <<-EOF.strip_heredoc
INSERT INTO project_features
(project_id, merge_requests_access_level, builds_access_level,
issues_access_level, snippets_access_level, wiki_access_level)
(SELECT, #{enabled_values.join(',')} FROM projects LEFT OUTER JOIN project_features
ON project_features.project_id =
def down
"Not needed"
......@@ -11,7 +11,7 @@
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20161018024550) do
ActiveRecord::Schema.define(version: 20161019213545) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -67,6 +67,14 @@
it { have_many(:notification_settings).dependent(:destroy) }
it { have_many(:forks).through(:forked_project_links) }
context 'after create' do
it "creates project feature" do
project =
expect { }.to change{ project.project_feature.present? }.from(false).to(true)
describe '#members & #requesters' do
let(:project) { create(:project, :public) }
let(:requester) { create(:user) }
......@@ -531,9 +539,9 @@
describe '#has_wiki?' do
let(:no_wiki_project) { build(:project, wiki_enabled: false, has_external_wiki: false) }
let(:wiki_enabled_project) { build(:project) }
let(:external_wiki_project) { build(:project, has_external_wiki: true) }
let(:no_wiki_project) { create(:project, wiki_access_level: ProjectFeature::DISABLED, has_external_wiki: false) }
let(:wiki_enabled_project) { create(:project) }
let(:external_wiki_project) { create(:project, has_external_wiki: true) }
it 'returns true if project is wiki enabled or has external wiki' do
expect(wiki_enabled_project).to have_wiki
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