BigW Consortium Gitlab

Commit 8cba1f51 by Douwe Maan Committed by Regis

Merge branch 'mk-fix-issue-1843' into 'master'

Fix root groups redirecting to group owner Closes #32474 See merge request !11465
parent 8fa6b11c
...@@ -46,7 +46,7 @@ class Namespace < ActiveRecord::Base ...@@ -46,7 +46,7 @@ class Namespace < ActiveRecord::Base
before_destroy(prepend: true) { prepare_for_destroy } before_destroy(prepend: true) { prepare_for_destroy }
after_destroy :rm_dir after_destroy :rm_dir
scope :root, -> { where('type IS NULL') } scope :for_user, -> { where('type IS NULL') }
scope :with_statistics, -> do scope :with_statistics, -> do
joins('LEFT JOIN project_statistics ps ON ps.namespace_id = namespaces.id') joins('LEFT JOIN project_statistics ps ON ps.namespace_id = namespaces.id')
......
...@@ -338,7 +338,7 @@ class User < ActiveRecord::Base ...@@ -338,7 +338,7 @@ class User < ActiveRecord::Base
end end
def find_by_full_path(path, follow_redirects: false) def find_by_full_path(path, follow_redirects: false)
namespace = Namespace.find_by_full_path(path, follow_redirects: follow_redirects) namespace = Namespace.for_user.find_by_full_path(path, follow_redirects: follow_redirects)
namespace&.owner namespace&.owner
end end
......
...@@ -900,6 +900,15 @@ describe User, models: true do ...@@ -900,6 +900,15 @@ describe User, models: true do
end end
context 'with a group route matching the given path' do context 'with a group route matching the given path' do
context 'when the group namespace has an owner_id (legacy data)' do
let!(:group) { create(:group, path: 'group_path', owner: user) }
it 'returns nil' do
expect(User.find_by_full_path('group_path')).to eq(nil)
end
end
context 'when the group namespace does not have an owner_id' do
let!(:group) { create(:group, path: 'group_path') } let!(:group) { create(:group, path: 'group_path') }
it 'returns nil' do it 'returns nil' do
...@@ -907,6 +916,7 @@ describe User, models: true do ...@@ -907,6 +916,7 @@ describe User, models: true do
end end
end end
end end
end
describe 'all_ssh_keys' do describe 'all_ssh_keys' do
it { is_expected.to have_many(:keys).dependent(:destroy) } it { is_expected.to have_many(:keys).dependent(:destroy) }
......
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