Commit b303e9e2 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch...

Merge branch '273380-undefined-method-allow_mfa_for_subgroups-for-nil-nilclass-after-upgrading-to-13-5-1' into 'master'

Resolve "undefined method `allow_mfa_for_subgroups' for nil:NilClass after upgrading to 13.5.1 (8ee0746f)"

See merge request gitlab-org/gitlab!46875
parents f8aeff16 da7233d4
......@@ -41,6 +41,7 @@ class Admin::GroupsController < Admin::ApplicationController
if @group.save
@group.add_owner(current_user)
@group.create_namespace_settings
redirect_to [:admin, @group], notice: _('Group %{group_name} was successfully created.') % { group_name: @group.name }
else
render "new"
......
---
title: Resolve problem when namespace_settings were not created for groups created
via admin panel
merge_request: 46875
author:
type: fixed
# frozen_string_literal: true
class EnsureNamespaceSettingsCreation < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
BATCH_SIZE = 10000
MIGRATION = 'BackfillNamespaceSettings'
DELAY_INTERVAL = 2.minutes.to_i
disable_ddl_transaction!
class Namespace < ActiveRecord::Base
include EachBatch
self.table_name = 'namespaces'
end
def up
ensure_data_migration
end
def down
# no-op
end
private
def ensure_data_migration
Namespace.each_batch(of: BATCH_SIZE) do |query, index|
missing_count = query.where("NOT EXISTS (SELECT 1 FROM namespace_settings WHERE namespace_settings.namespace_id=namespaces.id)").limit(1).size
if missing_count > 0
ids_range = query.pluck("MIN(id), MAX(id)").flatten
migrate_in(index * DELAY_INTERVAL, MIGRATION, ids_range)
end
end
end
end
e17da7eebb6d054a711368369d2b4fa684e96344f845bb7c6b3c89a9b4c4e067
\ No newline at end of file
......@@ -25,6 +25,20 @@ RSpec.describe Admin::GroupsController do
end
end
describe 'POST #create' do
it 'creates group' do
expect do
post :create, params: { group: { path: 'test', name: 'test' } }
end.to change { Group.count }.by(1)
end
it 'creates namespace_settings for group' do
expect do
post :create, params: { group: { path: 'test', name: 'test' } }
end.to change { NamespaceSetting.count }.by(1)
end
end
describe 'PUT #members_update' do
let(:group_user) { create(:user) }
......
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20201104124300_ensure_namespace_settings_creation.rb')
RSpec.describe EnsureNamespaceSettingsCreation do
context 'when there are namespaces without namespace settings' do
let(:namespaces) { table(:namespaces) }
let(:namespace_settings) { table(:namespace_settings) }
let!(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
let!(:namespace_2) { namespaces.create!(name: 'gitlab', path: 'gitlab-org2') }
it 'migrates namespaces without namespace_settings' do
stub_const("#{described_class.name}::BATCH_SIZE", 2)
Sidekiq::Testing.fake! do
freeze_time do
migrate!
expect(described_class::MIGRATION)
.to be_scheduled_delayed_migration(2.minutes.to_i, namespace.id, namespace_2.id)
end
end
end
it 'schedules migrations in batches ' do
stub_const("#{described_class.name}::BATCH_SIZE", 2)
namespace_3 = namespaces.create!(name: 'gitlab', path: 'gitlab-org3')
namespace_4 = namespaces.create!(name: 'gitlab', path: 'gitlab-org4')
Sidekiq::Testing.fake! do
freeze_time do
migrate!
expect(described_class::MIGRATION)
.to be_scheduled_delayed_migration(2.minutes.to_i, namespace.id, namespace_2.id)
expect(described_class::MIGRATION)
.to be_scheduled_delayed_migration(4.minutes.to_i, namespace_3.id, namespace_4.id)
end
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