summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-05-18 15:27:11 +0000
committerDouwe Maan <douwe@gitlab.com>2017-05-18 15:27:11 +0000
commitb46b52af37fd8c800e8fdca5de25be31415c7d5d (patch)
tree66b91d248160b6e50b57525b501b673430193641
parentaa47d99bdda5a460346db1970ced0da169036de4 (diff)
parent2505fb7b656815f3099ba2d34b447b254d8ec37e (diff)
downloadgitlab-ce-b46b52af37fd8c800e8fdca5de25be31415c7d5d.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 a7ede5e3b9e..4d59267f71d 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 088a7cb83d5..d63641891fd 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -350,7 +350,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 e6e7774431e..6a15830a15c 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -929,10 +929,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