summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-05-18 15:27:11 +0000
committerRegis <boudinot.regis@yahoo.com>2017-05-18 11:42:28 -0600
commit8cba1f51668d11918a963ca46f78e26b9c8d0836 (patch)
treee3850034d0b73660c57e85590a1d007d8336055a
parent8fa6b11c642383029b6e6c63b19fb6e40aab92ae (diff)
downloadgitlab-ce-8cba1f51668d11918a963ca46f78e26b9c8d0836.tar.gz
Merge branch 'mk-fix-issue-1843' into 'master'
Fix root groups redirecting to group owner Closes #32474 See merge request !11465
-rw-r--r--app/models/namespace.rb2
-rw-r--r--app/models/user.rb2
-rw-r--r--spec/models/user_spec.rb16
3 files changed, 15 insertions, 5 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb
index 397dc7a25ab..d6b0ab0e52c 100644
--- a/app/models/namespace.rb
+++ b/app/models/namespace.rb
@@ -46,7 +46,7 @@ class Namespace < ActiveRecord::Base
before_destroy(prepend: true) { prepare_for_destroy }
after_destroy :rm_dir
- scope :root, -> { where('type IS NULL') }
+ scope :for_user, -> { where('type IS NULL') }
scope :with_statistics, -> do
joins('LEFT JOIN project_statistics ps ON ps.namespace_id = namespaces.id')
diff --git a/app/models/user.rb b/app/models/user.rb
index 4e5f94683b8..3228081a999 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -338,7 +338,7 @@ class User < ActiveRecord::Base
end
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
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 63e71f5ff2f..9be4996192b 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -900,10 +900,20 @@ describe User, models: true do
end
context 'with a group route matching the given path' do
- let!(:group) { create(:group, path: 'group_path') }
+ 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)
+ 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') }
+
+ it 'returns nil' do
+ expect(User.find_by_full_path('group_path')).to eq(nil)
+ end
end
end
end